-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hashing based Verification Token Handling #43
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,18 +100,35 @@ def prompt_and_set_token(cls, user_auth_handler: "UserAuthenticationClient"): | |
) | ||
) | ||
additional_info = cls.prompt_add_user_information() | ||
is_created, message = user_auth_handler.set_token_by_registration( | ||
email, password, password_confirm, validation_link, additional_info | ||
is_created, message, access_token = ( | ||
user_auth_handler.set_token_by_registration( | ||
email, password, password_confirm, validation_link, additional_info | ||
) | ||
) | ||
if not is_created: | ||
raise RuntimeError("User registration failed: " + str(message) + "\n") | ||
|
||
print( | ||
cls.indent( | ||
"Account created successfully! To start using TabPFN please click on the link in the verification email we sent you." | ||
"Account created successfully! To start using TabPFN please enter the secret key in the verification email we sent you." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To start using TabPFN please enter the verification code we sent to you by mail |
||
) | ||
+ "\n" | ||
) | ||
# verify token from email | ||
verified = False | ||
while not verified: | ||
token = input(cls.indent("Verification Token: ")) | ||
verified, message = user_auth_handler.verify_email(token) | ||
if not verified: | ||
print("\n" + cls.indent(str(message) + "Please try again!") + "\n") | ||
|
||
print( | ||
cls.indent( | ||
"Thank you for verifying your email successfully! Your access token is: " | ||
) | ||
+ access_token | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't show the access token here. Only write: cls.indent( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To access the token there should be a function get_token and set_token |
||
+ r" and we have stored it for you in the file in directory: '.\tabpfn\config.'\n\n" | ||
) | ||
|
||
# Login | ||
elif choice == "2": | ||
|
@@ -120,12 +137,29 @@ def prompt_and_set_token(cls, user_auth_handler: "UserAuthenticationClient"): | |
email = input(cls.indent("Please enter your email: ")) | ||
password = getpass.getpass(cls.indent("Please enter your password: ")) | ||
|
||
successful, message = user_auth_handler.set_token_by_login( | ||
successful, message, status_code = user_auth_handler.set_token_by_login( | ||
email, password | ||
) | ||
if successful: | ||
break | ||
print(cls.indent("Login failed: " + message) + "\n") | ||
print(cls.indent("Login failed: " + str(message)) + "\n") | ||
if status_code == 403: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure does 403 mean not verified? |
||
# Verify email | ||
verified = False | ||
while not verified: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow verification is duplicated? Why here and above? |
||
token = input(cls.indent("Verification Token: ")) | ||
verified, message = user_auth_handler.verify_email(token) | ||
if not verified: | ||
print( | ||
"\n" | ||
+ cls.indent(str(message) + "Please try again!") | ||
+ "\n" | ||
) | ||
else: | ||
print(cls.indent("Email verified successfully!") + "\n") | ||
user_auth_handler.set_token_by_login(email, password) | ||
break | ||
break | ||
|
||
prompt = "\n".join( | ||
[ | ||
|
@@ -239,6 +273,21 @@ def reverify_email( | |
) | ||
+ "\n" | ||
) | ||
# verify token from email | ||
verified = False | ||
while not verified: | ||
token = input( | ||
cls.indent( | ||
"Please enter the correct secret key sent to your email to verify: " | ||
) | ||
) | ||
# get user email from user_auth_handler | ||
verified, message = user_auth_handler.verify_email(token) | ||
if not verified: | ||
print("\n" + cls.indent(str(message) + "Please try again!") + "\n") | ||
else: | ||
print(cls.indent("Email verified successfully!") + "\n") | ||
break | ||
return | ||
|
||
@classmethod | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ def test_password_req_to_policy(self): | |
@patch("getpass.getpass", side_effect=["Password123!", "Password123!"]) | ||
@patch( | ||
"builtins.input", | ||
side_effect=["1", "[email protected]", "test", "test", "test", "y"], | ||
side_effect=["1", "[email protected]", "test", "test", "test", "y", "test"], | ||
) | ||
def test_prompt_and_set_token_registration( | ||
self, mock_input, mock_getpass, mock_server | ||
|
@@ -30,16 +30,22 @@ def test_prompt_and_set_token_registration( | |
mock_auth_client.set_token_by_registration.return_value = ( | ||
True, | ||
"Registration successful", | ||
"dummy_token", | ||
) | ||
mock_auth_client.validate_email.return_value = (True, "") | ||
mock_auth_client.verify_email.return_value = (True, "Verification successful") | ||
PromptAgent.prompt_and_set_token(user_auth_handler=mock_auth_client) | ||
mock_auth_client.set_token_by_registration.assert_called_once() | ||
|
||
@patch("getpass.getpass", side_effect=["password123"]) | ||
@patch("builtins.input", side_effect=["2", "[email protected]"]) | ||
def test_prompt_and_set_token_login(self, mock_input, mock_getpass): | ||
mock_auth_client = MagicMock() | ||
mock_auth_client.set_token_by_login.return_value = (True, "Login successful") | ||
mock_auth_client.set_token_by_login.return_value = ( | ||
True, | ||
"Login successful", | ||
200, | ||
) | ||
PromptAgent.prompt_and_set_token(user_auth_handler=mock_auth_client) | ||
mock_auth_client.set_token_by_login.assert_called_once() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you adapt line 38 and replace the array / tuple by two separate variables
A, B = user_auth_handler.try_reuse_existing_token() # with A, B replace by what that means