@@ -442,9 +442,16 @@ def _validate_magic_link_request(email: str, referrer: str) -> tuple[Response |
442442 return None , 200
443443
444444
445- def _generate_and_store_token (email : str ) -> str :
445+ def _generate_and_store_token (email : str , is_test : bool = False ) -> str :
446+ payload = {
447+ "exp" : datetime .datetime .now (datetime .timezone .utc ) + LINK_EXPIRATION ,
448+ "email" : email ,
449+ }
450+ if is_test :
451+ payload ["is_test" ] = True
452+
446453 token = jwt .encode (
447- { "exp" : datetime . datetime . now ( datetime . timezone . utc ) + LINK_EXPIRATION , "email" : email } ,
454+ payload ,
448455 CONFIG .SECRET_KEY ,
449456 algorithm = "HS256" ,
450457 )
@@ -560,15 +567,19 @@ def email_logged_in():
560567 # If the email domain list is explicitly configured to None, this allows any
561568 # email address to make an active account, otherwise the email domain must match
562569 # the list of allowed domains and the admin must verify the user
563- allowed = _check_email_domain (email , CONFIG .EMAIL_DOMAIN_ALLOW_LIST )
564- if not allowed :
565- raise UserRegistrationForbidden
570+ is_test = data .get ("is_test" , False )
571+
572+ if not is_test :
573+ allowed = _check_email_domain (email , CONFIG .EMAIL_DOMAIN_ALLOW_LIST )
574+ if not allowed :
575+ raise UserRegistrationForbidden
566576
567577 create_account = AccountStatus .UNVERIFIED
568578 if (
569579 CONFIG .EMAIL_DOMAIN_ALLOW_LIST is None
570580 or CONFIG .EMAIL_AUTO_ACTIVATE_ACCOUNTS
571581 or CONFIG .AUTO_ACTIVATE_ACCOUNTS
582+ or is_test
572583 ):
573584 create_account = AccountStatus .ACTIVE
574585
@@ -731,6 +742,6 @@ def create_test_magic_link():
731742 if error_response :
732743 return error_response , status_code
733744
734- token = _generate_and_store_token (email )
745+ token = _generate_and_store_token (email , is_test = True )
735746
736747 return jsonify ({"status" : "success" , "token" : token }), 200
0 commit comments