Beispiel #1
0
def login():
    form = LoginForm()
    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, remember=form.remember.data)
            #below lines accesses query param and allows a redirect to the page a user was previously trying to access.
            next_page = request.args.get('next')
            #ternery conditional
            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
        else:
            flash('Login Unsucessful. Please check email and password.',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    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, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
        else:
            flash('Login unsuccessfull!Please check Username and Password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #3
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    form = LoginForm()
    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, remember=form.remember.data)
            next_page = request.args.get("next")
            return redirect(next_page) if next_page else redirect(
                url_for("main.home"))
        else:
            flash("Login Unsuccessful. Please check email and password",
                  "danger")
    return render_template("login.html", title="Login", form=form)
Beispiel #4
0
def login():
    form = LoginForm()

    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, remember=form.remember.data)
            next_page = request.args.get('next')

            return redirect(next_page) if next_page else redirect(
                url_for('hello'))
        flash("login failed check your email and password", 'danger')

    return render_template('login.html', title="login", form=form)
Beispiel #5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    else:
        form = LoginForm()
        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, remember=form.remember.data)
                flash('You have been logged in!', 'success')
                return redirect(url_for('home'))
            else:
                flash('Login Unsuccessful. Please check username and password',
                      'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #6
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.hello'))
    form = LoginForm()
    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, remember=form.remember.data)
            next_page = request.args.get('next')

            return redirect(next_page) if next_page else redirect(
                url_for('main.hello'))
        else:
            flash(f'Incorrect Email or Password entered', 'danger')
    return render_template('login.html', title="Login", form=form)
Beispiel #7
0
def login():
    if current_user.is_authenticated:  #if user is already logged in and they click the link to the login page, they are redirected to the homepage
        return redirect(url_for('main.home'))
    form = LoginForm()
    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):
            #the user is logged in if their password in database matches the password they entered into the login form
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else (url_for('main.home'))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #8
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(pw_hash=user.password,
                                               password=form.password.data):
            login_user(user=user, remember=form.remember.data)
            # fix http://127.0.0.1:5000/login?next=%2Faccount
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash(f'Login Unsuccessful.', 'danger')
    return render_template('login.html', title='Login', form=form)
def login():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = LoginForm()
    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, remember=form.remember_me.data)
            next_page = request.args.get("next")
            if next_page:
                return redirect(next_page)
            else:
                return redirect(url_for("home"))
        else:
            flash("Login unsuceesful", 'danger')
    return render_template('login.html', title="login", form=form)
Beispiel #10
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    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, remember=form.remember.data)
            # inorder to redirect to the intended page if logs in
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash("Login unsuccessful. Please check email or password",
                  "danger")
    return render_template("login.html", title='login', form=form)
Beispiel #11
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('homepage'))
    form = LoginForm()
    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, remember=form.remember.data)
            flash('Welcome {}! You are logged in'.format(user.username),
                  'success')
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('homepage'))
        else:
            flash('Login is Bad. Please check', 'danger')
    return render_template('login.html', title="Login", form=form)
Beispiel #12
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    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, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
            # this statement will direct the user to pervious opened page when not loggged
            # and direct him to the home page if he just logged in
        else:
            flash('Login unsuccessfully. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #13
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    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, remember=form.remember.data)
            next_page = request.args.get('next')
            # if we try to access account page without logging in then we will redirected to login page
            #but after we login we will be redirected to about page directly instead of home page
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #14
0
def login():
    if(current_user.is_authenticated):
        flash('already logged in')
        return redirect(url_for('main.home'))
    form = LoginForm()
    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)):
            flash(f'{form.email.data} is logged in!', 'success')
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            if next_page:
                return redirect(next_page)
            else:
                return redirect(url_for('main.home'))
        else:
            flash('Login failed. Please check email and/or password', 'danger')

    return render_template('login.html', title='Login', form=form)
Beispiel #15
0
def login():
    if current_user.is_authenticated:  # redirect to home page if user logged in and click on login button
        return redirect(
            url_for('home')
        )  # to change login icon when logged in, check layout changes done.
    form = LoginForm()
    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, remember=form.remember.data)
            next_page = request.args.get('next')  #get argument for user
            if next_page:
                return redirect(next_page)
            else:
                return redirect(url_for('home'))
        else:
            flash("please check you credentials", 'danger')
    return render_template('login.html', title="Login", form=form)
Beispiel #16
0
def login():
    if current_user.is_authenticated:
        flash('You are already logged in!', 'warning')
        return redirect(url_for('main.index'))

    form = LoginForm()
    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, remember=form.remember.data)
            next_page = request.args.get('next')
            flash(f'You have been logged in!', 'success')
            return (redirect(next_page) if next_page else redirect(
                url_for('main.index')))
        else:
            flash('Login Unsucessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='login', form=form)
Beispiel #17
0
def signin():
    if current_user.is_authenticated:
        flash(f'Already signed in!', 'success')
        return redirect(url_for('main.home'))
    form = SignInForm()
    if form.validate_on_submit():
        # fake data to check the sign in process
        # if form.email.data == '*****@*****.**' and form.password.data == 'password':
        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, remember=form.remember.data)
            next_page = request.args.get('next')
            flash(f'Sign in successful!', 'success')
            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
        else:
            flash(f'Sign in unsuccessful! Please check your credentials!',
                  'danger')
    return render_template('signin.html', title='Sign In', form=form)
Beispiel #18
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    if form.validate_on_submit(
    ):  # validate_on_submit(): This is a shortcut for form.is_submitted() and form.validate()
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            # login_user() Logs a user in. form.remember.data is  a True/False value if checked(True) or unchecked(False)
            # login_user(): This will return True if the log in attempt succeeds, and False if it fails
            login_user(user, remember=form.remember.data)
            # after loggging in, access the page you were viewing before you logged in.
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
        else:
            flash(f'Login Unsuccessful. Please check email and password!',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #19
0
def login():

    if current_user.is_authenticated:
        return redirect("home")

    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user:
            flash("User does not exist", "danger")
        else:
            if bcrypt.check_password_hash(user.password, form.password.data):
                login_user(user, remember=form.remember.data)
                flash('Login Successful', "success")
                next_page = request.args.get("next")
                return redirect(next_page) if next_page else redirect("home")
            else:
                flash("Incorrect Password", "danger")

    return render_template("login.html", form=form)
def login():
    if current_user.is_authenticated:
        flash(f'Already logged in!')
        return redirect(url_for('blog'))
    # Create an instance of your RegistrationForm to pass to a template
    form = LoginForm()
    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, remember=form.remember.data)
            next_page = request.args.get(
                'next'
            )  # args is a dictionary, but use get access for empty case (returns None)
            return redirect(next_page) if next_page else redirect(
                url_for('blog'))
        else:
            flash(
                'Login attempt unsuccessful. Please check email and password.',
                'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #21
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    if form.validate_on_submit():
        # Get the user email from the form
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            # Log the user in
            login_user(user, remember=form.remember.data)
            # Get next param from the URL
            next_page = request.args.get('next')
            if next_page:
                return redirect(next_page)
            else:
                return redirect(url_for('main.home'))
        else:
            flash('Login Unsuccesful. Please check email and password',
                  'danger')

    return render_template('login.html', title="Log In", form=form)
Beispiel #22
0
def account_login():

    if current_user.is_authenticated:
        return redirect(url_for('posts.posts_list'))

    form = LoginForm()
    if form.validate_on_submit():

        user = User.query.filter_by(email=form.email.data).first()

        if user and user.active and bcrypt.check_password_hash(
                user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('posts.posts_list'))

        flash(f'Wrong login data', 'danger')

    return render_template('accounts/account_login.html',
                           title="Login",
                           form=form)
Beispiel #23
0
def login():
    if current_user.is_authenticated:
        flash(f'无效操作:{current_user.username} 你已在登陆状态', 'danger')
        return redirect(url_for('main.home'))
    form = LoginForm()
    rest_password_form = RequestResetPasswordForm()  # modal from
    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, remember=form.remember.data)
            flash(f'登陆成功', 'primary')
            # print(dict(request.args)) # 转dict显示
            next_page = request.args.get('next')
            return redirect(
                url_for('users.account')) if next_page else redirect(
                    url_for('main.home'))
        else:
            flash(f'登陆失败 : 邮箱或密码错误', 'danger')
    return render_template('login.html',
                           form=form,
                           title='登陆',
                           rest_form=rest_password_form)
Beispiel #24
0
def login():

    if current_user.is_authenticated:
        return redirect(url_for('main.home_page'))

    form = LoginForm()

    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, remember=form.remember.data)

            # jump to the attempted page(if any) before logged in
            # using get method otherwise it would raise a error when a query with dict key from a dict is not exist
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('main.home_page'))

        else:  # could remove this unrelated else branch

            flash('Login Unsuccessful, Please check email and password', 'danger')

    return render_template('login.html', title='Login', form=form)
Beispiel #25
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    if form.validate_on_submit():
        #Take first entry where email in form matches email in database if it exists
        user = User.query.filter_by(email=form.email.data).first()

        #Check if password and password hash matches
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):

            #Log the user in. Read the docs for flask-login
            login_user(user, remember=form.remember.data)
            #Optional, adds the capability to return to the page you were trying to visit before a login prompt
            next_page = request.args.get('next')

            flash('Logged in successfully!', 'success')
            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
        else:
            flash('Login failed. Please check email and password.', 'danger')
    return render_template('login.html', form=form, title='Login')
Beispiel #26
0
def password_reset_confirm(token):

    if current_user.is_authenticated:
        return redirect(url_for('posts.posts_list'))

    form = PasswordResetForm()
    user = User.confirm_usr_verify_token(token)

    if user and form.validate_on_submit():
        """create a hashed password"""
        if not bcrypt.check_password_hash(user.password, form.password.data):
            hashed_pw = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user.password = hashed_pw

        db.session.commit()

        flash('Your password has been reset', 'success')
        return redirect(url_for('users.account_login'))

    return render_template('accounts/password_reset_confirm.html',
                           title="Password reset confirmation",
                           form=form)
Beispiel #27
0
def login():
    #incase the user is trying to login although he has been authentcated, then route him
    #to the home page
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    if form.validate_on_submit():
        #check if user exists with the email address:
        user = User.query.filter_by(email=form.email.data).first()
        password_hashed = user.password
        if user and bcrypt.check_password_hash(pw_hash=password_hashed,
                                               password=form.password.data):
            login_user(user=user, remember=form.remember.data)
            nextpage = request.args.get('next')
            flash(message=f"Login Successfull for {form.email.data}",
                  category='success')
            return redirect(nextpage) if nextpage else redirect(
                url_for('main.home'))
        else:
            flash(
                message="Login Unsuccessful. Please Check Email and Password",
                category='danger')
            return (redirect(url_for("main.home")))
    return render_template('login.html', title='Login', form=form)
Beispiel #28
0
 def verify_password(self, password):
     return bcrypt.check_password_hash(self._password_hash, password)