# coding: utf-8
from auth import auth_bp
from flask.views import MethodView
from flask import render_template,flash,redirect,url_for,request
from flask_login import login_user,url_for,redirect
from .forms import RegisterForm, \
LoginForm, \
ResetPasswdForm, \
ForgetPasswordForm, \
ResetForgetPasswordForm
class Login(MethodView):
def __init__(self,**kw):
super(Login,self).__init__(**kw)
self.form = LoginForm()
def get(self):
return render_template("auth/register.html",title="Register",form=self.form)
def post(self):
if self.form.validate_on_submit():
email = self.form.email.data
user = User.query.filter_by(email=email).first()
if user is not None and user.verify_password(self.form.password.data):
login_user(user)
flash("Login Succeed!")
next = request.args.get("next")
if next is None or not next.startwith("/"):
next = url_for('index.index')
return redirect(next)
flash("invlida username or password")
return render_template("auth/login.html",title="Login",form=self.form)