def login(): """ 登录 :return: """ if request.user_agent.platform in ['ipad', 'iphone', 'android']: return jsonify(error='请先登录') # 用户验证通过直接跳转到首页 if current_user.is_authenticated: return redirect_next() if request.method == 'POST': email = request.form.get('email', None) password = request.form.get('password', None) if email and password: user, authenticated = User.authenticate(email=email, password=password) else: flash(gettext('please enter the correct email and password.')) return redirect_next() if user and authenticated: # remember = request.form.get('remember') == 'y' remember = True login_user(user, remember) else: flash('帐号或密码不正确') return redirect_next() return render_template('admin/user/login.html')
def login_email(): """ :return: """ data = request.json email = data.get('email', '') user, authenticated = User.authenticate(email=email, password=data.get('password', '')) if not authenticated: return jsonify(message='Failed') login_user(user, remember=True) return jsonify(message='OK', user=json_templ.get_user_info(user), remember_token=user.generate_auth_token())
def reauth(): """ 重新授权(确认) :return: """ form = ReauthForm(next=request.args.get('next')) if request.method == 'POST': user, authenticated = User.authenticate(email=current_user.email, password=form.password.data) if user and authenticated: confirm_login() current_app.logger.debug('reauth: %s' % session['_fresh']) flash(gettext('Reauthenticated.'), 'success') return redirect('frontend.change_password') flash(gettext('password is wrong.'), 'error') return render_template('admin/user/reauth.html', form=form)