Commit b8620f9a authored by John Wang's avatar John Wang

fix: CurrentPasswordIncorrectError not return with error msg

parent dad32ba7
...@@ -9,14 +9,13 @@ from flask_restful import Resource, reqparse, fields, marshal_with ...@@ -9,14 +9,13 @@ from flask_restful import Resource, reqparse, fields, marshal_with
from controllers.console import api from controllers.console import api
from controllers.console.setup import setup_required from controllers.console.setup import setup_required
from controllers.console.workspace.error import AccountAlreadyInitedError, InvalidInvitationCodeError, \ from controllers.console.workspace.error import AccountAlreadyInitedError, InvalidInvitationCodeError, \
RepeatPasswordNotMatchError RepeatPasswordNotMatchError, CurrentPasswordIncorrectError
from controllers.console.wraps import account_initialization_required from controllers.console.wraps import account_initialization_required
from libs.helper import TimestampField, supported_language, timezone from libs.helper import TimestampField, supported_language, timezone
from extensions.ext_database import db from extensions.ext_database import db
from models.account import InvitationCode, AccountIntegrate from models.account import InvitationCode, AccountIntegrate
from services.account_service import AccountService from services.account_service import AccountService
account_fields = { account_fields = {
'id': fields.String, 'id': fields.String,
'name': fields.String, 'name': fields.String,
...@@ -195,8 +194,11 @@ class AccountPasswordApi(Resource): ...@@ -195,8 +194,11 @@ class AccountPasswordApi(Resource):
if args['new_password'] != args['repeat_new_password']: if args['new_password'] != args['repeat_new_password']:
raise RepeatPasswordNotMatchError() raise RepeatPasswordNotMatchError()
AccountService.update_account_password( try:
current_user, args['password'], args['new_password']) AccountService.update_account_password(
current_user, args['password'], args['new_password'])
except api.services.errors.account.CurrentPasswordIncorrectError:
raise CurrentPasswordIncorrectError()
return {"result": "success"} return {"result": "success"}
......
...@@ -7,6 +7,12 @@ class RepeatPasswordNotMatchError(BaseHTTPException): ...@@ -7,6 +7,12 @@ class RepeatPasswordNotMatchError(BaseHTTPException):
code = 400 code = 400
class CurrentPasswordIncorrectError(BaseHTTPException):
error_code = 'current_password_incorrect'
description = "Current password is incorrect."
code = 400
class ProviderRequestFailedError(BaseHTTPException): class ProviderRequestFailedError(BaseHTTPException):
error_code = 'provider_request_failed' error_code = 'provider_request_failed'
description = None description = None
......
...@@ -52,7 +52,6 @@ class AccountService: ...@@ -52,7 +52,6 @@ class AccountService:
@staticmethod @staticmethod
def update_account_password(account, password, new_password): def update_account_password(account, password, new_password):
"""update account password""" """update account password"""
# todo: split validation and update
if account.password and not compare_password(password, account.password, account.password_salt): if account.password and not compare_password(password, account.password, account.password_salt):
raise CurrentPasswordIncorrectError("Current password is incorrect.") raise CurrentPasswordIncorrectError("Current password is incorrect.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment