def login(): loginform=Login() if request.method == "POST" and loginform.validate_on_submit(): username=loginform.username.data password=loginform.password.data if username=="admin" and password=="1234": return redirect(url_for('userinfo')) profile=db.engine.execute("select * from profiles join users on profiles.userid=users.userid where profiles.username='******' and password='******' limit 1") print(profile.rowcount) if (profile.rowcount!=0): for y in profile: session['userid']=str(y.userid) session['fname']=y.firstname session['lname']=y.lastname session['email']=y.email session['username']=y.username session['location']=y.countryliving session['biography']=y.biography getprofilepic=db.engine.execute("select photourl from gallery where photoid="+str(y.profilepic)) for m in getprofilepic: session['profilepic']=m.photourl followings=db.engine.execute("select count(fuserid) as following from friendship where userid='"+str(session['userid'])+"'") follower=db.engine.execute("select count(userid) as following from friendship where fuserid='"+str(session['userid'])+"'") for x in followings: # print(x.following) session['following']=x.following for z in follower: session['followers']=z.following return redirect('posts') else: flash('Username or Password is incorrect.','danger') return render_template('login.html',form=loginform)
def login(): if 'logged_in' in session: flash('Jesteś już zalogowany.', 'danger') return redirect(url_for('main_logged_in')) try: form = Login() if form.validate_on_submit(): password = find.find_password_by_email(form.email.data) if password == None: flash('Błędny login lub hasło. Spróbuj ponownie.', 'danger') return render_template('login.html', title='Login', form=form) if form.email.data and sha256_crypt.verify(str(form.password.data), password): rights = find.find_rights_by_email(form.email.data) session['logged_in'] = True session['username'] = find.find_username_by_email( form.email.data) username = session['username'] flash(f'Cześć {username}!', 'success') return redirect(url_for('main_logged_in')) else: flash('Błędny login lub hasło. Spróbuj ponownie.', 'danger') return render_template('login.html', title='Login', form=form) except Exception as e: return str(e)
def login(): form = Login() verify_code = form.verifyCode.data u = User.query.filter_by(username=form.username.data).first() if not form.validate_on_submit(): print('errors', form.errors) if form.validate_on_submit(): if u: if u.verify_password(form.password.data): # print(session['verifyCode']) # print(verify_code) # 利用正则 re.I 来忽略输入的验证码的大小写 if re.compile(verify_code, re.I).findall(session['verifyCode']): # 用户登录 login_user(u, remember=form.username.data) flash('欢迎%s登录' % form.username.data) return redirect( request.args.get('next') or url_for('main.index')) else: flash('验证码错误') else: flash('无效密码') else: flash('无效用户名') return render_template('user/login.html', form=form)
def login(): form = Login() if request.method == "POST": # change this to actually validate the entire form submission # and not just one field if form.validate_on_submit(): # Get the username and password values from the form. username = form.username.data password = form.password.data user = User.query.filter_by(username=username).first() if user is not None and check_password_hash(user.password, password): login_user(user) payload = {'sub':'12345' , 'name':username } token = jwt.encode(payload, 'some-secret', algorithm='HS256').decode('utf-8') return jsonify(error=None, data={'token': token}, message="Token Generated", LoginState = "Success") #return jsonify(LoginState = "Success" ) else: return jsonify(LoginState = "Fail" ) else: return jsonify(LoginState = "Failure")
def login(): form = Login() if current_user.is_authenticated: return redirect(url_for('home')) if form.validate_on_submit(): email = form.email.data password = form.password.data user_doc = get_user(email) if user_doc.to_dict() is not None: password_from_db = user_doc.to_dict()['password'] if check_password_hash(password_from_db, password): user_data = UserData(user_doc.to_dict()['name'], email, password) user = UserModel(user_data) login_user(user) flash(u'Bienvenido de nuevo!', 'success') return redirect(url_for('home')) else: flash('Información no validad', 'error') else: flash('El usuario no existe!', 'error') return redirect(url_for('auth.login')) return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('Convert')) form = Login() if request.method == 'POST' and form.validate_on_submit(): email = form.email.data password = form.password.data user = User.query.filter_by(email=email).first() if user is not None and check_password_hash(user.password, password): remember_me = False if 'remember_me' in request.form: remember_me = True session['logged_in'] = True login_user(user, remember=remember_me) session['logged_in'] = True return redirect(url_for('Convert')) else: flash('Username or Password is incorrect.', 'danger') return render_template('login.html', form=form)
def post(self): form = LoginForm(request.form) if form.validate(): session_util.login(form.account) return redirect(url_for('profile')) return self.render_template(form=form)
def login(): signin = None form = Login() if form.validate_on_submit(): username = form.username.data password = form.password.data signin = login_account(username, password) return render_template('login.html', form=form, signin=signin)
def dispatch_request(self): form = Login(request.form) if form.validate_on_submit(): user = db.session.query(models.User).filter_by(username=form.username.data).first() login_user(user) return redirect(url_for('login')) session['come-in-user'] = json.dumps(form.errors) return redirect(url_for('login'))
def login(): if current_user.is_authenticated: return redirect(url_for('main_page')) login_form = Login() 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): return redirect(url_for('login')) login_user(user) return redirect(url_for('index')) return render_template('login.html', form=login_form)
def login(): form = Login() if form.validate_on_submit(): username = form.username.data password = form.password.data is_remember = True if form.remember.data else False user = models.users.query.filter_by(username=username).first() if user is None or password != user.password: flash('用户名或密码错误') else: login_user(user, remember=is_remember) next = request.args.get('next') return redirect(next or url_for('index')) return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = Login() 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) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('home')) else: flash('Please check your credentials', 'danger') return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('dashboard'), current_user=current_user) form = Login() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is None or not user.check_password(form.password.data): flash('Invalid email or password') return redirect(url_for('login')) login_user(user) return redirect(url_for('dashboard')) return render_template('login.html', form=form)
def do_login_post(request): form = Login(request.POST) if not form.is_valid(): return do_login_get(request,"Invalid form entry") data = form.cleaned_data username = str(data['username']) password = str(data['password']) #otp = str(data['random_pass']) token = request.POST.get('token') if db.validate_login(request,username,password,token): #return HttpResponse(str({"id":"login","status":"success","msg":"Welcome " + username})) return render(request,'app/user_page.html',{'msg':'Welcome ' + str(username)}) else: return do_login_get(request,"Invalid login details")
def login(): form = Login() if form.validate_on_submit(): u = User.query.filter_by(username=form.username.data).first() if not u: flash('该用户不存在') elif not u.confirm: flash('未激活') elif u.checked_password_hash(form.password.data): flash('登陆成功') cache.clear() login_user(u, remember=form.remeber.data) return redirect(url_for('main.index')) else: flash('请输入正确的密码') return render_template('user/login.html', form=form)
def do_login_post(request): form = Login(request.POST) if not form.is_valid(): return do_login_get(request, "Invalid form entry") data = form.cleaned_data username = str(data['username']) password = str(data['password']) #otp = str(data['random_pass']) token = request.POST.get('token') if db.validate_login(request, username, password, token): #return HttpResponse(str({"id":"login","status":"success","msg":"Welcome " + username})) return render(request, 'app/user_page.html', {'msg': 'Welcome ' + str(username)}) else: return do_login_get(request, "Invalid login details")
def login(): if current_user.is_authenticated: return redirect(url_for("habit_UsR")) form = Login() if form.validate_on_submit(): # Iniciar sesion con bdd user = User.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash("Nombre de usuario o contraseña incorrecta.") return redirect(url_for("login")) login_user(user, remember=form.remember_me.data) flash("Iniciaste session correctamente, Hola {}".format( form.username.data)) #Para reconocer admin o recepcionista if user.type_User == "admin": return redirect("/habit_admin") return redirect("/habit_UsR") return render_template("login.html", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('feed')) form = Login() if not form.validate_on_submit(): print('Form did not validate ') if form.validate_on_submit(): citizen = Citizen.query.filter_by( citizen_id=form.citizen_id.data).first() if citizen is None or not citizen.check_password(form.password.data): flash('Incorrect Citizen ID or Password') return redirect(url_for('login')) login_user(citizen) if citizen.permission != 'admin': return redirect(url_for('feed')) else: return redirect(url_for('admin_board')) return render_template('login.html', form=form, links=get_links(), title="Login")
def login(): # If user is logged in and tries to access login page, redirect them to index if current_user.is_authenticated: return redirect(url_for("index")) form = Login() 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): # Increment user's number of visits user.visited += 1 db.session.commit() # Log in user and redirect to page they were attempting to visit login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for("index")) # If submitted password doesn't match db, flash warning and keep on login page else: flash(f"Unsuccessful login, please check email and password", category="danger") return render_template("login.html", title="Log In", form=form)
def dispatch_request(self): if current_user.is_authenticated: try: user = db.session.query(models.User).filter_by(id=current_user.username).first().username except Exception: logout_user() return redirect(url_for('login')) return render_template('login.html', user=user) else: register_form = Register() login_form = Login() register_errors = json.loads(session.get('new-user', '{}')) login_errors = json.loads(session.get('come-in-user', '{}')) session.pop('new-user', None) session.pop('come-in-user', None) return render_template('login.html', register_form=register_form, login_form=login_form, register_errors=register_errors, login_errors=login_errors)
def do_login_get(request, msg=""): form = Login() resp = render(request, 'app/login.html', {'login_form': form, 'msg': msg}) return resp
def login(): form = Login() if form.validate_on_submit() and request.method == 'POST': flash('Login successful!') return render_template("base.html", title="Home") return render_template("form.html", title='Login', form=form)
def logout(): flash("Logged out successfully!!!","success") loginform=Login() return redirect('login')