Beispiel #1
0
 def post(self):
     user = User.query.filter_by(email=self.data.get('email')).first()
     if user and bcrypt.check_password_hash(user.password,
                                            self.data.get('password')):
         return {'user': {'email': user.email}, 'token': user.token}
     else:
         return {'message': 'Please enter correct email and password.'}, 400
Beispiel #2
0
def check_user_password(username: str, password: str):
    # 检查用户密码,返回一个元组 (检查结果(Bool),提示信息)
    user = is_existing_user(username)

    if user and bcrypt.check_password_hash(user.password, password):
        return True, "登陆成功"
    else:
        return False, "用户不存在或密码错误"
Beispiel #3
0
def login():
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(email = form.login_email.data).first()
            if user is not None and bcrypt.check_password_hash(user.password, form.login_password.data):
                flash('You were logged in.')
                login_user(user)
                return redirect(url_for('assets.viewassets'))
            else:
                flash('Incorrect username or password.')
    return render_template('login.html', form=form)
Beispiel #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).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            # if a link is clicked that requires a user to be logged in, this will redirect to that link after login otherwise 'main.home'
            next_page = request.args.get('next')
            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)
Beispiel #5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('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')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Login failed, please check email and password.', 'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #6
0
def set_user(uid, origin_password, username=None, new_password=None, email=None):
    user = is_existing_user(uid=uid)
    if user and bcrypt.check_password_hash(user.password, origin_password):
        if username:
            if is_existing_user(username):
                return False, "用户已存在"
            user.username = username
        if new_password:
            user.password = bcrypt.generate_password_hash(new_password)
        if email:
            if is_existing_email(email):
                return False, "邮箱已注册"
            user.email = email
        db.session.commit()
        return True, "更新用户信息成功"
    else:
        return False, "用户不存在或密码错误"
Beispiel #7
0
    def post(self):

        form = LoginForm()

        if form.validate_on_submit():

            admin = get_admin_by_username(form.username.data)

            if admin:

                if bcrypt.check_password_hash(admin.password,
                                              form.password.data):

                    token = jwt.encode(
                        {
                            'user':
                            admin.username,
                            'exp':
                            datetime.datetime.utcnow() +
                            datetime.timedelta(minutes=30)
                        },
                        app.config['ADMIN_TOKEN_SECRET_KEY']).decode('UTF-8')

                    return {'success': True, 'token': token}

                else:
                    return {
                        'success': False,
                        "errors": {
                            "password": ["Senha incorreta."]
                        }
                    }

            else:

                return {
                    'success': False,
                    "errors": {
                        "username": ["Username não cadastrado."]
                    }
                }

        else:

            return {'success': False, "errors": form.errors}
def app_login():
    if current_user.is_authenticated:
        return redirect(url_for("home"))

    _form = LoginForm()
    if _form.validate_on_submit():
        user = db.session.query(User).filter(
            User.username == _form.username.data).first()

        if user and bcrypt.check_password_hash(user.password,
                                               _form.password.data):
            login_user(user, remember=False)
            flash("Logged in successfully!", "success")
            return redirect(url_for("home"))

        flash("Username or password incorrect! Please try again...", "danger")

    return render_template('pages/login.html', form=_form)
Beispiel #9
0
    def post(self):

        form = LoginForm()

        if form.validate_on_submit():

            obj = get_by_email("*****@*****.**")
            if obj:

                if bcrypt.check_password_hash(obj.password,
                                              form.password.data):

                    token = jwt.encode(
                        {
                            'user':
                            obj.email,
                            'exp':
                            datetime.datetime.utcnow() +
                            datetime.timedelta(minutes=30)
                        },
                        app.config['MANAGER_TOKEN_SECRET_KEY']).decode('UTF-8')

                    return {'success': True, 'token': token}

                else:
                    return {
                        'success': False,
                        "errors": {
                            "password": ["Senha incorreta."]
                        }
                    }

            else:

                return {
                    'success': False,
                    "errors": {
                        "email": ["Email não cadastrado."]
                    }
                }

        else:

            return {'success': False, "errors": form.errors}
Beispiel #10
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("users.account_home"))

    form = LoginForm()

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

        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)

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

            return redirect(next_page) if next_page else redirect(
                url_for("users.account_home"))
        else:
            flash('Login Error. Please check Username and Password', "danger")

    return render_template("login.html", form=form)
Beispiel #11
0
 def check_password(self, password):
     return bcrypt.check_password_hash(self.password_hash, password)
Beispiel #12
0
 def checkAuthenticator(self, plaintext_authenticator):
     if self.authenticator is None or self.authenticator == "":
         return False
     else:
         return bcrypt.check_password_hash(self.authenticator,
                                           plaintext_authenticator)
Beispiel #13
0
 def checkAuthentification(self, plaintext_authentification):
     return bcrypt.check_password_hash(self.authentification, plaintext_authentification)
Beispiel #14
0
 def checkAuthenticator(self, plaintext_authenticator):
     return bcrypt.check_password_hash(self.authenticator,
                                       plaintext_authenticator)
Beispiel #15
0
def login_user(model, payload):
    user = model.query.filter_by(Email=payload["email"]).first()
    if user and bcrypt.check_password_hash(user.password, payload["password"]):
        return user
    return None
Beispiel #16
0
 def checkPassword(self, plaintext_password):
     return bcrypt.check_password_hash(self.password, plaintext_password)
Beispiel #17
0
 def checkPin(self, plaintext_pin):
     if self.pin is None or self.pin == "":
         return False
     else:
         return bcrypt.check_password_hash(self.pin, plaintext_pin)
Beispiel #18
0
 def validate_password(self, password):
     if password.data:
         if not bcrypt.check_password_hash(current_user.password,
                                           password.data):
             raise ValidationError(
                 'That password is incorrect. Please try again.')