A
A
arhansolo2019-12-17 15:17:20
Python
arhansolo, 2019-12-17 15:17:20

How to implement simple user authorization in a Flask application?

def login():
form = LoginForm()
if form.validate_on_submit():
    flash('Login requested for user {}, remember_me={}'.format(
        form.username.data, form.remember_me.data))


    return redirect('/index')
return render_template('login.html', title='Sign In', form=form)

To begin with, I would like to see how user authorization will work without the user database itself, i.e. to check when the "Login" button is pressed for a match with the value that I defined in advance. For example, I created a login condition where the user's login should be: "Login". And the password was: "Password".
I would be kind if you explain this so complicated (for me personally) topic.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2019-12-17
@arhansolo

def login():                                                                                                                                                               
    form = LoginForm()                                                                                                                                                     
    if form.validate_on_submit():                                                                                                                                                                                                                                                 
        if form.username.data == 'Login' and form.password.data == 'Password':                                          
            flash('Вы вошли')                                                                                                                                              
            return redirect('/index')                                                                                                                                      
        else:                                                                                                                                                              
            flash('Неверный логин или пароль')                                                                                                                             
    return render_template('login.html', title='Sign In', form=form)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question