def login(): mySql = MySQLConnection('equip-trak') query = 'SELECT * FROM users WHERE user_name = %(user)s' data = {'user': request.form['userName']} pw_hash = mySql.query_db(query, data) if pw_hash: pw_hash = pw_hash[0] session['userId'] = pw_hash['id'] session['fName'] = pw_hash['first_name'] session['lName'] = pw_hash['last_name'] session['email'] = pw_hash['email'] print("*"*60) print(session) print(pw_hash['password']) print(request.form['password']) print(bcrypt.check_password_hash( pw_hash['password'], request.form['password'])) print("*"*60) if bcrypt.check_password_hash(pw_hash['password'], request.form['password']): session['login'] = True return redirect('/checkout') else: session['login'] = True return redirect('/checkout') return redirect('/')
def Signin(): if current_user.is_authenticated: return redirect(url_for('main.AllPosts')) form = LoginForm() if form.validate_on_submit(): user_e = User.query.filter_by(email=form.email.data).first() user_u = User.query.filter_by(username=form.email.data).first() if user_u and bcrypt.check_password_hash(user_u.password, form.password.data): login_user(user_u, remember=form.remember.data) flash('Welcome %s, You have been logged in!' % user_u.username, 'success') session.permanent = True return redirect(url_for('main.AllPosts')) elif user_e and bcrypt.check_password_hash(user_e.password, form.password.data): login_user(user_e, remember=form.remember.data) next_page = request.args.get('next') session.permanent = True flash('Welcome %s, You have been logged in!' % user_e.username, 'success') return redirect(next_page) if next_page else redirect( url_for('main.AllPosts')) else: flash( 'Login Unsuccessful. Please check email/username and password', 'danger') return render_template('signin.html', form=form, title='Signin')
def login_validation(cls, form): user = cls.query.filter_by(email=form['email']).first() print(user) if user: if bcrypt.check_password_hash(user.password, form['password']): return (True, user.id) return (False, "Email or password in incorrect")
def login(): if request.method == "POST": print("Logging in") login_email = request.form['login_email'] print(f"LOGIN EMAIL: {login_email}") print(f"REQUEST.FORM: {request.form}") query = "SELECT * FROM users WHERE email=%(email)s;" data = {'email': login_email} mysql = connectToMySQL(SCHEMA) user_info = mysql.query_db(query, data) print(f"USER INFO: {user_info}") if user_info: if bcrypt.check_password_hash(user_info[0]['password'], request.form['user_pwd']): print("Login Successful!") session['id'] = user_info[0]['id'] print(f"Added New session with ID: {session['id']}") # return render_template("dashboard.html", fname=user_info[0]['first_name']) return redirect('/dashboard') else: print(f"USER_INFO HASH: {user_info[0]['password']}") flash("Bad password") else: flash("Unknown user") return redirect('/')
def login_validate(cls, form): user = cls.query.filter_by(email=form['login_email']).first() if user: if bcrypt.check_password_hash(user.password, form['login_password']): return True, user.id return False, "Email or bad password"
def login_user(): is_valid = True if not request.form['em']: is_valid = False flash("Please enter an email.") if not EMAIL_REGEX.match(request.form['em']): is_valid = False flash("Please enter a valid email.") if not is_valid: return redirect("/") else: user_list = User.query.filter_by(email=request.form['em']).all() if not user_list: flash("Email is not valid") return redirect("/") else: user = user_list[0] if not request.form['pw']: is_valid = False flash("Please enter a password") if not bcrypt.check_password_hash(user.password, request.form['pw']): is_valid = False flash("Password is not valid") if is_valid: session['user_id'] = user.id return redirect("/tweets_landing") else: return redirect("/")
def validate_login(cls, user_info): is_valid = True match = 0 if len(user_info['email']) < 1: is_valid = False flash("Please enter your email address.", "danger") elif len(user_info['pass']) < 1: is_valid = False flash("Please enter your password.", "danger") elif not EMAIL_REGEX.match(user_info['email']): is_valid = False flash("Please enter a valid email address.", "danger") else: for user in cls.query.all(): if user.email == user_info['email']: match += 1 this_user = user session['userid'] = user.id if match < 1: is_valid = False flash("Email address is not registered.", "danger") elif match > 0: if not bcrypt.check_password_hash(this_user.password, user_info['pass']): is_valid = False flash("Incorrect username or password.", "danger") return is_valid
def login(): # Redirect to listing page if user is logged in if current_user.is_authenticated: return redirect(url_for('listing')) form = LoginForm() if form.validate_on_submit(): user = users.find_one({'email': form.email.data}) # If user exists and password matches password in db, # log in and create a user session if user and bcrypt.check_password_hash( user['password'], form.password.data.encode('utf-8')): username = user['username'] # Save session, even after browser is closed login_user(User(user), remember=form.remember.data) # Checks where to redirect the user after login next_page = request.args.get('next') flash(f'Welcome to squirrel, {username}.', 'success') # If unauthorized page has been accessed before being logged in, # redirect to it after login if it is safe if next_page and is_safe_url(next_page, socket.gethostname()): return redirect(next_page) # If not, redirect to the listing page else: return redirect(url_for('listing')) else: flash( 'Login unsucessful, please check email and password.', 'danger') return render_template('pages/login.html', title="Login", form=form)
def login(): user = User.query.filter_by(email=request.form["email"]).all() if user: hashed_pw = user[0].password if bcrypt.check_password_hash(hashed_pw, request.form['pass']): session["user_id"] = { "first": user[0].f_name, "last": user[0].l_name, "id": user[0].user_id } print("Login Sucessful") print(session["user_id"]) return redirect("/userpage") else: login_pw = False # flash("Invalid Password", "login") # return redirect("/") return render_template("partials/log_error.html", login_pw=login_pw) else: login_email = False print("test") # flash("Email not in Database", "login") # return redirect("/") return render_template("partials/log_error.html", login_email=login_email)
def login_organization(cls, form): organization = cls.query.filter_by(email=form['email']).first() if organization: if bcrypt.check_password_hash(organization.password, form['password']): return (True, organization.id) return (False, "Email or password is incorrect")
def login_check(): switch = request.form["switch"] if switch == "dev": user = Developer.query.filter_by(email=request.form["email"]).all() elif switch == "org": user = Organization.query.filter_by(email=request.form["email"]).all() for user_login in user: print(user_login.fname) print(user_login.lname) print(user_login.password) print(request.form["password"]) if user: hashed_pw = user[0].password if bcrypt.check_password_hash(hashed_pw, request.form['password']): session["user_id"] = { "first": user[0].fname, "lname": user[0].lname, "email": user[0].email, "id": user[0].id, "role": switch } print("ID:", session["user_id"]) if switch == "dev": return redirect("/dev_dash") elif switch == "org": return redirect("/{}_landing".format(switch)) else: flash("Invalid Password", "login") return redirect("/login_page#{}_log".format(switch)) else: flash("Email not registered", "login") return redirect("/login_page#{}_log".format(switch))
def login_validation(cls, login_info): is_valid = True if len(login_info['lemail']) < 1 or not EMAIL_REGEX.match( login_info["lemail"]): is_valid = False flash("Please enter your email") if len(login_info['lpassword']) < 5: is_valid = False flash("Please enter your password") if not is_valid: return is_valid user = cls.query.filter_by(email=login_info["lemail"]).first() if user: if bcrypt.check_password_hash(user.password, login_info["lpassword"]): session["user_id"] = user.id return is_valid else: is_valid = False flash("Invalid Credentials") return is_valid else: is_valid = False flash("User not Found") return is_valid return is_valid
def is_logged_in(cls, user_id, login_session): user = cls.query.get(user_id) result = False if user: if bcrypt.check_password_hash(login_session, str(user.created_at)): result = True return result
def validate_login(cls, form): user = cls.query.filter_by(email=form['email_address']).first() print(user) if user: if bcrypt.check_password_hash(user.password, form['password']): return user return None
def put(self, serial,key): schema = PostsSchema(partial=True) post = Post.find_by_serial(serial) if not post: return {"message": "There is no post with this serial. Please recheck."},404 if post.status != 'encrypted': return {"message": "This post is not encrypted. Everyone can read it."},400 if not bcrypt.check_password_hash(post.encryptionKey, key): return {"message": "This is the wrong key. We can't decrypt the message, so you can't edit it."}, 401 data = schema.load(request.get_json()) #You can change the title,category, content and status. if data.title: post.title = data.title if data.category: post.category = data.category if data.content: post.content = dataEnc.encodeString(data.content, key) if data.status and data.status != 'encrypted': post.encryptionKey = None #Removing the encryption key. post.content = dataEnc.decodeString(post.content, key) post.status = data.status try: post.save_to_db() return {"message": "Post with serial `{}` has been updated in our database.".format(serial)},200 except Exception as e: log.error("There was an error when updated an encrypted post. Check message: {}".format(e)) return {"message":"Something went wrong. We can't upload this in our database."},500
def validate_login(cls, postData): is_valid = True if len(postData["password"]) < 8: is_valid = False flash("Please enter your password.", "login") if len(postData['email']) < 1 or not EMAIL_REGEX.match( postData["email"]): is_valid = False flash("Please enter your mail address.", "login") if not is_valid: return is_valid user_exists = User.query.filter_by(email=postData["email"]).first() if user_exists: if bcrypt.check_password_hash(user_exists.password, postData["password"]): session['user_id'] = user_exists.id return is_valid else: is_valid = False flash("You have entered invalid credentials.", "login") return is_valid else: is_valid = False flash("You have entered invalid credentials.", "login") return is_valid
def login(): user = User.query.filter_by(user_name=request.form['user_name']).first() if user: if bcrypt.check_password_hash(user.hashed_pw, request.form['password']): session['userID'] = user.id return redirect('/dashboard') flash('You could not be logged in. Try agian!', 'login error') return redirect('/')
def login_user(cls, data): result = User.query.filter_by(email=data['email']).first() if bcrypt.check_password_hash(result.password, data['password']): # if we get True after checking the password, we may put the user id in session result.last_login = func.now() db.session.commit() return result flash('You could not be logged in', 'error') return
def is_logged_in_as_admin(cls, admin_id, login_session): user = cls.query.get(admin_id) result = False if user: if bcrypt.check_password_hash(login_session, str(user.created_at)): if user.user_level == 9: print("admin login_success") result = True return result
def log_validate(cls, form): user = cls.query.filter_by(username=form['un']).all() if not user: flash('Username not found', 'log_un') elif not bcrypt.check_password_hash(user[0].password, form['pw']): flash('Password is incorrect', 'log_pw') if '_flashes' in session.keys(): return False return user[0]
def login(cls, form_data): success = False user_info = Users.query.filter_by(email=form_data["email"]) if bcrypt.check_password_hash(user_info[0].password, form_data["password"]): success = True else: flash('Incorect username/password combination!') return success
def login(): user = User.query.filter_by(email=request.form['email']).first() if user and bcrypt.check_password_hash(user.pw_hash, request.form['password']): session['userid'] = user.id return redirect('/') flash('invalid email or password', 'login') return redirect('/')
def authenticate(username, password): user = active_user(username)[0] users = [User(user.user_id, user.user_email, user.password)] lusers = {u.username: u for u in users} user = lusers.get(username, None) if user and \ bcrypt.check_password_hash(user.password, password): return user else: abort(401, f'User unauthorized')
def log_validate(cls, form): user = cls.query.filter_by(email=form['email']).all() if not user: flash("email doesn't exist", 'log_em') elif not bcrypt.check_password_hash(user[0].password, form['password']): flash('invalid password or email', 'log_pw') if '_flashes' in session.keys(): return False return user[0]
def login(): user = Users.query.filter_by(email=request.form['lemail']).all() is_valid = True if len(user) == 1 and bcrypt.check_password_hash( user[0].passwordHash, request.form['lpassword']) else False if is_valid: session["logged_in"] = True session["user_id"] = user[0].id return redirect('/user/' + str(session["user_id"])) else: flash("Invalid Login Credentials", "log_error") return redirect('/')
def submitLogin(): queryUser = users.query.filter_by(email=request.form["email"]).all() if queryUser: if bcrypt.check_password_hash(queryUser[0].password, request.form["password"]): session["loggedInUserID"] = queryUser[0].id return redirect('/resetHome') flash("Incorrect password") return redirect('/login') flash("Unrecognized email") return redirect('/login')
def loginUser(email, password): user_id = False user = User.query.filter_by(email=email).first() if user: if bcrypt.check_password_hash(user.password, password): user_id = user.id else: flash("Login failed.") else: flash("Unknown user.") return user_id
def login_user(cls, data): result = User.query.filter( User.email.ilike("%{}%".format(data['email']))).first() if result: active = ActiveUser.query.filter_by(user_id=result.id).first() if active is None: return False if bcrypt.check_password_hash(result.password, data['password']): # if we get True after checking the password, we may put the user id in session db.session.commit() return result return False
def login(): mysql = MySQLConnection('dojo_tweets') query = "SELECT * FROM users WHERE users.email = %(email)s;" data = {'email': request.form['email']} user = mysql.query_db(query, data) print(user) if user: if bcrypt.check_password_hash(user[0]['password'], request.form['password']): session['userID'] = user[0]['id'] return redirect('/dashboard') flash('You could not be logged in. Try again!', 'login error') return redirect('/registration')
def validate_login(): user = User.query.filter_by(email=request.form['lemail']).all() print(user) is_valid = True if len(user) == 1 and bcrypt.check_password_hash( user[0].password, request.form['lpassword']) else False print(is_valid) if is_valid: session["logged_in"] = True session["user_id"] = user[0].id return redirect("/home") else: flash("Invalid Login Credentials", "log_error") return redirect("/login_page")