Skip to content
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

Add all info from signup post to get_or_create_user #48

Merged
merged 2 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions nativeauthenticator/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ def get_result_message(self, user):
return alert, message

async def post(self):
username = self.get_body_argument('username', strip=False)
password = self.get_body_argument('password', strip=False)
user = self.authenticator.get_or_create_user(username, password)
user_info = {
'username': self.get_body_argument('username', strip=False),
'pw': self.get_body_argument('pw', strip=False),
'email': self.get_body_argument('email', '', strip=False),
}
user = self.authenticator.get_or_create_user(**user_info)

alert, message = self.get_result_message(user)

Expand Down
8 changes: 5 additions & 3 deletions nativeauthenticator/nativeauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ def get_or_create_user(self, username, pw, **kwargs):
if username in self.admin_users or self.open_signup:
infos.update({'is_authorized': True})

user_info = UserInfo(**infos)
user = User(name=username)
try:
user_info = UserInfo(**infos)
user = User(name=username)
except AssertionError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What raises an AssertionError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the email is not validated by the ORM function, it will return an AssertionError. We can see this behavior being tested here:

def test_validate_method_wrong_email(email, tmpdir, app):

return

self.db.add_all([user_info, user])
self.db.commit()

return user_info

def change_password(self, username, new_password):
Expand Down
2 changes: 1 addition & 1 deletion nativeauthenticator/templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2>
<input
type="password"
class="form-control"
name="password"
name="pw"
id="pwd"
tabindex="2"
required
Expand Down