def login(): form = LoginForm(request.form) if request.method == 'POST': if form.validate(): if form.register.data: return redirect(url_for('user_new')) user = User.query.filter_by(username=form.username.data).first() if user: if user.check_password(form.password.data): login_user(user, remember=True) else: flash('incorrect password') return redirect(url_for('login')) else: flash('username not found') return redirect(url_for('login')) if request.args.get('next') == '/react': return redirect(url_for('react')) else: return redirect(url_for('stats', username=g.user.username)) else: flash_errors(form) return render_template('login.html', title='login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): # if GET it False user = User.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(eth_address=form.eth_address.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('event_index')) else: flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', title='Login', form=form)
def backend_login(request): if request.method == 'POST': login_form = LoginForm(request.POST) if login_form.is_valid(): user = authenticate(username=request.POST['username'], password=request.POST['password']) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect('/') else: error_message = 'Your account is not active' else: error_message = 'Invalid Login' else: login_form = LoginForm() return render_to_response('backend/login.html', locals(), context_instance=RequestContext(request))
def login(request): # When already logged in if request.user.is_authenticated: messages.warning( request, '用户 {username}, 你已经登陆'.format(username=request.user.username)) return redirect('index') # Attempt to login login_form = LoginForm(request.POST.dict() or None) if request.method == 'POST' and login_form.is_valid(): username = login_form.cleaned_data.get('username') password = login_form.cleaned_data.get('password') user = auth.authenticate(username=username, password=password) if user: auth.login(request, user) messages.success( request, '欢迎回来, {username}'.format(username=request.user.username)) return redirect('index') else: messages.error(request, '账号或密码错误') return render(request, 'login.html', {'login_form': login_form})
def login(): if current_user.is_authenticated: return redirect(url_for("home")) form = LoginForm() # if the data is valid then flash a success prompt if form.validate_on_submit(): # get user email user = User.query.filter_by(email=form.email.data).first() # User initial page selected before login next_page = request.args.get("next") if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) # Redirect user to next page if there is any or just home if none return redirect(next_page) if next_page else redirect( url_for('home')) else: flash("Login failed. Please check your email and password", "danger") return render_template('login.html', title="Login", form=form)
def login(request): """后台登录页面""" if request.method == "GET": login_obj = LoginForm() return render(request, "login.html", {"login_obj": login_obj}) elif request.method == "POST": login_obj = LoginForm(request.POST) if login_obj.is_valid(): code = login_obj.cleaned_data.get("check_code") # 获取用户输入验证码 if request.session.get("CheckCode").upper() == code.upper(): # 用户输入验证码和系统生成验证码匹配 username = login_obj.cleaned_data.get("username") # 获取用户输入用户名 request.session["username"] = username # 在session中设置用户名 request.session.clear_expired() # 将所有Session失效日期小于当前日期的数据删除 remember = login_obj.cleaned_data.get("remember") # 用户是否选中一个月内自动登录 if remember: # 用户选中一个月内自动登录 request.session.set_expiry(2592000) # 设置过期时间为一个月之后 return redirect("/backend/index/") # 注册完毕直接跳转登录页面 else: login_obj.add_error("check_code", "验证码错误") # 添加验证码错误信息 return render(request, "login.html", {"login_obj": login_obj})