def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).one() login_user(user) flash("Logged in successfully.", "success") return redirect(request.args.get("next") or url_for(".home")) return render_template("login.html", form=form)
def login_view(self): form = LoginForm(request.form) if helpers.validate_form_on_submit(form): user = form.get_user() flask_login.login_user(user) if flask_login.current_user.is_authenticated: return redirect(url_for('.index')) self._template_args['form'] = form return super().index()
def login(): """Handle User Login.""" form = LoginForm() if request.method == 'POST' and form.validate(): user = User.query.filter_by(name=form.name.data).first() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect('/admin/login') login_user(user) return redirect('/admin') return render_template('admin/login.html', form=form)
def handle_login(): form = LoginForm() if form.validate_on_submit(): user = Administrator.objects(username=form.username.data).first() if validate_login(user, form): login_user(user) flash('Logged in', category='success') return redirect(url_for('admin.index')) else: flash('Wrong username or password', category='danger') return render_template('login.html', form=form)
def login(): forms = LoginForm() #实例化 if forms.validate_on_submit(): #提交的时候进行验证 data = forms.data #获取form数据信息 admin = Admin.query.filter_by(name=data["account"]).first() # if admin == None: # flash("账号不存在") # return redirect(url_for('admin.login')) if admin != None and not admin.check_pwd(data["pwd"]): #这里的check_pwd函数在models 下Admin模型下定义 flash("密码错误") return redirect(url_for('admin.login')) session['admin'] = data['account'] #添加session #session['user_id'] = User. return redirect(request.args.get('next') or url_for('admin.index')) return render_template('admin/login.html',form=forms)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user: if check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) return redirect(url_for('dashboard')) return '<h1> Invalid username or password </h1>' return render_template('login.html', form=form)
async def post(self, request): """Submit for User login form.""" form = LoginForm(request) if form.validate(): user = await authenticate( request.ctx.conn, form.data["username"], form.data["password"] ) if user: await login(request, user) return response.redirect(LOGIN_REDIRECT_URL) else: form.username.errors.append("Not valid username or password!") return await jinja.render_async("login.html", request, form=form)
def index(): form = LoginForm() error = None if form.validate_on_submit(): if (request.form['username'] == "jaqen" and request.form['password'] == "hghar"): return render_template('index.html') else: error = "Invalid username or password" return render_template('login.html', title='Sign in', form=form, error=error)
def login(): forms = LoginForm() #实例化forms if forms.validate_on_submit(): #提交的时候进行验证,如果数据能被所有验证函数接受,则返回true,否则返回false data = forms.data #获取form数据信息(包含输入的用户名(account)和密码(pwd)等信息),这里的account和pwd是在forms.py里定义的 admin = Admin.query.filter_by( name=data["account"]).first() #查询表信息admin表里的用户名信息 if admin == None: flash("账号不存在") #操作提示信息,会在前端显示 return redirect(url_for('admin.login')) elif admin != None and not admin.check_pwd( data["pwd"]): #这里的check_pwd函数在models 下Admin模型下定义 flash("密码错误") return redirect(url_for('admin.login')) session['admin'] = data['account'] #匹配成功,添加session return redirect(request.args.get('next') or url_for('admin.index')) #重定向到首页 return render_template('admin/login.html', form=forms)
async def get(self, request): """User login form.""" if request.ctx.session.get("user"): return response.redirect(LOGIN_REDIRECT_URL) form = LoginForm(request) return await jinja.render_async("login.html", request, form=form)
def home(): if current_user.is_authenticated: return redirect(url_for('links')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username = form.username.data).first() if user: login_user(user, remember = form.remember.data) if user.type != "": return redirect(url_for('links')) else: flash('You do not have admin status! Please contact IT to be assigned an admin status.', 'danger') return redirect(url_for('logout')) else: flash('Login failed. Check username and password.', 'danger') #render_template will render the template located in the templates folder #Conifiguration with the Jinja2 template engine is taken care of by Flask return render_template('login.html',title = 'Login', form = form)
def login_post(): loginForm = LoginForm() admin = Admin.query.filter_by(name='Yusif').one() if request.method == 'POST': email = loginForm.email.data password = loginForm.password.data if email == admin.email and password == '123456': return redirect("/admin") else: flash('Incorrect mail or password') return redirect('/login') return render_template('/login', form=loginForm)
def login(): loginForm = LoginForm() return render_template("login.html", form=loginForm)
def homepage(): """ Render the homepage template on the / route """ form = LoginForm() return render_template("admin/index.html", title="Admin", form=form)