def login(): ''' func of login user chech authentificated user, pass and empty textbox, and check remember checkbox ''' titleVar = _('Авторизация') flash_uncheck = _('Неправильный логин или пароль!') flash_check = _('Вы вошли на сайт') 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 ) or user.password_hash is None or user.password_hash == "": #print("Неправильный логин или пароль") flash(flash_uncheck) return redirect(url_for('user.login')) login_user(user, remember=form.remember_me.data) flash(flash_check) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': #print("Нет некста") next_page = url_for('welcome.index') return redirect(next_page) #print("Загрузил страницу") return render_template('user/login.html', title=titleVar, form_login=form)
def settings_user_deactivate(): form = LoginForm() if form.validate_on_submit(): form.user.make_deactivated() db.session.add(form.user) db.session.commit() return logout() return render_template('users/settings_user_deactivate.html', form = form, title = 'Deactivate Account')
def index(): if g.user is not None and g.user.is_authenticated: return redirect(url_for('institution')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() login_user(user, remember=form.remember_me.data) return redirect(request.args.get('next') or url_for('institution')) flash("Nom d\'utilisateur ou mot de passe érroné") return render_template('index.html', title='Connexion', form=form)
def login(): if current_user.is_authenticated: return 'you need to logout to access this page' form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first_or_404() if user and user.check_password(form.password.data): login_user(user, remember=True) return redirect(url_for('main.home')) return render_template('login.html', form=form)
def process_login(): form = LoginForm() if form.validate_on_submit(): user = User.objects.get(username=form.username.data) if user and user.check_password(form.password.data): login_user(user) flash('You are logged in') return redirect(url_for('posts.index')) else: flash('Wrong username or password') return redirect(get_redirect_target()) #url_for('posts.index'))
def login(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): # login and validate the user... user = User.query.filter_by(email=form.email.data).first() login_user(user) flash('Logged in successfully.', category='success') return redirect(request.args.get('next') or url_for('index')) return render_template('user/login.html', form=form)
def signin(): form = LoginForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and user.verify(form.password.data): session['nick'] = user.username session['email'] = user.email flash('Welcome %s' % user.username) return redirect(url_for('dashboard')) flash('Wrong email or password', 'error-message') return render_template('/user/signin.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if not user or not bcrypt.check_password_hash(user.password, form.password.data): flash('Please check your login details and try again.') return redirect(url_for('auth.login')) login_user(user, remember=form.remember) return redirect(url_for('auth.profile')) return render_template('login.html', form=form)
def login(): form = LoginForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and check_password_hash(user.password, form.password.data): session['user_id'] = user.id flash('Welcome %s' % user.nickname) return redirect(url_for('general.main')) flash('Worng email or password', 'error-message') return redirect(url_for('general.main'))
def login(): if g.user.is_authenticated(): flash("You are already registered.") return redirect(url_for('user_thanks', username = g.user.username)) form = LoginForm() if form.validate_on_submit(): login_user(form.user, remember = form.remember_me.data) g.user.date_last_logged_in = datetime.utcnow() db.session.add(g.user) db.session.commit() return redirect(request.args.get("next") or url_for('thanks')) return render_template('users/login.html', form = form, title = 'Login')
def login(): form = LoginForm() if form.validate_on_submit(): user = User.find_by(email=form.email.data) if not user or not user.login(form.password.data, form.remember.data): flash('Email or password incorrect.', 'danger') return render_template('user_login.html', title='Login', form=form) return redirect( request.args.get('next') or url_for('accounts.pagination')) return render_template('user_login.html', title='Login', form=form)
def login(): form = LoginForm(request.form) if form.validate_on_submit(): user = User.query.filter( db.or_(User.username == form.username.data, User.email == form.username.data)).first() if user is not None and user.check_password(form.password.data): login_user(user) flash('You are logged in. Welcome!', 'success') return redirect(url_for('main.home')) else: flash('Wrong username/email or password.', 'danger') return render_template('user/login.html', form=form) return render_template('user/login.html', form=form)
def login(self): form = LoginForm() service = UserService() if request.method == 'POST' and form.validate_on_submit(): user = service.login(form.username.data, form.password.data) if user: flash('Login Successfully.', 'success') login_user(user, form.remember.data) next_path = request.args.get('next', request.path) return redirect(next_path) else: raise Exception('Username or Password Incorrect.') return render_template('user/login.html', form=form)
def login(): if current_user.is_authenticated: return make_response(redirect("/")) form = LoginForm() if form.validate_on_submit(): #try: try: controller.login(form.username.data, form.password.data) return redirect(url_for('web.index')) except UserDoesNotExistError: flash("Invalid username or password.") #except: # return redirect(url_for('user.login')) 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(username=form.username.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: return redirect(next_page) else: return redirect(url_for('main.home')) else: flash('登录失败,请检查账号或者密码', 'danger') return render_template('user/login.html', title='登录', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('posts.index')) form = LoginForm() if form.validate_on_submit(): # user = User.query.filter_by(username=form.username.data).first() user = User.query.filter_by(email=form.email.data).first_or_404() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('posts.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('posts.index') return redirect(next_page) return render_template('user/login.html', title='Sign In', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): try: user = User.get(User.email == form.email.data) except DoesNotExist: flash("Your email or password does not exist.") else: if check_password_hash(user.password, form.password.data): login_user(user) flash("You have been logged in.") return redirect(url_for(".index")) else: flash("Your email or password does not exist.") return render_template("login.html", form=form)
def login(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): # login and validate the user... user = User.query.filter_by(email=form.email.data).first() user.update_login_info(request.environ['REMOTE_ADDR']) db.session.add(user) db.session.commit() login_user(user) flash('Logged in successfully !', category='success') return redirect(request.args.get('next') or url_for('index')) return render_template('user/login.html', form=form)
def login(): ''' Login form ''' form = LoginForm(request.form) # make sure data are valid, but doesn't validate password is right if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() # we use werzeug to validate user's password if user and check_password_hash(user.password, form.password.data): # the session can't be modified as it's signed, # it's a safe place to store the user id session['user_id'] = user.id flash('Welcome %s' % user.name) return redirect(url_for('user.home')) flash('Wrong email or password', 'error-message') return render_template('user/login.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): email = form.email.data password = form.password.data user_email, user_pwd_hash, user_name = load_user(email) if user_email is None: flash('User not present') elif not bcrypt.checkpw(password.encode('utf8'), user_pwd_hash): flash('Incorrect Password!') return redirect(url_for('user.login')) else: session['email'] = user_email session['name'] = user_name return redirect(url_for('index')) return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('user.account')) form = LoginForm() if form.validate_on_submit(): user = users.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('Login Successful.') return redirect(next_page) if next_page else redirect( url_for('main.register')) else: flash('Login Unsuccessful. Please check email and password') else: print(form.errors) 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).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) session['user_id'] = user.public_key next_page = request.args.get('next') flash(f'Hi {user.full_name}') if not next_page or url_parse(next_page).netloc != '': return redirect(url_for('main.home')) else: return redirect(next_page) flash('Email or password incorrect please try again') return redirect(url_for('user.login')) return render_template('login.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = users.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 current_user.admin is True: return (redirect(next_page) if next_page else redirect( url_for("admin.ldrbrd"))) else: return (redirect(next_page) if next_page else redirect( url_for("user.quiz"))) else: flash("Login Unsuccessful. Please check email and password") else: print(form.errors) return render_template("login.html", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('users.index')) form_login = LoginForm() form_register = RegisterForm() if form_login.validate_on_submit(): # check user existst user = User.query.filter_by(username=form_login.username.data).first() if user and bcrypt.check_password_hash(user.password, form_login.password.data): login_user(user, remember=form_login.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('main.index')) else: flash('Login Unsuccessful. Please check username and password', 'danger') return render_template('user/login.html', title='Login', form_login=form_login, form_register=form_register)
def login(): if current_user.is_authenticated: return redirect_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.endpoint return redirect( url_for(next_page)) if next_page else redirect_home() else: flash( 'Login unsuccessful. Please check email and password and try again.', 'danger') return render_template('login_user.html', title='Login', login_user_form=form)