コード例 #1
0
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get(
            'next'
    ):  #Code to help send user back to the page on application...
        session['next'] = request.args.get(
            'next')  #..after user successfully logs in. URL saved in next

    if form.validate_on_submit():
        user = Users.query.filter_by(username=form.username.data).first()
        if user:
            if check_password_hash(user.password, form.password.data):
                session['username'] = form.username.data
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('user_app.login'))
            else:
                user = None
        if not user:
            error = 'Login was Unsuccessful. Incorect username and/or password'
    return render_template('users/login.html', form=form, error=error)
コード例 #2
0
ファイル: views.py プロジェクト: scolex/flask-forum
def login():
    form = LoginForm()
    if form.validate_on_submit():
        login_user(form.user)
        flash("Logged in successfully.")
        return redirect(request.args.get("next") or url_for("users.home"))
    return render_template("login.html", form=form)
コード例 #3
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            login_user(user)
            return redirect(url_for('main.home'))
    return render_template('users/login.html', form=form)
コード例 #4
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = db.session.query(User).get(form.user.id)
        login_user(user)
        flash(u"Successfully logged in as %s" % form.user.username,  "success")
        return redirect(request.args.get('next') or url_for('secret'))
    return render_template('login.html', form=form)
コード例 #5
0
ファイル: views.py プロジェクト: KarolJanik/sky-twitter
def login():
    if current_user.get_id():
        flash('You are already logged in!')
        return redirect('/')
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter(User.username == form.username.data).first()
        if user and user.check_password(form.password.data):
            login_user(user)
            return redirect(url_for('main.hello'))
        else:
            flash('Incorrect login info.', 'error')
    return render_template('login.html', form=form)
コード例 #6
0
def login():
    if 'email' in session:
        return redirect('/messages')
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and check_pw_hash(form.password.data, user.pw_hash):
            session['email'] = user.email
            return redirect('/messages')
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('users/login.html', title='Login', form=form)
コード例 #7
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        user = User.query.filter_by(username=username).first()
        if not user or not check_password_hash(user.password,
                                               form.password.data):
            flash('Please check your login details and try again.')
            return redirect(
                url_for('users.login')
            )  # if user doesn't exist or password is wrong, reload the page
        login_user(user)
        return redirect(url_for('users.home'))
    return render_template("login.html", form=form, title="Login")
コード例 #8
0
def login():
    ''' log in users to there account '''
    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=True)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('task.create_todo'))
    return render_template('login.html', title='login', form=form)
コード例 #9
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", 'danger')
    return render_template('login.html', title='Login', form=form)
コード例 #10
0
def login():
    form = LoginForm()
    if not form.validate_on_submit():
        return {'errors': form.errors}, 400
    email = form.email.data
    password = form.password.data
    user = User.query.filter_by(Email=email).first()
    if not user:
        return {'error': 'Email or Password does not match.'}, 403
    if not user.check_password(password):
        return {'error': 'Email or Password does not match.'}, 403
    isActive = user.Confirmed
    access_token = create_access_token(identity=user.Email, fresh=True)
    refresh_token = create_refresh_token(identity=user.Email)
    return {'is_active': isActive, 'access_token': access_token, 'refresh_token': refresh_token}, 200
コード例 #11
0
def login():
    form = LoginForm()
    if form.validate_on_submit():

        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if check_password_hash(user.password, form.password.data):
                login_user(user)
                #flash('Login successful')
        # if user has been redirected from another page
            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('core_bp.index')
                return redirect(next)
    return render_template('users/login.html', form=form)
コード例 #12
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard.dashboard_panel'))

    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)
            return redirect(url_for('dashboard.dashboard_panel'))
        else:
            flash('Invalid credentials.', 'warning')

    return render_template('users/login.html', form=form)
コード例 #13
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(User.email.ilike(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 Unsuccesful, please try again', 'danger')

    return render_template('login.html', form=form, title='Login')
コード例 #14
0
def login():
    """Handle user login."""

    form = LoginForm()

    if form.validate_on_submit():
        user = User.authenticate(form.username.data,
                                 form.password.data)

        if user:
            do_login(user)
            flash(f"Hello, {user.username}!", "success")
            return redirect("/")

        flash("Invalid credentials.", 'danger')

    return render_template('users/login.html', form=form)
コード例 #15
0
def login():
    form = LoginForm()
    error = None

    # Manage the 'next'
    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    # Check if user and pass are correct
    if form.validate_on_submit():
        username = form.username.data.lower()
        password = form.password.data.lower()
        user = Users.query.filter_by(
            username=username,
            password=password
        ).first()
        if user:
            # Add user end level to session
            session['username'] = username
            session['level'] = user.level

            # Test
            flash('Usuario %s logueado' % (user.fullname.title()))

            '''
            if 'next' in session:
                next = session.get('next')
                session.pop('next')
                return redirect(next)
            else:
            '''
            # Check access level
            if session['level'] == 20:
                return redirect(url_for('formularios'))
            elif session['level'] == 10:
                return redirect(url_for('directivos'))
            elif session['level'] == 0:
                return redirect(url_for('admin'))

        else:
            error = 'Usuario o contraseña incorrectos'

    return render_template('users/login.html', form=form, error=error)
コード例 #16
0
ファイル: views.py プロジェクト: shunyata/nobooru
def login():
    form = LoginForm(request.form)

    # If form contains valid data (not necessarily good creds)...
    if form.validate_on_submit():
        user = User.get_by_email(form.email.data)

        if user and user.check_password(form.password.data):
            login_user(user)
            flash(LOGIN_WELCOME_MESSAGE.format(username=user.name))
            # If the user was redirected to this page from a page that requires being logged in,
            # then the query parameter `next` will hold the next URL to go to.
            next_url = request.args.get("next") or url_for("users.profile")
            return redirect(next_url)

        flash(INVALID_CREDS, "error-message")

    # By passing the form into the template, we refill the fields with the values the user provided, if any.
    return render_template('users/login.html', form=form)
コード例 #17
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!')

            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)
コード例 #18
0
def login():
    form = LoginForm()
    validation = None

    if current_user.is_authenticated:
        flash('You are logged in')
        return redirect(url_for('main.index'))

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data

        password = hashlib.md5(password.encode()).hexdigest()

        user = User.query.filter_by(username=username).first()

        if user and user.password == password:
            login_user(user, form.remember_me.data)
            flash('You Have Logged In')
            return redirect(url_for('main.index'))

    return render_template('users/login.html',
                           form=form,
                           validation=validation)
コード例 #19
0
def login():
    form = LoginForm(
    )  # kreiranje bojekta klase RegistrationForm koji se kasnije prosledjuje
    if form.validate_on_submit():
        user = User.query.filter_by(
            email=form.email.data).first()  # prvo uzimam mejl sa forme
        if user and bcrypt.check_password_hash(
                user.password, form.password.data
        ):  # provera korisnika i da li je sifra koja je uneta sa forme hasovana

            login_user(user, remember=form.remeber.data
                       )  # ulogovati korisnika preko login_user funkcije

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

            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
        else:
            flash('Log in unsuccessful. Please check username and password!',
                  'danger')

    return render_template(
        'login.html', title='Register', form=form
    )  # form=form posledjivanje ovjekta klase form da se odnosi na nasu buducu html stranicu