def confirm_email(): if current_user.is_authenticated: #logout_user() return redirect(request.args.get('next') or url_for('home.index')) action = request.args.get('action') if action == 'confirm': token = request.args.get('token') if not token: return render_template('feedback.html', status=False, message=_('此激活链接无效,请准确复制邮件中的链接。')) if RT.query.get(token): return render_template('feedback.html', status=False, message=_('此激活链接已被使用过。')) RT.add(token) try: email = ts.loads(token, salt="email-confirm-key", max_age=86400) except: abort(404) user = User.query.filter_by(email=email).first_or_404() user.confirm() flash(_('Your email has been confirmed')) login_user(user) return redirect(url_for('home.index')) elif action == 'send': email = request.args.get('email') user = User.query.filter_by(email=email).first_or_404() print(user) if not user.confirmed: print(email) send_confirm_mail(email) return render_template('feedback.html', status=True, message=_('邮件已经发送,请查收!')) else: abort(404)
def revoke_token(): jti = get_raw_jwt()["jti"] RevokedToken.add(jti) return jsonify({ "status": "success", "message": "successuflly logged out" }), 200
def post(self): jti = get_raw_jwt()['jti'] try: revoked_token = RevokedToken(jti = jti) revoked_token.add() return {'message': 'Refresh token has been revoked'} except: return {'message': 'Something went wrong'}, 500
def post(self): jti = get_raw_jwt()['jti'] try: revoked_token = RevokedToken(jti=jti) revoked_token.add() return {'msg': 'Token has been revoked'} except: return {'msg': 'Something error'}, 500
def delete(self): body = request.get_json() email = body.get('email') username = body.get('username') password = body.get('password') user = UserModel.find_by_email(email) if not user: return {'message': 'cannot find user'}, 409 if user.username == username and user.check_password(password): user.delete_from_db() jti = get_raw_jwt()['jti'] revoked_token = RevokedToken(jti=jti) revoked_token.add() return {'status': 'deleted'}, 200 else: return {'message': 'invalid data'}, 400
def reset_password(token): '''重设密码''' if RT.query.get(token): return render_template('feedback.html', status=False, message=_('此密码重置链接已被使用过。')) form = ResetPasswordForm() if form.validate_on_submit(): RT.add(token) try: email = ts.loads(token, salt="password-reset-key", max_age=86400) except: return render_template('feedback.html', status=False, message=_('此密码重置链接无效,请准确复制邮件中的链接。')) user = User.query.filter_by(email=email).first_or_404() password = form['password'].data user.set_password(password) logout_user() flash('密码已经修改,请使用新密码登录。') return redirect(url_for('home.signin')) return render_template('reset-password.html',form=form)