Exemplo n.º 1
0
def login():
    form = LoginForm(request.form)

    if form.validate_on_submit():
        user = User.query.filter_by(login=form.login.data).first()
        if user and check_password_hash(user.password, form.password.data):
            login_user(user)
            return redirect(url_for('article_pages.article_list'))
        abort(400)
    return render_template('login.html', form=form)
Exemplo n.º 2
0
def login():
    form = LoginForm()
    if request.method == 'POST':

        if form.validate_on_submit():
            return jsonify(success=True)
        else:
            errors = form.errors.items()
            return render_template('auth/login.html', form=form, errors=errors)

    return render_template('auth/login.html', form=form)
Exemplo n.º 3
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(form.password.data):
            login_user(user, form.remember_me.data)
            page = request.args.get('next')
            if not page or not page.startswich('/'):
                page = url_for('main.index')
            return redirect(page)
        flash('无效的用户名或密码')
    return render_template('auth/login.html', form=form)
Exemplo n.º 4
0
def login():
    if current_user.is_authenticated == True:
        return redirect(url_for('users.home', user_id=current_user._id))
    form = LoginForm()
    if form.validate_on_submit():
        phone_number = form.phone_number.data
        password = form.password.data
        remember_me = form.remember_me.data

        if '@' in phone_number and phone_number == Admin.find_admin_email(
                phone_number)["email"]:
            admin_data = Admin.find_admin_email(phone_number)
            if admin_data:
                admin = Admin.classify(name=admin_data["name"],
                                       family=admin_data["family"],
                                       email=admin_data["email"],
                                       password=admin_data["password"],
                                       permission=admin_data["permission"],
                                       _id=admin_data["_id"])
                if admin.check_pw(password):
                    session["email"] = admin.email
                    login_user(user=admin, remember=remember_me)

                    return redirect(url_for('admins.admin_home'))

        user_data = User.find_one(phone_number)
        if not user_data:
            flash('User does not exists.')
            return redirect(url_for('auth.register'))
        user = User.classify1(user_data)
        # check user account time
        # if user.account_time == 'None':
        #     return redirect(url_for('payments.new_account', user_id=user._id))

        # elif user.account_time

        if user.valid_phone_number(phone_number):
            if Utils.check_password(user.password, password):
                flash("Log in successful.")
                login_user(user, remember_me)
                if user.name == 'none':
                    return redirect(url_for("users.info", user_id=user._id))
                else:
                    return redirect(url_for('users.home', user_id=user._id))
            else:
                flash("Your password was wrong.")
                return redirect(url_for('auth.login'))
        else:
            flash("The user does not exist.")
            return redirect(url_for('auth.login'))
    return render_template('auth/login.html', form=form)
Exemplo n.º 5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home.index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and 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('home.index'))
        else:
            flash('Войти не удалось. Please check email and password',
                  'danger')
    return render_template('auth/login.html', title='Login', form=form)
Exemplo n.º 6
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('common.home'))
    form = LoginForm()
    if form.validate_on_submit():
        user_service = UserService()
        user = user_service.get_user_from_username(form.username.data)
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('auth.login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('dashboard.feed')
        return redirect(next_page)
    return render_template('pages/auth/login.html', form=form)
Exemplo n.º 7
0
def auth_login():
    if request.method == "GET":
        return render_template("auth/loginform.html", form=LoginForm())

    form = LoginForm(request.form)

    if not form.validate():
        return render_template("auth/loginform.html", form=form)

    user = User.query.filter_by(email=form.email.data,
                                password=form.password.data).first()
    if not user:
        return render_template("auth/loginform.html",
                               form=form,
                               error="Incorrect email or password")

    login_user(user)

    return redirect(url_for("index"))
Exemplo n.º 8
0
def auth_login():
    #If GET request, redirect to the loginform
    if request.method == "GET":
        return render_template("auth/loginform.html", form=LoginForm())

    #Otherwise, proceed with logging in
    form = LoginForm(request.form)
    user = User.query.filter_by(username=form.username.data).first()
    #Check if user exists with name
    if not user:
        return render_template("auth/loginform.html",
                               form=form,
                               error="No such username or password")

    #If username exists, check if password exists
    if not bcrypt.check_password_hash(user.password, form.password.data):
        return render_template("auth/loginform.html",
                               form=form,
                               error="No such username or password")

    login_user(user)
    return redirect(url_for("index"))
Exemplo n.º 9
0
def login():
    form = LoginForm()
    if request.method == 'POST' and form.validate_on_submit():
        flash("You sign in to your account")
    return render_template("auth/login.html", form=form)