Ejemplo n.º 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.check_password(form.password.data) and user is not None:
            #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)
    return render_template('login.html', form=form)
Ejemplo n.º 2
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.checkPassword(form.password.data) and user is not None:
            login_user(user)
            flash('User Login Sucessfully')

            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)
Ejemplo n.º 3
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 Success!")

            #If user tried to go to unavailable page and it will redirect to this page
            next = request.args.get("next")
            if next == None or not next[0] == "/":
                next = url_for("core.index")
            return redirect(next)
    return render_template("login2.html", form=form)
Ejemplo n.º 4
0
def login():
    """ Logs the user in """
    if current_user.is_authenticated:
        return redirect(url_for('core.index'))
    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid email or password', 'warning')
            return redirect(url_for('users.login'))
        login_user(user)
        flash("You've been logged in!", 'success')

        next = request.args.get('next')
        if not next or url_parse(next).netloc != '':
            next = url_for('core.index')
        return redirect(next)
    return render_template('login.html', form=form)