Example #1
0
def login():
    mapper = inspect(User)
    for column in mapper.attrs:
        print(column.key)

    columns = inspect(User).columns.keys()

    formdata = {}

    form = LoginForm()

    formdata['form'] = form



    #formdata['form']['name'].data = 'Carlxxxx'



    # if form.validate_on_submit():
    #     formdata['name'] = form.name.data
    #     form.name.data = ''
    #     # return render_template('login.html', form=form, name=name, password=password)
    # return render_template('login.html', data = formdata)

    formdata['name'] = session.get('name')


    if form.validate_on_submit():
        session['name'] = form.name.data
        formdata['name'] = form.name.data

        # if db.session.query(User).filter(username=form.name.data).count():
        #     p = 'found'

        new_user = User(password=form.password.data, username=form.name.data)

        # try:
        #     new_user = User(password=form.password.data, username=form.name.data)
        #
        # except ValueError as e:
        #     form.name.errors.append(e)
        #     return render_template('login.html', data = formdata)
        # except:
        #     pass

        try:
            db.session.add(new_user)
            db.session.commit()
        except  exc.SQLAlchemyError as e:
            form.name.errors.append(e.orig.args[1])
            return render_template('login.html', data = formdata)


        form.name.data = ''
        return redirect(url_for('users.login'))

    return render_template('login.html', data = formdata)
Example #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('posts.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)
            return redirect(url_for('posts.home'))

    return render_template('login.html', form=form)
Example #3
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_request = request.args.get('next')
            return redirect(next_request) if next_request else redirect(url_for('main.home'))
        else:
            flash("Login Unsuccessful. Please check the username or password.", "danger")
    return render_template("login.html", title = 'Login', form=form) 
Example #4
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.lower()).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')
            flash('Logged in!', 'success')
            return redirect(next_page) if next_page else redirect(url_for('main.home'))
        else:
            flash('Login Unsuccessful. Please check email and password', 'danger')
    return render_template('login.html', title='Login', form=form)
Example #5
0
def login():

    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('.user_page', username=g.user.username))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first_or_404()

        if user.password == form.password.data:
            login_user(user)
            return redirect(url_for('.user_page', username=user.username))

    return render_template('login.html', form=form)
def login():
    form = LoginForm()

    if form.validate_on_submit():
        user = UserModel.query.filter_by(email=form.email.data).first()
        if user is not None and user.check_password(form.password.data):
            login_user(user)
            flash(f'Welcome back, {user.given_name}!')
            return redirect(url_for('core_bp.main'))

        else:
            flash('Incorrect email or password, please try again.')
            return redirect(url_for('users_bp.login'))

    return render_template('login.html', form=form)
Example #7
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('core.index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = Account.query.filter_by(email=form.email.data).first()
        if user.check_password(form.password.data):
            login_user(user)
            flash('Logged in successfully.')
            next = request.args.get('next')
            if next is None or not next[0] == '/':
                next = url_for('core.index')
            return redirect(next)
        else:
            flash("Wrong password.")
    return render_template('login.html', form=form)
Example #8
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)
            flash('Good! You have been logged in.', 'is-success')
            next_page = request.args.get('next')
            # if not is_safe_url(next_page):
            # return abort(400)
            return redirect(next_page or url_for('main.home'))
        else:
            flash('Login Unsuccessul. Try again! Your credentials is false',
                  'is-danger')
    return render_template('pages/login.html', title='login', form=form)
Example #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')
            if next_page is not None:
                if "/upvote" in next_page or "/downvote" in next_page:
                    return redirect(url_for('main.home'))
            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
        else:
            flash('Prihlásenie bolo neúspešné. Skontrolujte email a heslo',
                  'danger')
    return render_template('login.html', title='Prihlásenie', form=form)
Example #10
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    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')
            flash(f'Seja Bem vindo ao Direito Sem Preconceito {user.username}',
                  'success')
            return redirect(next_page) if next_page \
                else redirect(url_for('main.index'))

        else:
            flash('Não foi possível acessar sua conta.\
                Por favor verifique seu email e senha', 'danger')
    return render_template('login.html', title='Entrar', form=form)
Example #11
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        #判断用户是否存在
        username = form.username.data
        user = Users.query.filter_by(username=username).first()
        if not user:
            flash('用户名或密码错误')
            return render_template('users/login.html', form=form)

        password = form.password.data
        #判断密码是否正确
        if check_password_hash(user.password, password):
            #自动登录
            login_user(user, remember=form.remember_me)
            flash('恭喜你,登录成功!')
            return redirect(url_for('users.select_class'))
        else:
            flash('用户名或密码错误')

    return render_template('users/login.html', form=form)
Example #12
0
def login():
    if current_user.is_authenticated:  #if the user is already logged in
        return redirect(
            url_for("main.home"))  #redirect the user back to the home page
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first(
        )  #check if there are any emails within our database matching the email that the user entered
        if user and bcrypt.check_password_hash(
                user.password, form.password.data
        ):  #if the email exists and the password hash is valid
            login_user(user, remember=form.remember.data)

            #If the user tried to access a log-in only page and was redirected to /login, then automaticall send the user back to where they were going.
            next_page = request.args.get(
                "next"
            )  #args is a dictionary but use args.get() not args[] because [] will throw an error if the key does not exist
            return redirect(next_page) if next_page else redirect(
                url_for("main.home"))
        else:  #login is unsuccessful
            flash("Invalid!", "danger")  #danger alert (Bootstrap)
    return render_template("login.html", title="Login", form=form)
Example #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_by(user_email=form.email.data).first()
        result = bcrypt.check_password_hash(user.user_password,
                                            form.password.data)
        if result is not True:
            flash(f"{form.email.data} Something Wrong !!!", "danger")
            # return redirect(url_for('login'))
            return redirect(request.url)
        else:
            login_user(user,
                       remember=form.rememberMe.data,
                       duration=timedelta(minutes=10),
                       fresh=True)
            flash(f"{form.email.data} welcome to Home!!! ", "success")
            next_page = request.args.get("next")
            return redirect(next_page) if next_page else redirect(
                url_for('main.home'))
    return render_template("login.html", title="Login", form=form)