Пример #1
0
    def post(self):
        """
        Handles the HTTP POST requests (overriding :meth:`MethodView.post`) .

        If the form was correctly filled and the user password validates
        (through :meth:`~base.models.User.check_password`),
        calls :func:`flask.ext.login.login_user`,
        emits a flash message of success and redirects the request to
        the `next` parameter or the home page if not specified.

        Otherwise, emits errors as flash messages and renders the login page again.

        :return: On error, renders the login page, but redirects to value of `next` or home page on success.
        """
        form = LoginForm()
        if not form.validate_on_submit():
            flash(self._messages['invalid_data'])
            return render_template('login.html', form=form)

        user = User.get_by_email(form.email.data)
        if user and user.check_password(form.password.data):
            login_user(user)
            flash(self._messages['success'])
        else:
            flash(self._messages['invalid_auth'])
            return redirect(url_for('base.login'))

        return redirect(request.args.get('next') or url_for('base.front_page'))
Пример #2
0
    def post(self):
        """
        Handles the HTTP POST requests (overriding :meth:`MethodView.post`) .

        If the form was correctly filled and the user password validates
        (through :meth:`~base.models.User.check_password`),
        calls :func:`flask.ext.login.login_user`,
        emits a flash message of success and redirects the request to
        the `next` parameter or the home page if not specified.

        Otherwise, emits errors as flash messages and renders the login page again.

        :return: On error, renders the login page, but redirects to value of `next` or home page on success.
        """
        form = LoginForm()
        if not form.validate_on_submit():
            flash(self._messages['invalid_data'])
            return render_template('login.html', form=form)

        user = User.get_by_email(form.email.data)
        if user and user.check_password(form.password.data):
            login_user(user)
            flash(self._messages['success'])
        else:
            flash(self._messages['invalid_auth'])
            return redirect(url_for('base.login'))

        return redirect(request.args.get('next') or url_for('base.front_page'))
Пример #3
0
def login():
    if not current_user.is_anonymous:
        return redirect(
            request.args.get("next") or url_for(".index", _external=True))
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        user = None
        try:

            user = mongo.db.user.find_one({"username": username})
        except MultipleResultsFound as e:
            # TODO: deal with MultipleResultsFound
            pass
        # password_match = bcrypt.checkpw(password.encode(), user.password.encode())
        if user is None:
            flash(u"帐号或密码出错", category="danger")
            return render_template("base/login.html", form=form)
        user = User(user["username"])
        login_user(user, form.remember_me.data)
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.username))
        return redirect(
            request.args.get("next") or url_for(".index", _external=True))
    return render_template("base/login.html", form=form)
Пример #4
0
def login():
    login_form = LoginForm(request.form)
    if login_form.validate_on_submit():
        user = User.objects(email=login_form.email.data).first()
        if user and user.check_password(login_form.password.data):
            login_user(user)
            return redirect(request.args.get("next") or url_for('dashboard._dashboard'))
        else:
            flash("Login failed.", "login_error")
            # login is not valid
            return redirect('#create')
    return render_template('index.html', login_form=login_form, create_form=CreateAccountForm())
Пример #5
0
def login():
    login_form = LoginForm(request.form)
    if login_form.validate_on_submit():
        user = User.objects(email=login_form.email.data).first()
        if user and user.check_password(login_form.password.data):
            login_user(user)
            return redirect(request.args.get("next") or url_for('dashboard._dashboard'))
        else:
            flash("Login failed.", "login_error")
            # login is not valid
            return redirect('#create')
    return render_template('index.html',
                           login_form=login_form,
                           create_form=CreateAccountForm())
Пример #6
0
    def post(self):
        form = LoginForm()
        if not form.validate_on_submit():
            flash(self._messages['invalid_form'])
            return render_template('login.html', form=form)

        user = User.get_by_email(form.email.data)
        if user and user.check_password(form.password.data):
            login_user(user)
            flash(self._messages['success'])
        else:
            flash(self._messages['invalid_auth'])
            return redirect(url_for('base.login'))

        return redirect(request.args.get('next') or url_for('base.front_page'))
Пример #7
0
    def post(self):
        form = LoginForm()
        if not form.validate_on_submit():
            flash(self._messages['invalid_form'])
            return render_template('login.html', form=form)

        user = User.get_by_email(form.email.data)
        if user and user.check_password(form.password.data):
            login_user(user)
            flash(self._messages['success'])
        else:
            flash(self._messages['invalid_auth'])
            return redirect(url_for('base.login'))

        return redirect(request.args.get('next') or url_for('base.front_page'))