def login(): form = LoginForm(request.form) if form.validate(): user = User.objects.get(email=request.form['email']) password = request.form['password'] if isinstance(password, list): password = ''.join([str(i) for i in password]) logger.debug('user: {0} password (actual): {1} password (attempted): {2} length diff: {3}'.format(user.email, user.hashed_password, password, len(user.hashed_password) - len(password))) #logger.debug('logging in {0} with pw {1}'.format(user.email, password)) if user.try_login(request.form['password']): logger.debug('logging in user: {0}'.format(user.email)) print 'login_user', login_user(user) flask.flash('Logged in successfully.') # user is now logged in so a redirect will suffice return redirect('home') else: logger.debug('invalid user creds for {0}'.format(user.email)) else: logger.error('invalid form') return render_template('index.html', form=form)
def login(): # Determine initial welcome message (bonus point) register_redirect = request.args.get('register_redirect') if register_redirect is not None: login_message = register_redirect else: login_message = LOGIN_MESSAGE # Main logic login_form = LoginForm(request.form) if request.method == 'POST': if login_form.validate(): username = request.form['username'] password = request.form['password'] validated_user = login_validation(username, password) if validated_user: login_user(validated_user) return redirect(url_for('dashboard_page.dashboard')) else: return render_template( 'login.html', form=login_form, error_message=LOGIN_FAILURE, ) else: return render_template( 'login.html', form=login_form, error_message=FORM_INVALID, ) else: return render_template( 'login.html', form=login_form, register_redirect=login_message, )
def login(): form = LoginForm(request.form) if request.method == "POST" and form.validate(): username = form.username.data password = form.password.data result = get_user(username) if result: if sha256_crypt.verify(password, result.password): flash("Giriş İşlemi Başarılı", "success") session["logged_in"] = True session["id"] = result.id session["username"] = username session["name_lastname"] = f"{result.name} {result.last_name}" return redirect(url_for("index")) else: flash("Girilen Şifre Hatalı", "danger") return redirect(url_for("login")) else: flash("Kullanıcı Adı ve Şifre Hatalı", "danger") return redirect(url_for("login")) else: return render_template("login.html", form=form)
def login(): if not session.get('logged_in'): loginForm = LoginForm(request.form) registrationForm = RegistrationForm(request.form) if request.method == 'POST': username = request.form['username'].lower() password = request.form['password'] if loginForm.validate(): if credentials_valid(username, password): session['logged_in'] = True session['username'] = username return jsonify({ "message": "success", "status": 200, "username": username, }) return jsonify({ "message": "success", "status": 200, }) return jsonify({ "message": "invalid username or password", "status": 200, }) return jsonify({ "message": "both fields required", "status": 200, }) return render_template('landing.html', form=registrationForm) return redirect(url_for('home.home'))
def api_login(): if not session.get('logged_in'): loginForm = LoginForm(request.form) if request.method == 'POST': print("LOGIN request.data", request.data) print("LOGIN is_json", request.is_json) if "username" in request.form: username = request.form['username'].lower() password = request.form['password'] if loginForm.validate(): if credentials_valid(username, password): session['logged_in'] = True session['username'] = username return jsonify({ "message": "success", "status": 200, "username": username, "source": "api", "isAuthenticated": True }) return json.dumps({'status': 'Invalid user/pass'}) elif request.is_json is True: json_data = request.get_json() username = json_data["username"] password = json_data["password"] if credentials_valid(username, password): session['logged_in'] = True session['username'] = username # return json.dumps({'status': 'success', "username": username, "source": "api"}) return jsonify({ "message": "success", "status": 200, "source": "api", "isAuthenticated": True }) return jsonify({ "message": "invalid username or password", "status": 200, "isAuthenticated": False }) return jsonify({ "message": "both field required", "status": 200, "isAuthenticated": False }) user = get_user() return jsonify({ "message": "success", "status": 200, "source": "api", "isAuthenticated": True })
def login(): loggedInUser = getLoggedUser(getUserSessionId(request)) if loggedInUser != None: return redirect('/') form = LoginForm() if request.method == 'POST': if not form.validate(): return render_template('login_form.html', isUserLoggedIn=False, form=form, form_name="Login", action="login", method='POST') else: username = form.username.data password_hash = getPasswordHash(form.password.data) db = PostgresDb() response = db.sqlalchemy_session.query(Users).filter( Users.username == username).filter( Users.password_hash == password_hash).all() if len(response) != 1: return render_template('login_form.html', isUserLoggedIn=False, form=form, form_name="Login", action="login", method='POST') user_id = response[0].user_id new_uuid = str(uuid.uuid4()) new_session = UserSessions(user_id=user_id, session_id=new_uuid) db.sqlalchemy_session.add(new_session) try: db.sqlalchemy_session.commit() except DatabaseError as e: db.sqlalchemy_session.rollback() print(e) response = make_response(redirect('/')) response.set_cookie(session_id_key, new_uuid) return response return render_template('login_form.html', isUserLoggedIn=False, form=form, form_name="Login", action="login", method='POST')
def login(): form = LoginForm() if request.method == 'POST': if form.validate(): try: res = db.session.query(OrmUser).filter(OrmUser.user_email == form.user_email.data).one() except: form.user_email.errors = ['user doesnt exist'] return render_template('login.html', form=form) if res.user_password == form.user_password.data: newSession(res.user_email, res.user_password) return redirect('/') else: form.user_password.errors = ['wrong password'] return render_template('login.html', form=form) else: return render_template('login.html', form=form) else: return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit() and form.validate(): session = Session(bind=engine) client = session.query(User, Client, Profile).select_from(User).join(Client).join(Profile).filter( Profile.mail == form.mail.data). \ filter(User.check_password(Profile.password, form.password.data)).first() friend = session.query(User, Friend, Profile).select_from(User).join(Friend).join(Profile). \ filter(Profile.mail == form.mail.data). \ filter(User.check_password(Profile.password, form.password.data)).first() if friend is None and client is None: flash('Invalid username or password') return redirect(url_for('login')) user = friend if friend is not None else client login_user(user.User, remember=True) return redirect(url_for('index')) return render_template('login.html', title='Sign In', form=form)
def dispatch_request(self): form = LoginForm() register_form = RegisterForm() if request.method == 'POST': if not form.validate(): flash("please enter valid information") return redirect(url_for('user.login')) else: username = request.form['username'] password = request.form['password'] if login_function(username, password): user_details = get_user_details(username) login_session['username'] = username login_session['name'] = user_details['name'] login_session['account'] = user_details['account_num'] login_session['balance'] = user_details['balance'] return redirect(url_for('landing.home')) return redirect(url_for('user.login')) # user_auth = Login(username, password) # r = user_auth.login_user() # # if hasattr(r, 'status_code') and r.status_code == 200: # record = r.json() # login_session['username'] = username # login_session['name'] = record['name'] # login_session['account'] = record['accountNumber'] # return redirect(url_for('landing.home')) # return redirect(url_for('user.login')) return render_template('login.html', form=form, register_form=register_form)