现在注册玩之后跳转到登录界面,然后登录后在进行认证,这一步我感觉多余,注册成功后怎么直接跳转到认证页面,并且是当前注册用户登录?相当于注册成功后省略登录认证这一步。
登录:
@auth.route('/login',methods=['GET','POST'])
def login():
username = request.form.get('username')
password = request.form.get('password')
if username:
user = User.query.filter_by(username=username).first()
if user is not None and user.verify_passwd(password):
login_user(user)
return redirect(url_for('main.index'))
else:
error = '用户名不存在或密码错误.'
return render_template('auth/login.html',error=error)
return render_template('auth/login.html',success=success)
注册:
@auth.route('/register',methods=['GET','POST'])
def register():
error = []
if request.method == 'POST':
try:
new_user = User(username=request.form.get('username'),email=request.form.get('email'),password=request.form.get('confirm_password'))
db.session.add(new_user)
db.session.commit()
except:
error.append('用户名或邮箱已被注册.')
db.session.rollback()
else:
token = new_user.tokens()
send_email(new_user.email, 'Confirm Your Account','auth/email/confirm', user=new_user, token=token)
global success
success = '一封认证邮件已发至您的邮箱,登陆后完成认证即可访问.'
return redirect(url_for('auth.login'))
return render_template('auth/register.html',error=error)
用户认证:
@auth.route('/confirm/<token>')
@login_required
def confirm(token):
if current_user.status:
return redirect(url_for('main.index'))
if current_user.loosen_tokens(token):
db.session.commit()
return redirect(url_for('main.index'))
添加回答
举报
0/150
提交
取消