def login(): mapper = inspect(User) for column in mapper.attrs: print(column.key) columns = inspect(User).columns.keys() formdata = {} form = LoginForm() formdata['form'] = form #formdata['form']['name'].data = 'Carlxxxx' # if form.validate_on_submit(): # formdata['name'] = form.name.data # form.name.data = '' # # return render_template('login.html', form=form, name=name, password=password) # return render_template('login.html', data = formdata) formdata['name'] = session.get('name') if form.validate_on_submit(): session['name'] = form.name.data formdata['name'] = form.name.data # if db.session.query(User).filter(username=form.name.data).count(): # p = 'found' new_user = User(password=form.password.data, username=form.name.data) # try: # new_user = User(password=form.password.data, username=form.name.data) # # except ValueError as e: # form.name.errors.append(e) # return render_template('login.html', data = formdata) # except: # pass try: db.session.add(new_user) db.session.commit() except exc.SQLAlchemyError as e: form.name.errors.append(e.orig.args[1]) return render_template('login.html', data = formdata) form.name.data = '' return redirect(url_for('users.login')) return render_template('login.html', data = formdata)
def login(): if current_user.is_authenticated: return redirect(url_for('posts.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user) return redirect(url_for('posts.home')) return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_request = request.args.get('next') return redirect(next_request) if next_request else redirect(url_for('main.home')) else: flash("Login Unsuccessful. Please check the username or password.", "danger") return render_template("login.html", title = 'Login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).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') flash('Logged in!', 'success') return redirect(next_page) if next_page else redirect(url_for('main.home')) else: flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', title='Login', form=form)
def login(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('.user_page', username=g.user.username)) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first_or_404() if user.password == form.password.data: login_user(user) return redirect(url_for('.user_page', username=user.username)) return render_template('login.html', form=form)
def login(): form = LoginForm() if request.method == 'POST': if form.validate(): authenticated_user = User.authenticate(form.username.data, form.password.data) if authenticated_user: session['user_id'] = authenticated_user.id flash('You are logged in.', 'positive') return redirect( url_for('users.show', user_id=authenticated_user.id)) else: flash('Invalid credentials!', 'negative') return redirect(url_for('auth.login')) return render_template('login.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = UserModel.query.filter_by(email=form.email.data).first() if user is not None and user.check_password(form.password.data): login_user(user) flash(f'Welcome back, {user.given_name}!') return redirect(url_for('core_bp.main')) else: flash('Incorrect email or password, please try again.') return redirect(url_for('users_bp.login')) return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('core.index')) form = LoginForm() if form.validate_on_submit(): user = Account.query.filter_by(email=form.email.data).first() if user.check_password(form.password.data): login_user(user) flash('Logged in successfully.') next = request.args.get('next') if next is None or not next[0] == '/': next = url_for('core.index') return redirect(next) else: flash("Wrong password.") return render_template('login.html', form=form)
def login(): if request.method == "GET": return render_template("users/login.html", form=LoginForm()) form = LoginForm(request.form) user = User.query.filter_by(username=form.username.data, password=form.password.data).first() if not user: return render_template("users/login.html", form=form, error="Invalid password or username") login_user(user) return redirect(url_for("index"))
def login(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) flash('Good! You have been logged in.', 'is-success') next_page = request.args.get('next') # if not is_safe_url(next_page): # return abort(400) return redirect(next_page or url_for('main.home')) else: flash('Login Unsuccessul. Try again! Your credentials is false', 'is-danger') return render_template('pages/login.html', title='login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.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') if next_page is not None: if "/upvote" in next_page or "/downvote" in next_page: return redirect(url_for('main.home')) return redirect(next_page) if next_page else redirect( url_for('main.home')) else: flash('Prihlásenie bolo neúspešné. Skontrolujte email a heslo', 'danger') return render_template('login.html', title='Prihlásenie', 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(email=form.email.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') flash(f'Seja Bem vindo ao Direito Sem Preconceito {user.username}', 'success') return redirect(next_page) if next_page \ else redirect(url_for('main.index')) else: flash('Não foi possível acessar sua conta.\ Por favor verifique seu email e senha', 'danger') return render_template('login.html', title='Entrar', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): #判断用户是否存在 username = form.username.data user = Users.query.filter_by(username=username).first() if not user: flash('用户名或密码错误') return render_template('users/login.html', form=form) password = form.password.data #判断密码是否正确 if check_password_hash(user.password, password): #自动登录 login_user(user, remember=form.remember_me) flash('恭喜你,登录成功!') return redirect(url_for('users.select_class')) else: flash('用户名或密码错误') return render_template('users/login.html', form=form)
def login(): if current_user.is_authenticated: #if the user is already logged in return redirect( url_for("main.home")) #redirect the user back to the home page form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first( ) #check if there are any emails within our database matching the email that the user entered if user and bcrypt.check_password_hash( user.password, form.password.data ): #if the email exists and the password hash is valid login_user(user, remember=form.remember.data) #If the user tried to access a log-in only page and was redirected to /login, then automaticall send the user back to where they were going. next_page = request.args.get( "next" ) #args is a dictionary but use args.get() not args[] because [] will throw an error if the key does not exist return redirect(next_page) if next_page else redirect( url_for("main.home")) else: #login is unsuccessful flash("Invalid!", "danger") #danger alert (Bootstrap) return render_template("login.html", title="Login", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(user_email=form.email.data).first() result = bcrypt.check_password_hash(user.user_password, form.password.data) if result is not True: flash(f"{form.email.data} Something Wrong !!!", "danger") # return redirect(url_for('login')) return redirect(request.url) else: login_user(user, remember=form.rememberMe.data, duration=timedelta(minutes=10), fresh=True) flash(f"{form.email.data} welcome to Home!!! ", "success") next_page = request.args.get("next") return redirect(next_page) if next_page else redirect( url_for('main.home')) return render_template("login.html", title="Login", form=form)
def login(): """User login page.""" # Bypass Login screen if user is logged in if current_user.is_authenticated: return redirect(url_for('user.dashboard')) form = LoginForm(request.form) # POST: Create user and redirect them to the app if request.method == 'POST': if form.validate(): #Get Form Fields email = request.form.get('email') password = request.form.get('password') # Validate Login Attempt user = User.query.filter_by(email=email).first() if user: if user.check_password(password=password): login_user(user) next = request.args.get('next') session['user_id'] = user.id return redirect(next or url_for('user.dashboard')) flash('Invalid username/password combination') return redirect(url_for('user.login')) #GET: Serve Log-in page return render_template('users/login.html', form=form)
def logout(): form = LoginForm() logout_user() return render_template('login.html', title="Login", form=form)