def login(): if session.get('user_id', -1) == -1: form = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() if session.get('user_id', -1) != -1: username = db_sess.query(User).filter(User.id == session.get('user_id')).first().name else: username = '******' if not db_sess.query(User).filter(User.email == form.email.data).first(): return render_template('login.html', title='Вход', form=form, message="Упс, пользователь не обнаружен") user = db_sess.query(User).filter(User.email == form.email.data).first() if user.check_password(form.password.data): session['user_id'] = user.id else: return render_template('login.html', title='Вход', form=form, message="wrong password") db_sess.commit() return redirect('/') if session.get('user_id', -1) != -1: username = db_sess.query(User).filter(User.id == session.get('user_id')).first().name else: username = '******' return render_template('login.html', title='Вход', form=form, username=username) else: return redirect('/')
def login(): form = LoginForm() if request.method == 'GET': user_login = session.get('login') or request.cookies.get('login') if user_login: return redirect('/') return render_template('login.html', form=form) if request.method == 'POST': if not form.validate(): return render_template('login.html', form=form) else: user = UserPackage() login_res = user.login_user(request.form['login'], request.form['password']).values[0, 0] if login_res == 1: response = make_response(redirect('/')) session['login'] = request.form['login'] if request.form.get('remember_me'): expires = datetime.now() + timedelta(days=60) response.set_cookie('login', request.form['login'], expires=expires) session['login'] = request.form['login'] return response elif login_res == 0: return render_template('login.html', form=form, problem='Невірний пароль або логін') else: return render_template('login.html', form=form, problem='А вто тут прям помилка')
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="Incorrect login or password", form=form) return render_template('login.html', title='Authorization', 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 post(self): x = request # 获取用户传过来的参数(api的参数为json数据) data = request.json # 将数据与LoginForm进行绑定 form = LoginForm(data=data) # 检查用户是否合法 user = form.validate() # 生成token token = create_token(uid=user.user_profile_id) return generate_response(data={"token":token})
def login(): form = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() user = db_sess.query(User).filter( (User.email == form.username.data.lower()) | (User.username == form.username.data.lower())).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="Incorrect password or login", form=form) return render_template('login.html', title='Sing in', form=form)
def login(): # login form = LoginForm() # login form if form.validate_on_submit(): db_sess = db_session.create_session() # create session user = db_sess.query(User).filter( User.name == form.name.data).first() # find user if user and user.check_password(form.password.data): # check user login_user(user, remember=form.remember_me.data) # remember user return redirect("/horoscope") return render_template('login.html', # error message="Неправильный логин или пароль", form=form) return render_template('login.html', title='Авторизация', form=form) # see the login website
def login(): con.hero.name = None form = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() user = db_sess.query(User).filter(User.name == form.name.data).first() if user and user.check_password(form.password.data): login_user(user) init_hero(form.name.data) return redirect("/main_window") return render_template('login.html', title='DarkQuest', message="Неправильный логин или пароль", form=form) return render_template('login.html', title='DarkQuest', form=form)
def post(self): # 接收用户数据 data = request.json if not data: raise ArgsTypeException(message="传参的方式不对,或没有传参") # 验证用户输入数据合法性 # 创建Form -> data绑定 -> validate form = LoginForm(data=data) # validate函数返回了合法的用户 user = form.validate() # 生成token pic = "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1016301861,2773103463&fm=26&gp=0.jpg" token = create_token(uid=user.user_profile_id) return generate_response(data={"token": token, "pic": pic})
def post(self): data = request.json if not data: raise ArgsTypeException # 将接收的数据绑定form,由form验证 form = LoginForm(data=data) # validate函数返回了合法的用户 user = form.validate() if user: # 生成token token = create_token(uid=user.user_profile_id) return generate_response(data={"token":token}) else: result = form.errors raise FormValidateException(message=result)
def login(): local_db_session = db_session.create_session() form = LoginForm() params = { "title": "Авторизация", "current_user": current_user, "form": form } if form.validate_on_submit(): user = local_db_session.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("/") params["message"] = "Неправильный логин или пароль", return render_template('login.html', **params)
def login(): parameters['message'] = "" parameters['title'] = "MEGAFACEBOOK: Авторизация" 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("/") parameters['message'] = "Неправильный логин или пароль" parameters["form"] = form return render_template('login.html', **parameters) parameters["form"] = form return render_template('login.html', **parameters)
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) if form.user_type.data == 'Обычный пользователь' and user.type == 'Обычный пользователь': return redirect("/start_logged") elif form.user_type.data == 'Администратор' and user.type == 'Администратор': return redirect("/start_dev_logged") return render_template('Login.html', message="Неправильный логин или пароль", form=form) return render_template('Login.html', title='Авторизация', form=form)
def login(): form = LoginForm() if form.submit.data: users = db.session.query_property(Users).all() count = 0 for user in users: if user.mail == form.mail.data: if user.mail == form.mail.data and user.password == form.password.data: if user.isAdmin is False: return render_template('index_logged.html') elif user.isAdmin is True: return render_template('index_dev_logged.html') else: return render_template( 'login.html', message="Неправильный логин или пароль", form=form) else: count += 1 if count == len(users): return render_template( 'login.html', message="Неправильный логин или пароль", form=form) continue return render_template('login.html', form=form)
def login(): if request.method == 'GET': return render_template('base_index.html') if request.method == 'POST': form = LoginForm(request.form) if form.validate(): username = form.data.get('username', '') password = form.data.get('password', '') admin_user = User.authenticate(username, password) if admin_user: return_status(200) else: return_status(400) else: return_status(401)
def login(): """ Если форма логина прошла валидацию, мы находим пользователя, проверяем, введен ли для него правильный пароль, если да, вызываем функцию login_user модуля flask-login и передаем туда объект нашего пользователя, а также значение галочки «Запомнить меня». После чего перенаправляем пользователя на главную страницу нашего приложения.""" form = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() user = db_sess.query(Users).filter( Users.login == form.login.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(): params = {} params["title"] = "Авторизация" params["static_css"] = url_for('static', filename="css/") params["static_img"] = url_for('static', filename="img/") 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, **params) return render_template('login.html', form=form, **params)
def post(self): form = LoginForm(self.request.arguments) if form.validate(): username = form.data.get('username', '') password = form.data.get('password', '') user = User.authenticate(username, password) if user: user.last_login_at = datetime.datetime.now() user.last_login_ip = self.request.remote_ip user.save() self.set_secure_cookie('user_id', str(user.id)) self.redirect(self.reverse_url('admin')) else: return self.return_status(400, '用户名或密码错误') else: return self.return_status(400, form.errors)
def login(): form = LoginForm() # создание формы if form.validate_on_submit(): session = db_session.create_session() user = session.query( users.User).filter(users.User.email == form.email.data).first() if user and user.check_password( form.password.data): # если верный пароль, то входим login_user(user) return redirect("/") elif user: # если неверный логин и/или пароль return render_template('login.html', message="Неправильный логин и/или пароль", form=form) else: # если пользователя не существует return render_template('login.html', message="Такого пользователя не существует", form=form) if current_user.is_authenticated: return redirect('/') return render_template('login.html', title='Авторизация', form=form)
def login(): form = LoginForm() if form.is_submitted(): if form.validate_on_submit(): user = User.query.filter(User.email == form.email.data).first() if user is None: # User doesn't exist! flash("That email is not associated with a user.") return render_template('index.html', form=form) if not user.verify_password(form.password.data): # Password is wrong! flash("The password and email combination was not found.") return render_template('index.html', form=form) session['uid'] = user.id g.user = user flash('Thanks for logging in, %s' % user.name) return redirect(url_for('index')) else: # Some deeper problem in submission flash("There was an error logging in. Please try again.") return render_template('index.html', form=form) return render_template('index.html', form=form)
def render_login(self, next_action=None, key=None, **kw): login_form = LoginForm().get_form() if next_action == 'accept': if key: # get the source provider provider_network_connection = ndb.Key(urlsafe = key).get() # get the target provider (ie. the guy clicking the email) target_provider = provider_network_connection.target_provider.get() login_form = LoginForm().get_form(obj=target_provider) if next_action == 'booking': if key: # get the patient's email booking = ndb.Key(urlsafe = key).get() patient_from_booking = booking.patient.get() login_form = LoginForm().get_form(obj=patient_from_booking) login_form['remember_me'].data = True self.render_template('user/login.html', login_form=login_form, next_action=next_action, key=key, **kw)
def login(): form = LoginForm(request.form) if request.method == 'POST': is_pwd = request.values.get('is_pwd', '') if is_pwd: username = request.values.get('email', '') password = request.values.get('password', '') if check_auth_by_mail(username, password): user = User.query.filter_by(email=username).first() else: return tpl('login.html', form=form, msg=u"用户名或者密码错误.") else: password = request.values.get('password') if password == DEFAULT_PASSWORD and not DevelopmentConfig.DEBUG: return tpl('login.html', form=form, msg=u"用户名或者密码错误.") user = form.validate() if user: login_user(user) if user.check_password(DEFAULT_PASSWORD) and not is_pwd: flash(u'您还在使用默认密码, 请及时<a href="%s">修改您的密码!</a>' % url_for('user.pwd_change'), 'danger') return redirect(request.args.get("next", "/")) return tpl('login.html', form=form, msg=u"用户名或者密码错误.") return tpl('login.html', form=form)
def login(): form = RegisterForm() form_log = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() if db_sess.query(User).filter(User.name == form.name.data).first(): return render_template('login.html', title='DarkQuest', form=form, form_log=form_log, message="Такой пользователь уже есть") user = User(name=form.name.data, data='[]') user.set_password(form.password.data) db_sess.add(user) db_sess.commit() return redirect('/fdb') return render_template('login.html', title='DarkQuest', form=form, form_log=form_log)
def reqister(): form = RegisterForm() if form.validate_on_submit(): if form.password.data != form.password_again.data: return render_template('register.html', title='Регистрация', form=form, message="Пароли не совпадают") db_sess = db_session.create_session() if db_sess.query(User).filter(User.email == form.email.data).first(): return render_template('register.html', title='Регистрация', form=form, message="Такой пользователь уже есть") user = User(name=form.name.data, email=form.email.data, results='') user.set_password(form.password.data) db_sess.add(user) db_sess.commit() login_user(user, remember=LoginForm().remember_me.data) return redirect("/") return render_template('register.html', title='Регистрация', form=form)
def login(): data = request.form print("login接收的数据: ", data) form = LoginForm(data=data) if request.method == "POST": # it_user = Userinfo.query.filter_by(email=data['email']).first().username # session["username"], session["email"] = it_user, data["email"] email = data.get('email') password = data.get('password') users = Userinfo.query.filter(Userinfo.email == email).all() for user in users: flag = check_password_hash(user.password, password) if flag: # 1、cookie 的实现机制 # response = redirect(url_for('view01.index')) # # 设置cookie,max_age是登录存在多长时间 # response.set_cookie('uid', str(user.userid), max_age=1800) # return response # 2、session的实现机制:session当成字典使用 session['uid'] = user.userid return redirect(url_for('view01.index')) else: flash("登录失败!邮箱或密码错误") return redirect(url_for('view01.login')) # if form.validate(): # flash("登录成功") # user = Userinfo.query.filter_by(email=data['email']).first().username # session["username"], session["email"] = user, data["email"] # print(session["username"]) # return redirect('/?user={}'.format(user)) # else: # flash("登录失败!") # return render_template('login.html', msg='邮箱或密码错误') return render_template('login.html', title="登录", form=form, user=Userinfo.query.get(session.get('uid')))
def post(self, next_action=None, key=None): ''' checks username, password, logs in user and redirect to start page ''' login_form = LoginForm().get_form(self.request.POST) if login_form.validate(): email = login_form['email'].data password = login_form['password'].data remember_me = login_form['remember_me'].data logging.info('(LoginHandler.post) Trying to login email: %s' % email) # Username and password check try: user = self.login_user(email, password, remember_me) user.last_login = datetime.datetime.now() user.put() # set the language from user profile self.set_language(user.language) # login was succesful, User is in the session if next_action == 'booking': # moved booking up here since it can come from any role (provider or patient) booking = ndb.Key(urlsafe=key).get() patient_from_user = db.get_patient_from_user(user) if patient_from_user.key == booking.patient: self.email_and_confirm_booking(booking) self.redirect('/patient/bookings/' + patient_from_user.key.urlsafe()) else: # check role of user, redirect to appropriate page after login if auth.PROVIDER_ROLE in user.roles: provider = db.get_provider_from_user(user) logging.info( '(LoginHandler.post) User %s logged in as provider, redirecting to profile page', user.get_email()) # check the action, if it's from a connection do that first # and then redirect back to profile page with a message if next_action == 'connect': connected_provider_key = ndb.Key(urlsafe=key) connected_provider = connected_provider_key.get() target_url = '/' + connected_provider.vanity_url + '/connect' self.redirect(target_url) elif next_action == 'accept': target_url = '/provider/network/' + provider.vanity_url + '/accept/' + key self.redirect(target_url) elif provider.display_welcome_page: self.redirect('/provider/welcome/' + provider.vanity_url) else: self.redirect('/provider/profile/%s' % provider.vanity_url) # log the event self.log_event(user, "Provider Logged In") elif auth.PATIENT_ROLE in user.roles: patient = db.get_patient_from_user(user) logging.info( '(LoginHandler.post) User %s logged in as patient, redirecting to / page', user.get_email()) self.redirect('/patient/bookings/' + patient.key.urlsafe()) else: logging.error( '(LoginHandler.post) User %s logged in without roles', user.get_email()) error_message = 'Your account is not activated. Please check your email for an activation message or <a href="/contact">contact us</a> if you require assistance.' self.render_template('user/login.html', login_form=login_form, error_message=error_message) except (InvalidAuthIdError, InvalidPasswordError), e: # throws InvalidAuthIdError if user is not found, throws InvalidPasswordError if provided password doesn't match with specified user error_message = _(u'Login failed. Try again.') self.render_template('user/login.html', login_form=login_form, error_message=error_message) except AttributeError, ae: logging.warn('User has not password, authentication fails %s' % ae)
def post(self, next_action=None, key=None): ''' checks username, password, logs in user and redirect to start page ''' login_form = LoginForm().get_form(self.request.POST) if login_form.validate(): email = login_form['email'].data password = login_form['password'].data remember_me = login_form['remember_me'].data logging.info('(LoginHandler.post) Trying to login email: %s' % email) # Username and password check try: user = self.login_user(email, password, remember_me) user.last_login = datetime.datetime.now() user.put() # set the language from user profile self.set_language(user.language) # login was succesful, User is in the session if next_action == 'booking': # moved booking up here since it can come from any role (provider or patient) booking = ndb.Key(urlsafe=key).get() patient_from_user = db.get_patient_from_user(user) if patient_from_user.key == booking.patient: self.email_and_confirm_booking(booking) self.redirect('/patient/bookings/' + patient_from_user.key.urlsafe()) else: # check role of user, redirect to appropriate page after login if auth.PROVIDER_ROLE in user.roles: provider = db.get_provider_from_user(user) logging.info('(LoginHandler.post) User %s logged in as provider, redirecting to profile page', user.get_email()) # check the action, if it's from a connection do that first # and then redirect back to profile page with a message if next_action == 'connect': connected_provider_key = ndb.Key(urlsafe=key) connected_provider = connected_provider_key.get() target_url = '/' + connected_provider.vanity_url + '/connect' self.redirect(target_url) elif next_action == 'accept': target_url = '/provider/network/' + provider.vanity_url + '/accept/' + key self.redirect(target_url) elif provider.display_welcome_page: self.redirect('/provider/welcome/' + provider.vanity_url) else: self.redirect('/provider/profile/%s' % provider.vanity_url) # log the event self.log_event(user, "Provider Logged In") elif auth.PATIENT_ROLE in user.roles: patient = db.get_patient_from_user(user) logging.info('(LoginHandler.post) User %s logged in as patient, redirecting to / page', user.get_email()) self.redirect('/patient/bookings/' + patient.key.urlsafe()) else: logging.error('(LoginHandler.post) User %s logged in without roles', user.get_email()) error_message = 'Your account is not activated. Please check your email for an activation message or <a href="/contact">contact us</a> if you require assistance.' self.render_template('user/login.html', login_form=login_form, error_message=error_message) except (InvalidAuthIdError, InvalidPasswordError), e: # throws InvalidAuthIdError if user is not found, throws InvalidPasswordError if provided password doesn't match with specified user error_message = _(u'Login failed. Try again.') self.render_template('user/login.html', login_form=login_form, error_message=error_message) except AttributeError, ae: logging.warn('User has not password, authentication fails %s' % ae)