-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/fix/dataset_operator' into deploy/dev
* refs/heads/fix/dataset_operator: (33 commits) feat: update dataset sort feat: add dataset_permissions tenant_id chore: optimize memory fetch performance (#6039) feat: support moonshot and glm base models for volcengine provider (#6029) Optimize db config (#6011) fix: token count includes base64 string of input images (#5868) chore: skip pip upgrade preparation in api dockerfile (#5999) feat(*): Swtich to dify_config. (#6025) fix: the input field of tool panel not worked as expected (#6003) Add 2 firecrawl tools : Scrape and Search (#6016) test(test_rerank): Remove duplicate test cases. (#6024) chore: optimize memory messages fetch count limit (#6021) Revert "feat: knowledge admin role" (#6018) feat: add Llama 3 and Mixtral model options to ddgo_ai.yaml (#5979) fix: add status_code 304 (#6000) 6014 i18n add support for spanish (#6017) [Feature] Support loading for mermaid. (#6004) fix: update workflow trace query (#6010) Removed firecrawl-py, fixed and improved firecrawl tool (#5896) fix API tool's schema not support array (#6006) ...
- Loading branch information
Showing
117 changed files
with
5,588 additions
and
1,153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,3 +174,5 @@ sdks/python-client/dify_client.egg-info | |
.vscode/* | ||
!.vscode/launch.json | ||
pyrightconfig.json | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import base64 | ||
import logging | ||
import secrets | ||
|
||
from flask_restful import Resource, reqparse | ||
|
||
from controllers.console import api | ||
from controllers.console.auth.error import ( | ||
InvalidEmailError, | ||
InvalidTokenError, | ||
PasswordMismatchError, | ||
PasswordResetRateLimitExceededError, | ||
) | ||
from controllers.console.setup import setup_required | ||
from extensions.ext_database import db | ||
from libs.helper import email as email_validate | ||
from libs.password import hash_password, valid_password | ||
from models.account import Account | ||
from services.account_service import AccountService | ||
from services.errors.account import RateLimitExceededError | ||
|
||
|
||
class ForgotPasswordSendEmailApi(Resource): | ||
|
||
@setup_required | ||
def post(self): | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('email', type=str, required=True, location='json') | ||
args = parser.parse_args() | ||
|
||
email = args['email'] | ||
|
||
if not email_validate(email): | ||
raise InvalidEmailError() | ||
|
||
account = Account.query.filter_by(email=email).first() | ||
|
||
if account: | ||
try: | ||
AccountService.send_reset_password_email(account=account) | ||
except RateLimitExceededError: | ||
logging.warning(f"Rate limit exceeded for email: {account.email}") | ||
raise PasswordResetRateLimitExceededError() | ||
else: | ||
# Return success to avoid revealing email registration status | ||
logging.warning(f"Attempt to reset password for unregistered email: {email}") | ||
|
||
return {"result": "success"} | ||
|
||
|
||
class ForgotPasswordCheckApi(Resource): | ||
|
||
@setup_required | ||
def post(self): | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('token', type=str, required=True, nullable=False, location='json') | ||
args = parser.parse_args() | ||
token = args['token'] | ||
|
||
reset_data = AccountService.get_reset_password_data(token) | ||
|
||
if reset_data is None: | ||
return {'is_valid': False, 'email': None} | ||
return {'is_valid': True, 'email': reset_data.get('email')} | ||
|
||
|
||
class ForgotPasswordResetApi(Resource): | ||
|
||
@setup_required | ||
def post(self): | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('token', type=str, required=True, nullable=False, location='json') | ||
parser.add_argument('new_password', type=valid_password, required=True, nullable=False, location='json') | ||
parser.add_argument('password_confirm', type=valid_password, required=True, nullable=False, location='json') | ||
args = parser.parse_args() | ||
|
||
new_password = args['new_password'] | ||
password_confirm = args['password_confirm'] | ||
|
||
if str(new_password).strip() != str(password_confirm).strip(): | ||
raise PasswordMismatchError() | ||
|
||
token = args['token'] | ||
reset_data = AccountService.get_reset_password_data(token) | ||
|
||
if reset_data is None: | ||
raise InvalidTokenError() | ||
|
||
AccountService.revoke_reset_password_token(token) | ||
|
||
salt = secrets.token_bytes(16) | ||
base64_salt = base64.b64encode(salt).decode() | ||
|
||
password_hashed = hash_password(new_password, salt) | ||
base64_password_hashed = base64.b64encode(password_hashed).decode() | ||
|
||
account = Account.query.filter_by(email=reset_data.get('email')).first() | ||
account.password = base64_password_hashed | ||
account.password_salt = base64_salt | ||
db.session.commit() | ||
|
||
return {'result': 'success'} | ||
|
||
|
||
api.add_resource(ForgotPasswordSendEmailApi, '/forgot-password') | ||
api.add_resource(ForgotPasswordCheckApi, '/forgot-password/validity') | ||
api.add_resource(ForgotPasswordResetApi, '/forgot-password/resets') |
Oops, something went wrong.