コード例 #1
0
 def setpwd(self):
     """
     修改密码
     """
     data = request.get_json()
     if current_user.verify_and_update_password(data["oldpasswd"]):
         current_user.password = encrypt_password(data["passwd"])
         current_user.save()
         return {"code": 0, "msg": "success"}
     else:
         return {"code": 1, "msg": "wrong old password"}
コード例 #2
0
    def validate(self):
        if not super(ChangePasswordForm, self).validate():
            return False

        if not current_user.verify_and_update_password(self.password.data):
            self.password.errors.append(get_message('INVALID_PASSWORD')[0])
            return False
        if self.password.data == self.new_password.data:
            self.password.errors.append(get_message('PASSWORD_IS_THE_SAME')[0])
            return False
        return True
コード例 #3
0
ファイル: views.py プロジェクト: sniweef/adam_heaven
def change_password():
    form = ChangePasswordForm()

    if form.validate_on_submit():
        if current_user.verify_and_update_password(form.old_password.data,
                                                   form.password.data):
            flash(u'修改密码成功!', 'success')
            return redirect(url_for('blog.account'))
        else:
            flash(u'修改密码失败!密码不正确!', 'danger')
            return redirect(url_for('blog.account'))
    else:
        flash(u'输入的两个新密码不一致!', 'danger')
        return redirect(url_for('blog.account'))
コード例 #4
0
    def validate(self):
        if not super(ChangePasswordForm, self).validate():
            return False

        if not current_user.verify_and_update_password(self.password.data):
            self.password.errors.append(get_message("INVALID_PASSWORD")[0])
            return False
        if self.password.data == self.new_password.data:
            self.password.errors.append(get_message("PASSWORD_IS_THE_SAME")[0])
            return False
        pbad = _security._password_validator(self.new_password.data,
                                             False,
                                             user=current_user)
        if pbad:
            self.new_password.errors.extend(pbad)
            return False
        return True
コード例 #5
0
ファイル: forms.py プロジェクト: mephi42/flask-security
    def validate(self, **kwargs: t.Any) -> bool:
        if not super().validate(**kwargs):
            return False

        self.password.data = _security._password_util.normalize(
            self.password.data)
        if not current_user.verify_and_update_password(self.password.data):
            self.password.errors.append(get_message("INVALID_PASSWORD")[0])
            return False
        if self.password.data == self.new_password.data:
            self.password.errors.append(get_message("PASSWORD_IS_THE_SAME")[0])
            return False
        pbad, self.new_password.data = _security._password_util.validate(
            self.new_password.data, False, user=current_user)
        if pbad:
            self.new_password.errors.extend(pbad)
            return False
        return True