deflogin_func(email, password):
user = User.query.filter_by(UserEmail=email).first()
if user == None:
return"NOACCOUNT"else:
if check_password_hash(user.UserPassword, password):
login_user(user)
session['userid'] = user.UserID
session['usertype'] = user.UserType
return"SUCCEED"else:
return"WRONGPWD"@auth_.route('/login', methods=['GET', 'POST'])deflogin():
form = RegisterForm(request.form)
if request.form:
if request.form['action'] == 'login':
if g.user isnotNoneand g.user.is_authenticated:
print g.user.UserName, g.user.UserPassword
return redirect(url_for('module_a.index_view'))
if form.validate_on_submit():
ret = login_func(form.email.data, form.password.data)
print"login ret : ", ret
if ret == 'NOACCOUNT'or ret == 'WRONGPWD':
flash('Invalid email and/or password.', 'danger')
return render_template('login.html', form=form, page='login')
else:
return redirect(url_for('module_a.index_view'))
elif request.form['action'] == 'register':
if form.validate_on_submit():
ret = register_func(form.username.data, form.email.data, form.password.data, form.confirm.data, form.type.data)
if ret == "INPUTERR":
flash('the input too few')
elif ret == "TYPEERR":
flash('No such Type Account')
elif ret == "PWDERR":
flash('Two password are not the same')
elif ret == "REPEAT":
flash('The email have been register')
if ret == "SUCCEED":
return redirect(url_for("auth.unconfirmed"))
return render_template('login.html', form=form, page='register')
return render_template('login.html', form=form, page='login')