예제 #1
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        # Grab the user from our User Models table
        user = User.query.filter_by(email=form.email.data).first()

        # Check that the user was supplied and the password is right
        # The verify_password method comes from the User object
        # https://stackoverflow.com/questions/2209755/python-operation-vs-is-not

        if user is not None and user.check_password(form.password.data):
            #Log in the user

            login_user(user)
            flash('Logged in successfully.')

            # If a user was trying to visit a page that requires a login
            # flask saves that URL as 'next'.
            next = request.args.get('next')

            # So let's now check if that next exists, otherwise we'll go to
            # the welcome page.
            if next == None or not next[0] == '/':
                next = url_for('core.index')

            return redirect(next)
        else:
            flash('Invalid Username or Password')
    return render_template('login.html', form=form)
예제 #2
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        # Grab the user from our User Models table
        user = User.query.filter_by(email=form.email.data).first()

        # Check that the user was supplied and the password is right
        # The verify_password method comes from the User object
        # https://stackoverflow.com/questions/2209755/python-operation-vs-is-not

        if user.check_password(form.password.data) and user is not None:
            #Log in the user

            login_user(user)
            flash('Logged in successfully.')

            next = request.args.get('next')

            # to

            if next == None or not next[0] == '/':
                next = url_for('core.index')

            return redirect(next)
    return render_template('login.html', form=form)
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email = form.email.data).first()
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash('Log in success')
            next = request.args.get('next')
            if next == None or not next[0] == '/':
                next = url_for('core.index')
            return redirect(next)
    return render_template('login.html', form = form)
예제 #4
0
def login():
    form = LoginForm()
    # Validate the form
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash("Logged in successfully.")
            next = request.args.get("next")
            if next == None or not next[0] == "/":
                next = url_for("core.index")
            return redirect(next)
    return render_template("login.html", form=form)
예제 #5
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash('Log in was a success')

            # if a user was trying to access a page that required a log in, this will let them go to that page after log in
            next = request.args.get('next')
            if next is None or not next[0] == '/':
                next = url_for('core.index')
            return redirect(next)

    return render_template('login.html', form=form)
예제 #6
0
def login():

    form = LoginForm()

    if form.validate_on_submit():

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

        if user and user.check_password(password=form.password.data):

            login_user(user)
            flash('user logged in successfully!')
            return redirect(url_for('core.home'))

    return render_template('login.html', form=form)
예제 #7
0
파일: views.py 프로젝트: araj01/Flask_App
def login():

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

        user = User.query.filter_by(email=form.email.data).first()#so that we get email in the right format rather than list 

        if user.check_password(form.password.data) and user is not None:

            login_user(user)
            flash('Log in Success!')

            next = request.args.get('next')

            if next == None or not next[0]=='/':#if next was none or next was home page 
                next = url_for('core.index')

            return redirect(next)

    return render_template('login.html',form=form)
예제 #8
0
def login():

    form = LoginForm()

    if form.validate_on_submit():
        # フィルターをかけて検索して最初に見つかったものを返す
        user = User.query.filter_by(email=form.email.data).first()

        # userがあるか、パスワードが合っているか
        if user is not None and user.check_password(form.password.data):
            login_user(user)
            flash('Log in Success!')

            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('core.index')

            return redirect(next)
    return render_template('login.html', form=form)
예제 #9
0
def login():
    form = LoginForm()

    if form.validate_on_submit():
        # query the user that already exists
        user = User.query.filter_by(
            email=form.email.data).first()  # grab the first user
        # make sure they provided the correct password
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash("Login success")

            # grab what the user was trying to access
            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('core.index')

            return redirect(next)

    return render_template('login.html', form=form)
예제 #10
0
def login():

    form = LoginForm()

    if form.validate_on_submit():
        #query user that already exists
        user = User.query.filter_by(email=form.email.data).first()
        #check password
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash('Log In Success')

            #grabs the information the user was trying to access
            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('core.index')

            return redirect(next)

    return render_template('login.html', form=form)
예제 #11
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(form.password.data) and user is not None:
            #check_password method we created from our main models.py
            login_user(user)
            flash('Logged in successfully.')

            next = request.args.get('next')

            if next == None or not next[0] == '/':
                #if next==none means they went straight to login page
                #not next[0]=='/' means: or wasn't equal to the homepage
                next = url_for('core.index')
                #set next to the home page and then redirect them to next,
                #OR let them go to the page they were trying to view: request.args etc
            return redirect(next)
    return render_template('login.html', form=form)
예제 #12
0
def login():

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

        # buscando o user que fez o login
        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(form.password.data) and user is not None:

            login_user(user)
            flash('Log in Success!')

            # recebe a pág que o user está tentando acessar após logado e redireciona-o
            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('core.index')

            return redirect(next)

    return render_template('login.html', form=form)
예제 #13
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None or user.check_password(form.password.data) == False :
            flash('Wrong Email or Password', 'alert-danger')
            return redirect(url_for('users.login'))


        if user.check_password(form.password.data) and user is not None:
            username = user.username
            login_user(user)
            flash('Log in Success!', 'alert-success')

            next = request.args.get('next')

            if next == None or not next[0]=='/':
                next = url_for('users.user_posts', username=username)
            return redirect(next)

        else:
            flash('Wrong email or password', 'alert-warning')

    return render_template('login.html', form=form)