Exemple #1
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user=User.query.filter_by(email=form.email.data).first()
        login_user(user, form.remember_me.data)
        return redirect(url_for('.front_index'))
    return render_template('login.html',form=form)
Exemple #2
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' and form.password == 'passwordTEMP':
            flash(f'You have been logged in!', 'success')
            return redirect(url_for('home'))
        else:
            flash(
                f'Sorry, your password was incorrect. Please double-check your password.',
                'danger')

    return render_template('login.html', title='Login', form=form)
Exemple #3
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')
            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)
Exemple #4
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    login_form = LoginForm()
    if login_form.validate_on_submit():
        user = User.query.get(login_form.email_or_username.data) or \
                User.query.filter_by(email=login_form.email_or_username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               login_form.password.data):
            login_user(user, force=True)
            return redirect(url_for('home'))
        flash('Login failed. Please check your username/email and password.')
    return render_template('login-page.html', form=login_form)
Exemple #5
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if not user or not user.check_password(form.password.data):
            flash('Invalid credentials.')
            return redirect(url_for('login'))
        login_user(user)
        if user.role == 'admin':
            return redirect(url_for('user_page'))
        else:
            return redirect(url_for('exam_page'))
    return render_template('users/login.html', form=form)
Exemple #6
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if not user or not user.check_password(form.password.data):
            flash('Invalid credentials.')
            return redirect(url_for('login'))
        login_user(user)
        if user.role == 'admin':
            return redirect(url_for('user_page'))
        else:
            return redirect(url_for('exam_page'))
    return render_template('users/login.html', form=form)
Exemple #7
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('account'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password', 'danger')
            return redirect(url_for('login'))
        login_user(user)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('home')
        return redirect(next_page)
    return render_template('login.html', title="Log In", form=form)
Exemple #8
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.get_by_username(form.login.data)
        if user is None:
            form.login.errors.append("Такого пользователя не существует")
            return render_template("login.html", form=form)
        if not check_password_hash(user.password_hash, form.password.data):
            form.password.errors.append("Неправильный пароль")
            return render_template("login.html", form=form)
        session["user_name"] = user.name
        session["role"] = user.role
        session["blocked"] = user.blocked
        return redirect("/")

    return render_template("login.html", form=form)
Exemple #9
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    with open('config.json') as f:
        data = json.load(f)
    if form.validate_on_submit():
        if form.password.data == data['password']:
            user = User()
            user.id = "Rick"
            login_user(user, remember=True)
            flash('Successfully logged in!', 'success')
            return redirect(url_for('home'))
        else:
            flash('Incorrect password!', 'danger')
    return render_template('login.html', form=form, data=data)
Exemple #10
0
def login():
    # if user already logged in -> logout to login
    if current_user.is_authenticated:
        flash('חייבים להתנתק בכדי להכנס מחדש', 'error')
        return redirect(url_for("views.dashboard"))
    else:
        form = LoginForm()
        if form.validate_on_submit():
            # Get user from db
            user = User.query.filter_by(email=form.email.data).first()
            # Checking pwd
            if user and bcrypt.check_password_hash(user.password, form.password.data):
                login_user(user, remember=form.remember.data)
                #session.permanent = True
                #session['user'] = user
                # if user get here from page that needed authentication -> redirect to that page
                next_page = request.args.get('next')
                return redirect(next_page) if next_page else redirect(url_for('views.dashboard'))
            else:
                flash('הוכנסו נתונים לא נכונים', 'error')
    return render_template('login.html', form=form)
Exemple #11
0
def login():
    print(count)
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    title = 'Log In'
    if form.validate_on_submit():
        #Query by email to see if it exists in db to login
        username = user_list.query.filter_by(
            username=form.username.data).first()
        if username and bcrypt.check_password_hash(username.password,
                                                   form.password.data):
            login_user(username, remember=form.remember.data)

            #If a page accessible only to logged in users is accessed before logging in
            next_page = request.args.get('next')
            flash('Successfully logged in!', category='success')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Incorrect email or password', 'danger')
    return render_template('login.html', title=title, form=form)
def login():
    form = LoginForm()

    if current_user.is_authenticated:
        print(
            'Authenticated user attempting to login. Redirecting to index.html...'
        )
        return redirect(url_for('index'))

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None:
            return redirect(url_for('login'))

        if validate_password(form.password.data, user.hash_pw) == False:
            # TODO: Flash
            return redirect(url_for('login'))

        print('Succesfully logged in!')
        login_user(user)
        return redirect(url_for('index'))

    return render_template('login.html', form=form)
Exemple #13
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = LoginForm()
    if form.validate_on_submit():
        users = getDBData()
        print(users)
        userFoundRow = None
        if users:
            for row in users:
                print(row.username)
                if row.username.lower() == form.username.data.lower():
                    userFoundRow = row
                    break

        if userFoundRow:
            if bcrypt.check_password_hash(userFoundRow.password,
                                          form.password.data):
                login_user(User(userFoundRow), remember=form.remember.data)
                return redirect(url_for("home"))
            flash("Incorrect password specified.")
        else:
            flash("The specified household nickname was not found")
    return render_template("login.html", form=form)