示例#1
0
def index():
    if current_user.is_authenticated:
        return redirect(url_for('frontend.index'))
    form = LoginForm()
    if form.validate_on_submit():
        login_user(form.admin)
        return redirect(url_for('frontend.index'))
    return render_template('login/index.html', form=form)
示例#2
0
def site_login():
    form = LoginForm()
    if form.validate_on_submit():
        try:
            user = User.objects.get(email=request.form['email'])

            if user.verify_password(request.form['password']):
                login_user(user)
                flash('Logged in successfully.', 'success')

                return redirect(request.args.get('next') or url_for('site_index'))
            else:
                flash('Username or password is incorrect', 'error')
        except User.DoesNotExist:
            flash('Username or password is incorrect', 'error')
    return render_template('site/login.html', form=form)
示例#3
0
def login():
    current_app.logger.info('ログイン処理開始')
    form = LoginForm()

    if request.method == 'POST' and form.validate_on_submit():
        current_app.logger.info('ログイン認証処理開始')
        user, authenticated = User.auth(db.session.query, form.email.data,
                                        form.password.data)
        if authenticated:
            current_app.logger.info('ログインユーザー: {}'.format(user))
            login_user(user)
            flash('ログインしました。', 'success')
            return redirect(url_for('home_view.index'))

        flash('メールアドレスかパスワードが違います', 'danger')

    return render_template('login.html', form=form)
示例#4
0
def site_register():
    form = LoginForm()
    if form.validate_on_submit():
        try:
            user = User.objects.get(email=request.form['email'])
            if user:
                flash('This email address is already in use.', 'error')
            return render_template('site/login.html', form=form)

        except User.DoesNotExist:
            user = User()
            user.email = request.form['email']
            user.username = request.form['email']
            user.set_password(request.form['password'])
            user.save()

            flash('Successfully registered', 'success')
            return redirect(url_for('site_index'))
    return render_template('site/login.html', form=form)
示例#5
0
def login() -> Response:
    login_form = LoginForm()

    if request.method == 'POST':
        if login_form.validate_on_submit():
            dict_type_form = dict(request.form)
            email: str = dict_type_form.get('email')
            password: str = dict_type_form.get('password')
            remember: bool = True if dict_type_form.get('remember') else False
            user = User.query.filter_by(email=email).first()
            if check_password_hash(pwhash=user.password, password=password):
                login_user(user, remember=remember)
                return make_response(redirect(url_for('main.profile')))
            elif not check_password_hash(pwhash=user.password,
                                         password=password):
                flash('入力されたパスワードが正しくありません')
                return make_response(redirect(url_for('auth.login')))
            else:
                flash('予期せぬエラーが発生しました')
                return make_response(redirect(url_for('auth.login')))

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