def login(): try: if current_user.is_authenticated: flash('Đã xác thực.') return redirect( url_for('auth.truy_xuat_gia_chu', username=current_user.username)) form = LoginForm() if form.validate_on_submit(): username = UserDb.query.filter_by( username=form.username.data.title()).first() if username is None or not username.check_password( form.birthday.data): flash( 'Họ tên chưa đăng ký hoặc nhập sai ngày tháng năm sinh !') return redirect(url_for('auth.login')) else: login_user(username) return redirect( url_for('auth.truy_xuat_gia_chu', username=current_user.username)) except Exception as error: return render_template('errors/500.html', error=error) huongdan = huong_dan() return render_template('auth/login.html', form=form, HUONGDAN=huongdan)
def test_validate_invalid_password(self, user): """Invalid password.""" user.set_password("example") user.save() form = LoginForm(username=user.username, password="******") assert form.validate() is False assert "Invalid password" in form.password.errors
def test_validate_success(self, user): """Login successful.""" user.set_password("example") user.save() form = LoginForm(username=user.username, password="******") assert form.validate() is True assert form.user == user
def test_validate_inactive_user(self, user): """Inactive user.""" user.active = False user.set_password("example") user.save() # Correct username and password, but user is not activated form = LoginForm(username=user.username, password="******") assert form.validate() is False assert "User not activated" in form.username.errors
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.email.data).first() if user is None: user = User(username=form.email.data) db.session.add(user) session['know'] = False else: session['know'] = True return render_template('login.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.UserName.data).first() if user is not None and user.verify_password(form.Passwd.data): #登陆成功 login_user(user) # print("\n???") # print(url_for('auth.hello_world')) return redirect(url_for('main.dash')) else: print('err\n'); return render_template('auth/login.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.UserName.data).first() if user is not None and user.verify_password(form.Passwd.data): #登陆成功 login_user(user) # print("\n???") # print(url_for('auth.hello_world')) return redirect(url_for('main.dash')) else: print('err\n') return render_template('auth/login.html', form=form)
def login(): print(current_user.is_authenticated) # if current_user.is_authenticated: # return redirect(url_for("main.home")) form = LoginForm() if form.validate_on_submit(): user = User.get_by_name(form.username.data) if user is not None and user.verify_password(form.password.data): login_user(user,remember=form.remember.data) return redirect(url_for("main.home")) flash("username or password incorrect!") form.remember.data = True return render_template("login.html",form=form)
def home(): """Home page.""" form = LoginForm(request.form) current_app.logger.info("Hello from the home page!") # Handle logging in if request.method == "POST": if form.validate_on_submit(): login_user(form.user) flash("Successfully logged in.", "success") redirect_url = request.args.get("next") or url_for( "user.profile.account") return redirect(redirect_url) else: flash_errors(form) return render_template("home.html", form=form)
def do_the_login(): if current_user.is_authenticated: flash('you are already logged in') return redirect(url_for('main.display_books')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(user_email=form.email.data).first() if not user or not user.check_password(form.password.data): flash('Invalid Credentials, Please try again') return redirect(url_for('authentication.do_the_login')) login_user(user, form.stay_loggedin.data) return redirect(url_for('main.display_books')) return render_template('login.html', form=form)
def login(): if g.user is not None and g.user.is_authenticated: return redirect(url_for('module_a.index_view')) form = LoginForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(UserEmail=form.email.data).first() if user and check_password_hash(user.UserPassword, request.form['password']): login_user(user) flash('Welcome.', 'success') return redirect(url_for('module_a.index_view')) else: flash('Invalid email and/or password.', 'danger') return render_template('auth/login.html', form=form) return render_template('auth/login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit(): 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('auth.login')) login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.index') return redirect(next_page) return render_template('auth/login.html', title='登录', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by( username=form.username.data).first() # 查询对应表里符合用户名的第一条数据 if user is not None and user.verify_password(form.password.data): login_user(user) # 用户登录,为其注册会话 return redirect(request.args.get('next') or url_for('main.index')) else: if user is None: # 渲染表单 flash('用户名不存在') elif not user.verify_password(form.password.data): flash('密码不正确') return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.index')) # 生成一个表单实例 form = LoginForm() # 执行Form校验工作,当浏览器发起GET请求,它会返回False,这样视图会直接跳过if块代码,直接转到最后一局渲染模板 # 但是当点击Submit按钮的时候,浏览器会发起POST请求,然后验证生成的页面中,进行验证页面自定义验证(非空、长度等等) # 若每个字段都验证通过,则会继续执行下面语句,否则会直接跳到最后一句执行 if form.validate_on_submit(): 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('auth.login')) login_user(user, remember=form.remember_me.data) # 处理登录后重定向问题 next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.index') return redirect(next_page) return render_template('auth/login.html', title=_('Sign In'), form=form)
def login(): ''' 登录, :return: ''' form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): # 在用户会话中标记用户已登陆 login_user(user, form.remeber_me.data) next = request.args.get('next') print(1, next) if next is None or not next.startswith('/'): next = url_for('main.index') # print(2, next) # print(3, next) return redirect(next) flash('你的用户名或密码好像有点问题哦') return render_template('auth/login.html', form=form)
def index(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.email.data).first() return render_template('index.html', username=name)
def test_validate_unknown_username(self, db): """Unknown username.""" form = LoginForm(username="******", password="******") assert form.validate() is False assert "Unknown username" in form.username.errors assert form.user is None
def contributors(): """Application contributors page.""" form = LoginForm(request.form) return render_template("contributors.html", form=form)
def about(): """Application "About" page.""" form = LoginForm(request.form) return render_template("about.html", form=form)
def login(): form = LoginForm() if form.validate_on_submit(): flash('你已經成功登錄') return render_template('login.html',form=form)