def index(): '''Login form to enter a room.''' if current_user.is_authenticated: return redirect(url_for('.chat')) admin = is_admin(g.session, current_user) form = LoginForm() if form.validate_on_submit(): username = form.username.data password = form.password.data try: user = get_user(g.session, username, password) login_user(user) session['username'] = username session['name'] = f'{user.first_name} {user.last_name}' session['room'] = form.room.data return redirect(url_for('.chat')) except Exception as err: return render_template('index.html', msg=str(err), form=form, admin=admin, svg=Markup( svg_contents('./app/static/socks.svg'))) elif request.method == 'GET': form.username.data = session.get('name', '') form.room.data = session.get('room', '') return render_template('index.html', form=form, admin=admin, svg=Markup(svg_contents('./app/static/socks.svg')))
def login(): if current_user.is_authenticated: return redirect(url_for("main.index")) gset = GeneralSetting.query.get(1) if not gset: flash("You were redirected to the setup.", "info") return redirect(url_for("main.install")) 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", "danger") return redirect(request.full_path) else: 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("login.html", title=page_title("Login"), form=form)
def login(): form = LoginForm() if form.validate_on_submit(): flash('Login requested for user {}, remember_me={}'.format( form.username.data, form.remember_me.data)) return redirect('/index') return render_template('login.html', title='Sign In', form=form)
def login(): # print('--main----login-----') if g.user is not None and g.user.is_authenticated: # 如果已认证则进入index页 return redirect(url_for('leaf.index')) form = LoginForm() # 如果 validate_on_submit在表单提交请求中被调用,它将会收集所有的数据,对字段进行验证,如果所有的事情都通过的话, # 它将会返回True,表示数据都是合法的。 if form.validate_on_submit(): session['remember_me'] = form.remember_me.data user_name = form.user_name.data user = User.query.get(user_name) if not user: flash(gettext('没有该用户,请检查!')) return render_template('login.html', title=gettext('登录'), form=form) password = form.password.data if password != user.password: flash(gettext('密码错误,请重新输入!')) return render_template('login.html', title=gettext('登录'), form=form) # 登录 login_user(user, remember=form.remember_me.data) next = request.args.get('next') return redirect(next or url_for('leaf.index')) return render_template('login.html', title=gettext('登录'), form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.home_page')) # we create an instance of the form the user inputted form_login = LoginForm() # we want to check that the form submitted by the username exists, so we can check the email address exists: to # do this, we query to see if there's any value in the column email which matches to the email the user inputted # in the form. first else statement = correct login details, the second else statement is where the query returns # no users matching that email if form_login.validate_on_submit(): if form_login.validate_on_submit(): user = User.query.filter_by(email=form_login.email.data).first() if user is None or not user.check_password( form_login.password.data): flash('Invalid username or password', 'danger') return redirect(url_for('main.login')) else: login_user(user, remember=form_login.remember.data) flash('Login successful!', 'success') next_page = request.args.get( 'next' ) # will get the page the user wanted to go to before they were redirected to login return redirect(next_page) if next_page else redirect( url_for('main.home_page') ) # will redirect user to the page they requested before they tried to log in, # otherwise they will be redirected to home. return render_template('login.html', title='Login Page', form=form_login)
def process_login(): next_url = request.args.get('next') form = LoginForm() if form.validate_on_submit(): user_json = admin_api_client.authenticate_user(form.email_address.data, form.password.data) if user_json: user = User.from_json(user_json) login_user(user) session['organisation_name'] = "GDS Notify" if next_url and next_url.startswith('/admin'): return redirect(next_url) return redirect(url_for('.view_dashboard')) else: flash("no_account", "error") return render_template( "login.html", form=form, **get_template_data()), 403 else: return render_template( 'login.html', **get_template_data(form=form) ), 400
def login(): 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.remember_me.data) return redirect(request.args.get('next') or url_for('main.index')) flash('invalid username or password') return render_template('auth/login.html', form=form)
def login_view(self): form = LoginForm(request.form) if helpers.validate_form_on_submit(form): user = form.get_user() login.login_user(user) if login.current_user.is_authenticated: return redirect(url_for('.index')) self._template_args['form'] = form return super(MyView,self).index()
def index(): """Login form to enter a room.""" form = LoginForm() if form.validate_on_submit(): session['name'] = form.name.data session['room'] = form.room.data return redirect(url_for('.chat')) elif request.method == 'GET': form.name.data = session.get('name', '') form.room.data = session.get('room', '') return render_template('index.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('main.login')) login_user(user, remember=form.remember_me.data) return redirect(url_for('main.index')) return render_template('login.html', title='Sign In', form=form)
def sign_in(): if current_user and current_user.is_authenticated: return redirect(url_for('main.choose_account')) form = LoginForm() if form.validate_on_submit(): user = user_api_client.get_user_by_email_or_none(form.email_address.data) user = _get_and_verify_user(user, form.password.data) if user: if user.state == 'pending': return redirect(url_for('main.resend_email_verification')) if session.get('invited_user'): invited_user = session.get('invited_user') if user.email_address.lower() != invited_user['email_address'].lower(): flash("You can't accept an invite for another person.") session.pop('invited_user', None) abort(403) else: invite_api_client.accept_invite(invited_user['service'], invited_user['id']) session['user_details'] = { 'id': user.id, 'email': user.email_address, } if user.is_active: if user.auth_type == 'email_auth': return sign_in_email(user.id, user.email_address) elif user.auth_type == 'sms_auth': return sign_in_sms(user.id, user.mobile_number) # Vague error message for login in case of user not known, # locked, inactive or password not verified flash(Markup( ( "The email address or password you entered is incorrect." " <a href={password_reset}>Forgot your password</a>?" ).format(password_reset=url_for('.forgot_password')) )) other_device = current_user.logged_in_elsewhere() return render_template( 'views/signin.html', form=form, again=bool(request.args.get('next')), other_device=other_device )
def sign_in(): if current_user and current_user.is_authenticated: return redirect(url_for("main.show_accounts_or_dashboard")) form = LoginForm() if form.validate_on_submit(): login_data = { "user-agent": request.headers["User-Agent"], "location": _geolocate_ip(get_remote_addr(request)), } user = User.from_email_address_and_password_or_none(form.email_address.data, form.password.data, login_data) if user and user.locked: flash( _("Your account has been locked after {} sign-in attempts. Please email us at [email protected]").format( user.max_failed_login_count ) ) abort(400) if user and user.state == "pending": return redirect(url_for("main.resend_email_verification")) if user and session.get("invited_user"): invited_user = InvitedUser.from_session() if user.email_address.lower() != invited_user.email_address.lower(): flash(_("You cannot accept an invite for another person.")) session.pop("invited_user", None) abort(403) else: invited_user.accept_invite() requires_email_login = user and user.requires_email_login if user and user.sign_in(): if user.sms_auth and not requires_email_login: return redirect(url_for(".two_factor_sms_sent", next=request.args.get("next"))) if user.email_auth or requires_email_login: args = {"requires_email_login": True} if requires_email_login else {} return redirect(url_for(".two_factor_email_sent", **args)) # Vague error message for login in case of user not known, inactive or password not verified flash(_("The email address or password you entered is incorrect.")) other_device = current_user.logged_in_elsewhere() return render_template( "views/signin.html", form=form, again=bool(request.args.get("next")), other_device=other_device, )
def login(): 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('main.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('login.html', title='Sign In', form=form)
def login(): form = LoginForm(request.form) status = 200 if request.method == 'POST' and form.validate(): user = User.query.filter_by(username=form.username.data).first() if user and user.validate(form.password.data): login_user(user) flash('Logged in successfully.') return redirect(url_for('main.index')) else: flash('Invalid Credentials') status = 401 return render_template('login.html', form=form), status
def login(): form = LoginForm() # if user email and password are valid, save info in session and direct to download/scraping home page if form.validate_on_submit(): mail = validate_email(form.email.data, form.password.data) if mail: session["email"] = form.email.data session["pass"] = form.password.data flash('You have been logged in!', 'success') return redirect(url_for('main.home')) else: flash('Login Unsuccessful. Please check username and password', 'danger') return render_template('login.html', title='Login', form=form)
def sign_in(): if current_user and current_user.is_authenticated: return redirect(url_for('main.choose_service')) form = LoginForm() if form.validate_on_submit(): user = user_api_client.get_user_by_email_or_none(form.email_address.data) user = _get_and_verify_user(user, form.password.data) if user and user.state == 'pending': flash("You haven't verified your email or mobile number yet.") return redirect(url_for('main.sign_in')) if user and session.get('invited_user'): invited_user = session.get('invited_user') if user.email_address != invited_user['email_address']: flash("You can't accept an invite for another person.") session.pop('invited_user', None) abort(403) else: invite_api_client.accept_invite(invited_user['service'], invited_user['id']) if user: # Remember me login if not login_fresh() and \ not current_user.is_anonymous and \ current_user.id == user.id and \ user.is_active: confirm_login() services = service_api_client.get_services({'user_id': str(user.id)}).get('data', []) if (len(services) == 1): return redirect(url_for('main.service_dashboard', service_id=services[0]['id'])) else: return redirect(url_for('main.choose_service')) session['user_details'] = {"email": user.email_address, "id": user.id} if user.is_active: user_api_client.send_verify_code(user.id, 'sms', user.mobile_number) if request.args.get('next'): return redirect(url_for('.two_factor', next=request.args.get('next'))) else: return redirect(url_for('.two_factor')) # Vague error message for login in case of user not known, locked, inactive or password not verified flash(Markup(( "The email address or password you entered is incorrect." " <a href={password_reset}>Forgot your password</a>?" ).format(password_reset=url_for('.forgot_password')) )) return render_template('views/signin.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(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=True) flash('User logged in!','success') return redirect(url_for('main.home')) else: flash('Unsuccessful Login','danger') return redirect(url_for('main.login')) return render_template('login.html', title='Login',form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = datadef.User.query.filter_by( username=form.username.data).first() if user: if user.check_password(form.password.data): login_user(user, remember=form.remember.data) return redirect(url_for('main.index')) return '<h1>Invalid username or password</h1>' return render_template('/login.html', form=form)
def sign_in(): if current_user and current_user.is_authenticated: return redirect(url_for('main.choose_service')) form = LoginForm() if form.validate_on_submit(): user = user_api_client.get_user_by_email_or_none(form.email_address.data) user = _get_and_verify_user(user, form.password.data) if user and user.state == 'pending': return redirect(url_for('main.resend_email_verification')) if user and session.get('invited_user'): invited_user = session.get('invited_user') if user.email_address != invited_user['email_address']: flash("You can't accept an invite for another person.") session.pop('invited_user', None) abort(403) else: invite_api_client.accept_invite(invited_user['service'], invited_user['id']) if user: # Remember me login if not login_fresh() and \ not current_user.is_anonymous and \ current_user.id == user.id and \ user.is_active: confirm_login() services = service_api_client.get_services({'user_id': str(user.id)}).get('data', []) if (len(services) == 1): return redirect(url_for('main.service_dashboard', service_id=services[0]['id'])) else: return redirect(url_for('main.choose_service')) session['user_details'] = {"email": user.email_address, "id": user.id} if user.is_active: user_api_client.send_verify_code(user.id, 'sms', user.mobile_number) if request.args.get('next'): return redirect(url_for('.two_factor', next=request.args.get('next'))) else: return redirect(url_for('.two_factor')) # Vague error message for login in case of user not known, locked, inactive or password not verified flash(Markup(( "The email address or password you entered is incorrect." " <a href={password_reset}>Forgot your password</a>?" ).format(password_reset=url_for('.forgot_password')) )) return render_template('views/signin.html', form=form)
def index(): global thread_rfid, exitRFID form = LoginForm() if request.method == "POST": if form.validate_on_submit(): username = form.user.data user = User.query.filter_by(username=username).first() if user is None or form.rfid.data == "": flash(unicode("O utilizador não existe!", "utf8")) elif form.rfid.data == "" and not check_password_hash( user.password_hash, form.pwd.data): flash(unicode("A palavra-passe está incorreta!", "utf8")) else: login_user(user) # creates new row at Task table new_task = Task(username=username, begin=datetime.now(), task=form.task.data) db.session.add(new_task) db.session.commit() session['task_id'] = new_task.id if request.remote_addr == "127.0.0.1": exitRFID = True if form.task.data == "production": return redirect(url_for('production.production')) elif form.task.data == "maintenance": return redirect(url_for('main.maintenance')) elif form.task.data == "setup": return redirect(url_for('main.setup')) elif form.task.data == "data": return redirect(url_for('main.data')) else: flash("Preencha todos os campos!") else: if request.remote_addr == "127.0.0.1": print("begin thread") exitRFID = False # thread_rfid = Thread(target=rfid_proc, # args=(current_app._get_current_object(),)) # thread_rfid.daemon = True # thread_rfid.start() return render_template('index.html', form=form, rpi=(request.remote_addr == "127.0.0.1"))
def login(): if current_user.is_authenticated: return redirect(url_for('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') return redirect(next_page) if next_page else redirect( url_for('home')) else: flash('login unsuccessful', 'danger') return render_template('login.html', title='Login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) login_form = LoginForm() if login_form.validate_on_submit(): user = User.query.filter_by(username=login_form.username.data).first() if user is None or not user.check_password(login_form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=login_form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template("login.html", title="Sign In", form=login_form)
def login(): if g.user.is_authenticated(): return redirect(url_for('main.personal')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.name.data).first() if user.verify_password(form.password.data): login_user(user) if not user.confirmed: flash('You registration is not finished, please, confirm your accout by link from email', 'info') return redirect(url_for('main.personal')) else: form.password.errors.append('Invalid password') return render_template('login.html', form=form, user=g.user)
def sign_in(): if current_user and current_user.is_authenticated: return redirect(url_for('main.show_accounts_or_dashboard')) form = LoginForm() password_reset_url = url_for('.forgot_password', next=request.args.get('next')) redirect_url = request.args.get('next') if form.validate_on_submit(): user = User.from_email_address_and_password_or_none( form.email_address.data, form.password.data) if user and user.state == 'pending': return redirect( url_for('main.resend_email_verification', next=redirect_url)) if user and session.get('invited_user'): invited_user = InvitedUser.from_session() if user.email_address.lower() != invited_user.email_address.lower( ): flash("You cannot accept an invite for another person.") session.pop('invited_user', None) abort(403) else: invited_user.accept_invite() if user and user.sign_in(): if user.sms_auth: return redirect(url_for('.two_factor', next=redirect_url)) if user.email_auth: return redirect( url_for('.two_factor_email_sent', next=redirect_url)) # Vague error message for login in case of user not known, locked, inactive or password not verified flash( Markup( (f"The email address or password you entered is incorrect." f" <a href={password_reset_url}>Forgotten your password?</a>" ))) other_device = current_user.logged_in_elsewhere() return render_template('views/signin.html', form=form, again=bool(redirect_url), other_device=other_device, password_reset_url=password_reset_url)
def index(): # If user is already authenticated, redirect to user dashboard if current_user.is_authenticated: return redirect(url_for('private.user', username=current_user.username)) # if not, prepare the login form 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('main.index')) 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('private.user', username=current_user.username) return redirect(next_page) return render_template('index.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = LoginForm() if form.validate_on_submit(): if form.email.data == "*****@*****.**" and ( form.password.data == "root" or form.password.data == "123"): # IDEA: mudar para uma coisa mais segura admin = Admin.query.filter_by(email=form.email.data).first() login_user(admin) flash("Você foi logado com sucesso", "success") return redirect(url_for('main.home')) else: flash( "Nao foi possivel logar. Por favor entre em contato com o administrador do sistema", "danger") return render_template('login.html', title="Login", form=form)
def login(): # Demonstration of sessions only (i.e. not an actual login function!). Set the session cookie with a value for # email address. form = LoginForm() if request.method == "POST": session['name'] = request.form['email'] return redirect(url_for('main.index')) return render_template("login.html", form=form)
def login(): login_form = LoginForm() if login_form.validate_on_submit(): user = User.query.filter_by(username=login_form.username.data).first() if user: if login_user(DbUser(user)): # do stuff flash("You have logged in") return redirect( request.args.get('next') or url_for('main.index')) flash('Invalid username or password') title = 'Login' return render_template('login.html', login_form=login_form, title=title)
def login(): form = LoginForm() if request.method == "POST": 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.remember_me.data) return redirect(url_for("main.index")) flash(u"用户名不存在或密码验证失败,请检查您的输入!", "warning") return render_template("auth/login.html", form=form)
def index(): global thread_rfid, exitRFID form = LoginForm() if request.method == "POST": if form.validate_on_submit(): username = form.user.data user = User.query.filter_by(username=username).first() if user is None or form.rfid.data == "": flash(unicode("O utilizador não existe!", "utf8")) elif form.rfid.data == "" and not check_password_hash(user.password_hash, form.pwd.data): flash(unicode("A palavra-passe está incorreta!", "utf8")) else: login_user(user) # creates new row at Task table new_task = Task(username=username, begin=datetime.now(), task=form.task.data) db.session.add(new_task) db.session.commit() session["task_id"] = new_task.id if request.remote_addr == "127.0.0.1": exitRFID = True if form.task.data == "production": return redirect(url_for("production.production")) elif form.task.data == "maintenance": return redirect(url_for("main.maintenance")) elif form.task.data == "setup": return redirect(url_for("main.setup")) elif form.task.data == "data": return redirect(url_for("main.data")) else: flash("Preencha todos os campos!") else: if request.remote_addr == "127.0.0.1": print("begin thread") exitRFID = False # thread_rfid = Thread(target=rfid_proc, # args=(current_app._get_current_object(),)) # thread_rfid.daemon = True # thread_rfid.start() return render_template("index.html", form=form, rpi=(request.remote_addr == "127.0.0.1"))
def login(): form = LoginForm() if request.method == 'POST': user = User.query.filter_by(username=form.username.data).first() verified = user.verify_password(form.password.data) if user is None or not verified: return redirect(url_for('main.login', **request.args)) login_user(user) return redirect(request.args.get('next') or url_for('main.index')) return render_template('login.html', form=form)
def sign_in(): if current_user and current_user.is_authenticated: return redirect(url_for('main.show_accounts_or_dashboard')) form = LoginForm() if form.validate_on_submit(): login_data = { "user-agent": request.headers["User-Agent"], "location": _geolocate_ip(request.remote_addr) } user = User.from_email_address_and_password_or_none( form.email_address.data, form.password.data, login_data) if user and user.state == 'pending': return redirect(url_for('main.resend_email_verification')) if user and session.get('invited_user'): invited_user = InvitedUser.from_session() if user.email_address.lower() != invited_user.email_address.lower( ): flash("You can't accept an invite for another person.") session.pop('invited_user', None) abort(403) else: invited_user.accept_invite() if user and user.sign_in(): if user.sms_auth: return redirect( url_for('.two_factor', next=request.args.get('next'))) if user.email_auth: return redirect(url_for('.two_factor_email_sent')) # Vague error message for login in case of user not known, locked, inactive or password not verified flash(_("The email address or password you entered is incorrect.")) other_device = current_user.logged_in_elsewhere() return render_template('views/signin.html', form=form, again=bool(request.args.get('next')), other_device=other_device)
def login(): if current_user.is_authenticated: print("User is authenticated!") return redirect(url_for('main.fun')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by( username=form.username.data.lower()).first() if user is None or not user.check_password(form.password.data): flash("Wrond password or username") print("wrong password mate") return redirect(url_for('main.login')) login_user(user, remember=False) print("[Login] {} logged in {}".format(user.username, datetime.utcnow())) return redirect(url_for('main.fun')) flash('login for {} with password {} is failed'.format( form.username.data, form.password.data)) return render_template("login.html", form=form)
def login(): """ :summary: :return: """ form = LoginForm() if 'user' in session: # 使用blueprint后,index前加blueprint名称; return redirect(url_for('main.index')) if form.validate_on_submit(): session['remember_me'] = form.remember_me.data from app.models import User u = User.query.filter(User.username == form.username.data).first() if u is not None and form.password.data == u.password: session['user'] = pickle.dumps(u) return redirect(url_for('.index')) else: error = 'Incorrect username or password. Please try again.' return render_template('login.html', title='Sign In', form=form, error=error) return render_template('login.html', title='Sign In', form=form)
def login(): if current_user is not None and current_user.is_authenticated(): return redirect(url_for('main.index')) registerForm = RegisterForm(request.form, prefix="registerForm") loginForm = LoginForm(request.form, prefix="loginForm") # log in user if request.method == 'POST': if request.form['submit'] == 'login' \ and loginForm.validate_on_submit(): user = User.query.filter_by(email=loginForm.email.data).first() if user and bcrypt.check_password_hash(user.passwd, loginForm.passwd.data): login_user(user) return redirect(request.args.get('next') or url_for('main.index')) flash('Wrong email or password', 'error-message') return render_template('register.html', form="login", loginForm=loginForm, registerForm=registerForm)
def login(): form = LoginForm() if form.validate_on_submit(): next = request.args.get("next") return redirect(next or url_for("auth.panel")) return render_template("main/login.html", form=form)