def index(): ctime = time.time() form = LoginForm() get_login_cd(session, ctime) if form.validate_on_submit(): if not check_login_cd(session, ctime): return redirect(url_for('login.index')) login_succ = False with sessionScope() as sessionDb: role = sessionDb.query(MAccount).get(form.account.data) _hash = passwdHash(form.password.data) if role and role.passwd == _hash: userLogin(role.uin, session) login_succ = True if login_succ: set_login_cd(session, ctime, succ=True) return redirect(url_for('game.index')) else: set_login_cd(session, ctime, succ=False) return redirect(url_for('login.index')) else: pass return render_template( 'login.html', title='Login', form=form)
def login(): forms = LoginForm() #实例化forms if request.method == 'POST' and forms.validate_on_submit( ): #提交的时候进行验证,如果数据能被所有验证函数接受,则返回true,否则返回false data = forms.data #获取form数据信息(包含输入的用户名(account)和密码(pwd)等信息),这里的account和pwd是在forms.py里定义的 admin = User.query.filter_by( name=data["account"]).first() #查询表信息admin表里的用户名信息 if admin == None: return jsonify({ "descraption": u"username is wrong!! ", "errno": 1002, "errmsg": u"failed", }) #操作提示信息,会在前端显示 elif admin != None and not admin.check_pwd( data["pwd"]): #这里的check_pwd函数在models 下Admin模型下定义 return jsonify({ "descraption": u"password is wrong!! ", "errno": 1003, "errmsg": u"failed", }) session['name'] = data['account'] #匹配成功,添加session db.session.commit() try: return redirect(request.args.get('next') or url_for('indexpage')) #重定向到下一页 except Exception as e: logging.error(e) print(e) finally: session['name'] = data['account'] # 匹配成功,添加session return redirect(request.args.get('next') or url_for('indexpage')) # 重定向到下一页 return render_template('login.html', form=forms)
def login(): title = "Login" template_vars = {"title": title} form = LoginForm() if form.validate_on_submit(): auth = firebase.auth() try: user_data = auth.sign_in_with_email_and_password( request.form["email"], request.form["password"]) except: return render_template("login.html", vars=template_vars, form=form, is_error=True) ev_bool = db.child('User').child(user_data['localId']).child( 'UserDetails').child('emailVerified').get().val() if (ev_bool == "true"): session['uid'] = user_data['localId'] session['logged_in'] = True return redirect('/trips') else: return render_template("login.html", vars=template_vars, form=form, not_verified=True) return render_template("login.html", vars=template_vars, form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user_name = form.user_name.data user = LoginForm.validate_password(form, None) login_user(user) return redirect('/index/' + user_name) return render_template('login.html', form=form)
def login(): # pdb.set_trace() # login functionality is implemented here # for GET requests, display the login form. For POST requests attempt to authenticate form = LoginForm(csrf_enabled=True) # instantiate the LoginForm with anti-CSRF enabled next = request.args.get('next') if form.validate_on_submit(): # and request.method=='POST': # Login and validate the user # fetch the data from the form fields username = form.username.data password = form.password.data remember_me = False # ** need to implement on form # store username and password in encrypted session??? session['username'] = username session['password'] = password if 'remember_me' in request.form: remember_me = True # make a call to the wrapper my_company = current_app.config['COMPANY'] netsuite_key = current_app.config['NETSUITE_API_KEY'] # Retrieve key from instance/config file json_obj = get_whoami(key=netsuite_key, un=username, pw=password, company=my_company) # flash("json_obj : {}".format(json_obj['response']['Read']['Project'])) auth = False if 'response' in json_obj and 'Auth' in json_obj['response']: auth = True if (json_obj['response']['Auth']['@status'])=='0' else False else: flash('There seems to be a problem with the OpenAir or Netsuite Server:' + str(json_obj)) return render_template('login.html', form=form) if auth: session['associate'] = '%s, %s' % (json_obj['response']['Whoami']['User']['addr']['Address']['last'], json_obj['response']['Whoami']['User']['addr']['Address']['first']) session['associate_title'] = '%s' % (json_obj['response']['Whoami']['User']['type']) session['associate_email'] = '%s' % (json_obj['response']['Whoami']['User']['addr']['Address']['email']) session['associate_id'] = '%s' % (json_obj['response']['Whoami']['User']['id']) session['logged_in'] = True # for session timeout to work we must set session permanent to True # session.permanent = True flash('Logged in successfully.') next = request.args.get('next') if next: session['currentpage'] = str(str(next).split('//')[-1:]).split('.')[:1] else: session['currentpage'] = 'projects' return redirect(next or url_for('mod_tempus_fugit.index')) flash('Sorry! Your password or username is invalid. Kindly try again.') return render_template('login.html', form=form)
def index(): """ Redirect to Login Form to enter a chat room """ form = LoginForm() if form.validate_on_submit(): session['name'] = form.name.data return redirect(url_for('.chat')) elif request.method == 'GET': form.name.data = session.get('name', '') return render_template('index.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): if (form.email.data == admin_user and form.password.data == admin_password): return render_template("success.html") else: return render_template("denied.html") return render_template("login.html", form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user_name = form.username.data password = form.password.data user_model = UsersModel(db.get_connection()) exists = user_model.exists(user_name, password) if (exists[0]): session['username'] = user_name session['user_id'] = exists[1] return redirect("/index") return render_template('login.html', title='Авторизация', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() user = db_sess.query(User).filter(User.email == form.email.data).first() if user and user.check_password(form.password.data): login_user(user, remember=form.remember_me.data) return redirect("/") return render_template('login.html', message="Неправильный логин или пароль", form=form) return render_template('login.html', title='Авторизация', form=form)
def login_view(self): # handle user login 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')) link = '<p>Don\'t have an account? <a href="' + url_for('.register_view') + '">Click here to register.</a></p>' self._template_args['form'] = form self._template_args['link'] = link return super(MyAdminIndexView, self).index()
def login(): login_form = LoginForm(request.form) if request.method == 'POST' and login_form.validate(): if valid_password(login_form): login_user(User(login_form.username.data)) return redirect("/") else: flash("wrong_password") return redirect("/login") return render_template('login.html', login_form=login_form, register_form=RegisterForm())
def login_view(self): print("route-login-admin"); form = LoginForm(request.form) if helpers.validate_form_on_submit(form): user = form.obtem_login() login.login_user(user) if login.current_user.is_authenticated: return redirect(url_for('.index')) link = '<p>nao tem conta ainda ?<a href="' + url_for('.register_view') + '"> crie uma conta agora!</a></p>' self._template_args['form'] = form self._template_args['link'] = link return super(MyAdminIndexView, self).index()
def login_view(self): # handle user login form = LoginForm(request.form) if helpers.validate_form_on_submit(form): log = open(config.LOG_PATH+config.DIVIDER+'login_log.txt', 'a') log.write("user {} logged in at {}\n".format(form.get_user().email, str(datetime.now()))) log.close() 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(CustomAdminIndexView, self).index()
def loginCheck(): form=LoginForm() if 'username' in session and session['username']!='': return redirect(url_for('userHome')) if request.method=='POST': if form.validate()==True: password_check=PasswordCheck(request.form['user'],request.form['password']) if password_check==1: session['username']=request.form['user'] GetUserData(session['username']) return redirect(url_for('userHome')) else: return render_template('site2/login.html',form=form,errors=1) else: return render_template('site2/login.html',form=form,errors=0) else: return render_template("site2/login.html",form=form,errors=0)
def login(error=None): form = LoginForm() if form.validate_on_submit(): user_name = form.username.data password = form.password.data user_model = UsersModel(db.get_connection()) exists = user_model.exists(user_name, password) if exists[0]: session['username'] = user_name session['user_id'] = exists[1] else: return redirect('/login/notexist') return redirect("/") return render_template('login.html', title='Login', text="Авторизоваться", form=form, error=error)
def login(error=None ): # Now there are User1, User2, User3 with the same passwords form = LoginForm() if form.validate_on_submit(): user_name = form.username.data password = form.password.data user_model = UsersModel(db.get_connection()) exists = user_model.exists( user_name, str(md5(bytes(password, encoding='utf-8')).hexdigest())) # encoding if exists[0]: session['username'] = user_name session['user_id'] = exists[1] else: return redirect('/login/notexist') return redirect("/index") return render_template('login.html', title='Login', form=form, error=error)
def init_root(): print 'login uin',session.get('uin',None) ctime = time.time() form = LoginForm() get_login_cd(session, ctime) if form.validate_on_submit(): if not check_login_cd(session, ctime): return redirect(url_for('login.index')) if form.account.data != u'root': return render_template('404.html') else: pass with sessionScope() as sessionDb: role = sessionDb.query(MAccount).get(form.account.data) _hash = passwdHash(form.password.data) if not role: role_root = MAccount( uin=u'root', passwd=_hash, group=u'root', registration_ip=unicode(request.remote_addr), ) sessionDb.add(role_root) userLogin(role_root.uin, session) return redirect(url_for('edit.index')) else: if role.passwd == _hash: set_login_cd(session, ctime, succ=True) userLogin(role.uin, session) return redirect(url_for('edit.index')) else: set_login_cd(session, ctime, succ=False) return redirect(url_for('login.init_root')) return render_template('404.html') else: pass return render_template( 'login.html', title='InitRoot', form=form)
def login(): method = request.method if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): cursor = connection.cursor() cursor.execute( f'SELECT id, username, name, password_hash FROM users where users.username = (%s)', (form.username.data, )) user_data = cursor.fetchone() user = User(user_data[0], user_data[1], user_data[2]) user.password_hash = user_data[3] if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) return redirect(f'/user/{user.id}') return render_template('index.html', title='Sign In', form=form)
def login(region): """The view for the login page""" try: error = '' form = LoginForm(request.form) if request.method == "POST" and form.validate(): attempted_username = form.username.data attempted_password = form.password.data user_found = users.filter_by(username=attempted_username, region=region).first() password = user_found.password if attempted_password == password: session['logged_in'] = True session['username'] = user_found.username session['icon'] = user_found.iconPath return redirect(url_for('edit_database', region=region)) else: print('invalid credentials') error = 'Invalid credentials. Please, try again.' return render_template('login.html', error=error, region=region, form=form) except Exception as e: return render_template('login.html', error=str(e), region=region, form=form)
def login(): form = LoginForm(request.form) next = request.args.get('next') if request.method == "POST": if form.validate(): user = data_layer.getUser(form.username.data, form.password.data) if not user: print("user does not exist") return abort(400) user = WolUser(user[0], user[1], user[2]) login_user(user) if not is_safe_url(next): print("unsafe redirect") return abort(400) print("redirecting to {}".format(next or url_for("index"))) return redirect(next or url_for("index")) else: print("invalid form") return abort(400) return render_template("login.html", form=form, next=next)
def login(error=None): form = LoginForm() if form.validate_on_submit( ): # checking if a login form fields are all valid user_name = form.username.data password = form.password.data user_model = UsersModel(db.get_connection()) exists = user_model.exists( user_name, str(md5(bytes(password, encoding='utf-8')).hexdigest()) ) # checking if a user with login user_name and password hash md5(password) if exists[0]: session['username'] = user_name session['user_id'] = exists[1] else: return redirect( '/login/notexist' ) # if password and login are invalid redirect to /login/ return redirect("/index") return render_template('login.html', title='Авторизация', form=form, error=error)
def login(): global flag_perm form = LoginForm() if form.validate_on_submit(): user_name = form.username.data password = form.password.data perm = form.remember_me.data user_model = UsersModel(db.get_connection()) exists = user_model.exists(user_name, password) if exists[0]: session['username'] = user_name session['user_id'] = exists[1] if perm: session.permanent = True flag_perm = True else: session.permanent = False flag_perm = True return redirect("/index") else: return render_template('login.html', form=form, error=1) return render_template('login.html', title='Авторизация', form=form)
def login(request): if request.method == 'GET': form = LoginForm() return render_to_response('login.html', RequestContext(request, {'form': form,})) else: form = LoginForm(request.POST) if form.is_valid(): username = request.POST.get('username', '') password = request.POST.get('password', '') user = auth.authenticate(username=username, password=password) if user is not None and user.is_active: request.session['member_id'] = user.pk request.session['user']=username auth.login(request, user) #return render_to_response('file_center.html', RequestContext(request,{"session":sess})) return HttpResponseRedirect("/files_center") else: notice="Your account isn't actived" return render_to_response('login.html', RequestContext(request, {'form': form, 'notice': notice})) else: return render_to_response('login.html', RequestContext(request, {'form': form,}))
def login(): # Форма входа form = LoginForm() # POST if form.validate_on_submit(): # Создание сессии подключения к БД session = db_session.create_session() # Проверка существования пользователя и правильности введённого пароля user = session.query(Users).filter( Users.login == form.login.data).first() if user and user.check_hashed_password(form.password.data): # Логин пользователя login_user(user, remember=form.remember_me.data) # Перенаправление на главную страницу return redirect('/') # Если данные не верны, сообщение об ошибке return render_template('login.html', message='Неправильный логин или пароль!', form=form) return render_template('login.html', form=form)
def login(): form = LoginForm() already = False if 'username' in session: return redirect("/logout") if form.validate_on_submit(): user_name = form.username.data password = form.password.data user_model = UsersModel(db.get_connection()) exists = user_model.exists(user_name, password) already = False if (exists[0]): alredy = True session['username'] = user_name session['user_id'] = exists[1] if UsersModel(db.get_connection()).get( session['user_id'])[6] == 'teacher': return redirect("/index_teacher") return redirect("/index") return render_template('login.html', title='Авторизация', form=form, already=already)
def login(): if current_user.is_authenticated: return redirect("/") form = LoginForm() print(form.data) if form.submit.data is True: session = db_session.create_session() user = session.query(User).filter( User.email == form.email.data).first() if user and user.check_password(form.password.data): login_user(user) return redirect("/") return render_template("login.html", message="Неправильный логин или пароль", form=form) return render_template("login.html", title="Авторизация", form=form)
def login(): if request.method == "GET": form = LoginForm() return render_template("login.html", next=request.args.get("next")) if request.method == "POST": form = LoginForm(request.form) if form.validate(): uid = validate_login(*form.as_args()) if perform_login(uid): return "", 200 # logged in, redirect to target page return abort(403) # logging in with a user that doesn't exist (login failed) return jsonify(form.errors), 400 # form doesn't validate return abort(404) # not GET or POST
def login(): if request.method == 'POST': form = LoginForm() user_name = request.form.get('username', None) password = request.form.get('password', None) print(user_name, password) user = User(user_name, password) temp_users = User.query.filter_by(username=user_name).all() if not (temp_users and len(temp_users) > 0): error = "username does not exist!" return render_template('login.html', title="Log In", error=error) if password == temp_users[0].password: login_user(user) flash("{0} were successfully logged in.".format( current_user.username)) return redirect( url_for('homepage', title="{0}".format(user.username))) else: error = "username and password do not match!" return render_template('login.html', title="Log In", error=error) return render_template('login.html', title="Log In")
def login(): form = LoginForm() if form.validate_on_submit( ) and form.username.data == "test" and form.password.data == "test": return redirect('/success') return render_template('login.html', title='Авторизация', form=form)
def login(): if 'username' in session and session['username']!='': name=session['username'] return redirect(url_for("userHome")) form=LoginForm() return render_template("site2/login.html",form=form,errors=0)
def login(): form = LoginForm() if form.validate_on_submit(): return redirect('/index') return render_template('login.html', title='Авторизация', form=form)