Skip to content
This repository was archived by the owner on Oct 24, 2018. It is now read-only.

Conversation

@inkhey
Copy link
Contributor

@inkhey inkhey commented Apr 25, 2018

Depends on #56.
-> Remove swagger_ui view
-> Allow in_context params in many user_lib method (is it the best way to deal with this problem) to return UserInContext object.
-> Add autehnticate_user method in user_lib
-> Add tests+renaming for user_lib.

Copy link
Collaborator

@lebouquetin lebouquetin left a comment

Choose a reason for hiding this comment

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

@inkhey some changes + the subject about route definition as a decorator (maybe we should talk about this with @buxx )


# Check methods

def user_with_email_exists(self, email: str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing return typing

if user.validate_password(password):
return user
else:
raise BadUserPassword()
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do you return an instance of exception here and a class 3 lines further?

)
new_user = api.get_user_with_context(user)
assert isinstance(new_user, UserInContext)
assert new_user.user == user
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should also check that the context is valid (eg: user avatar url, ...)

Copy link
Contributor Author

@inkhey inkhey May 9, 2018

Choose a reason for hiding this comment

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

Done with commit d9cdd65

assert isinstance(user, User)
assert user.email == 'admin@admin.admin'

def test_unit__authenticate_user___err__bad_password(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

replace bad password by wrong password

config=self.config,
)
with pytest.raises(AuthenticationFailed):
api.authenticate_user('unknown_user', 'bad_password')
Copy link
Collaborator

Choose a reason for hiding this comment

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

bad password means "un mot de passe de mauvaise qualité". wrong password means "un mot de passe erroné". you should use WrongPassword (even rename the exception BadPassword to WrongPassword)

password = request.params['password']
if not (email and password):
raise Exception
email = request.json_body['email']
Copy link
Collaborator

Choose a reason for hiding this comment

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

ask @buxx how to automatically fill an object from Schema in order not to have to fill yourself stuff from request.json_body.

session=request.dbsession,
config=app_config,
)
return uapi.authenticate_user(email, password)
Copy link
Collaborator

Choose a reason for hiding this comment

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

after the object is filled using Schema, the code here will be something like:

return uapi.authenticate_user(login.email, login.password)

self.login,
route_name='login',
)
configurator.add_route('login', '/sessions/login', request_method='POST') # nopep8
Copy link
Collaborator

Choose a reason for hiding this comment

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

would be nice to defin routes directly as view method decorators. is it possible ?

Copy link
Contributor Author

@inkhey inkhey May 9, 2018

Choose a reason for hiding this comment

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

we previously decide to not rely on pyramid default decorator :

It's not in pyramid philosophy to have decorator who create both view and route at the same time like in some others web framework, pyramid explicitly distinct view and route. That's why such type of decorator is not a good idea.

Working with default pyramid decorator who are only view decorator doesn't simplify a lot code as we already need to set route in another place .

Class method view decorator doesn't work well with Hapic , see algoo/hapic#42

@inkhey inkhey changed the title WIP: Fix/better user lib for authentication Fix/better user lib for authentication May 9, 2018
@lebouquetin lebouquetin merged commit 734ed10 into develop May 16, 2018
@inkhey inkhey deleted the fix/better_user_lib_for_authentication branch June 18, 2018 09:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants