Commit Graph

108 Commits

Author SHA1 Message Date
Leo Hemsted
dd326ec1d3 add new template to config
and rename existing new user email verification template for clarity
2017-11-07 16:47:26 +00:00
Leo Hemsted
b2756ac99d add email code verification
by hitting POST /<user_id>/email-code, we create an email two factor
code to send to the user. That email contains a link with a token that
will sign the user in when opened.

Also some other things:

"email verification" (aka when you first create an account) doesn't
hit the API anymore

refactor 2fa code verification and sending to use jsonschema, and share code between sms and email

Die marshmallow die!
2017-11-07 16:45:49 +00:00
Leo Hemsted
6c61a3fc2a Revert celery4
Revert the following three pull requests:
https://github.com/alphagov/notifications-api/pull/1085
https://github.com/alphagov/notifications-api/pull/1086
https://github.com/alphagov/notifications-api/pull/1088

celery 4.0.2 looked promising, however, on staging under mild load
(5/sec api calls) the performance was actually worse than 3.1.25
2017-07-19 15:17:19 +01:00
Martyn Inglis
786adb5d71 Move Queuenames in with the celery code, revamp config to allow move to celery 4.x 2017-07-12 12:01:52 +01:00
Chris Hill-Scott
f1399ca7f1 Fix support URLs in Notify emails 2017-06-07 11:58:10 +01:00
Martyn Inglis
2591d3a1df This massive set of changes uses the new queue names object throughout the app and tests.
Lots of changes, all changing the line of code that puts things into queues, and the code that tests that.
2017-05-25 10:51:49 +01:00
Rebecca Law
78242812ef Register a before_request event for all blueprints, that defines the authentication requirement.
There are three authentication methods:
 - requires_no_auth - public endpoint that does not require an Authorisation header
 - requires_auth - public endpoints that need an API key in the Authorisation header
 - requires_admin_auth - private endpoint that requires an Authorisation header which contains the API key for the defined as the client admin user
2017-03-16 18:15:49 +00:00
Rebecca Law
fd0bfbe2f6 If user account is locked return 404 even if the code is correct.
Update user.failed_login_count = 0 if code is correct.
New endpoint to reset the failed_login_count
2017-02-28 14:28:33 +00:00
Rebecca Law
fb61b4528b Remove resetting the failed_login_count to zero in the api. The admin app will deal with doing that. 2017-02-28 11:21:47 +00:00
Leo Hemsted
8bad5926ab dont set session_id or logged_in_at if user provides email code 2017-02-24 15:14:47 +00:00
Leo Hemsted
a47672f7e3 Add current_session_id to the user model, update on login
when we change the last logged in time, set the current session id to
a random uuid

this way, we can compare it to the cookie a user has, and if they
differ then we can log them out

also update user.logged_in_at at 2FA rather than password check, since
that feels more accurate
2017-02-22 17:30:55 +00:00
Leo Hemsted
521872ce63 update_user now resets failed_login_count if password is changed
until work is done to stop using PUT /user/{id} on the admin app, this
function also needs to reset failed logins, cos it's used during the
forgotten password flow
2017-02-16 17:39:47 +00:00
Leo Hemsted
ac9739f8a2 ensure we reset failed_login_count when appropriate
in verify_user_password, if succesful we reset the failed_login_count.
now we use failed_login_count for 2FA attempts, we need to make sure we
reset it in other places too, so that people don't get blocked,
especially in the reset-password user journey.

* verify_user_code - if it's succesful, reset the failed_login_count
* update_password - reset failed_login_count because either
  * you're logged in and so it's 0 anyway
  * you're resetting your password via pword reset link, and the old
    count isn't relevant anymore
2017-02-16 16:00:40 +00:00
Rebecca Law
ed4b9d34a6 Changes as per code review comments.
Fix my backward date math :P
2017-02-15 17:41:07 +00:00
Rebecca Law
52342afe3f Add a limit to the number of active 2fa codes that we create. At the moment that is set to 10. 2017-02-15 16:18:05 +00:00
Rebecca Law
6674640330 Removed resetting of the login count 2017-02-15 10:54:09 +00:00
Rebecca Law
5f48367ee5 Set the expiry time on a verify code (2fa) to 10 minutes.
When the verify code is wrong or expired increment the failed to login count for the user.
When the verify code is successfully used reset the failed login count to 0.
2017-02-14 14:04:11 +00:00
Imdad Ahad
69b1007c33 Add schema and separate endpoint to update a user password 2017-02-07 11:27:13 +00:00
Martyn Inglis
46d1e3bdb6 Two new methods needed to pass the service not the service ID into the create notifications methods. 2017-01-10 13:41:16 +00:00
minglis
0c6193e2e9 Merge pull request #775 from alphagov/do-not-write-test-data-to-the-history-table
Do not write test data to the history table
2017-01-10 13:05:06 +00:00
Rebecca Law
7bec9aefcc Removed unused imports. 2016-12-20 16:06:23 +00:00
Rebecca Law
a03732472c Refactor send_user_reset_password to persist and send message to the notify queue.
The reason for doing this is to ensure the tasks performed for the Notify users are not queued behind a large job, a way to
ensure priority for messages.

5th task for story: https://www.pivotaltracker.com/story/show/135839709
2016-12-20 11:55:26 +00:00
Rebecca Law
813947e7e4 Refactor send_already_registered_email to persist and send message to the notify queue.
The reason for doing this is to ensure the tasks performed for the Notify users are not queued behind a large job, a way to
ensure priority for messages.

4th task for story: https://www.pivotaltracker.com/story/show/135839709
2016-12-19 17:35:13 +00:00
Martyn Inglis
825db5e39d Ensure that all persist notification methods use service not service ID 2016-12-19 16:51:57 +00:00
Martyn Inglis
1e054ec698 Merge branch 'master' into do-not-write-test-data-to-the-history-table
Conflicts:
	app/user/rest.py
2016-12-19 16:47:54 +00:00
Martyn Inglis
0f37824b0c Ensure updates on a research mode service or test key don't touch the history table
- note this is an unexpectedly big change.
- When we create a service we pass the service id to the persist method. This means that we don't have the service available to check if in research mode.
- All calling methods (expecting the one where we use the notify service) have the service available. So rather than reload it I changed the method signature to pass the service, not the ID to persist.
- Touches a few places.

Note this means that the update or create methods will fall over on a null service. But this seems correct.

Goes back to the story which we need to play to make the service available as the API user so that the need to load and pass around services is minimised.
2016-12-19 16:45:18 +00:00
Rebecca Law
ab1326b97e Merge pull request #774 from alphagov/refactor-send_user_email_verification
Refactor the endpoint to send user email verification when registering
2016-12-19 16:29:02 +00:00
Rebecca Law
741cbd1741 Refactor send_user_email_verification to persist the notification then put on the "notify" queue for delivery.
The reason for doing this is to ensure the tasks performed for the Notify users are not queued behind a large job, a way to
ensure priority for messages.
2016-12-19 15:31:54 +00:00
Rebecca Law
75ca86ad0d Update the send_user_confirm_new_email to persist the notification then put on the "notify" queue for delivery.
The reason for doing this is to ensure the tasks performed for the Notify users are not queued behind a large job, a way to
ensure priority for messages.
2016-12-19 15:19:05 +00:00
Jenny Duckett
e569c54f45 Send Notify's 2FA codes via only the notify queue
This means that these codes won't be delayed by large jobs going through the
send-sms/email queues. send_user_sms_code now works much more like the
endpoints for sending notifications, by persisting the notification and only
using the deliver_sms task (instead of using send_sms as well).

The workers consuming the `notify` queue should be able to handle the deliver
task as well, so no change should be needed to the celery workers to support
this.

I think there's also a change in behaviour here: previously, if the Notify
service was in research mode, 2FA codes would not have been sent out, making
it impossible to log into the admin. Now, a call to this endpoint will always
send out the notification even if we've put the Notify service into research
mode, since we set the notification's key type to normal and ignore the
service's research mode setting when sending the notification to the queue.
2016-12-09 16:46:49 +00:00
Imdad Ahad
8b64aa7e79 Use POST endpoint for updating a user attr 2016-11-10 12:07:29 +00:00
Imdad Ahad
461d8a9b2c Add separate endpoint to update a single user attr 2016-11-07 17:42:23 +00:00
Rebecca Law
9ffdf66c49 Rename the endpoints.
Increase test coverage to include the encrypted message sent to the task.
2016-10-13 11:59:47 +01:00
Rebecca Law
b37eef974c Change email confirmation
- New endpoint to send a user an email to verify the email address when they want to change it.
2016-10-12 13:06:39 +01:00
Martyn Inglis
ce5b5fbf4c Rationalised the queues.
- the internal notify activites (send sms code, forgotten passwords etc) all not in a "notify" queue.
- deleted all unused queues
2016-09-26 12:35:59 +01:00
Rebecca Law
f4976539e4 Make email a required field for the email_data_schema. 2016-07-08 10:57:20 +01:00
Rebecca Law
36ecdca04c Add new email template for the GOV.UK Notify service, to send an email to users that register with the same email address.
Add a new endpoint to send the email.
2016-07-07 17:23:07 +01:00
Rebecca Law
3f11447bc8 A small refactor to use the SMS_TYPE and EMAIL_TYPE in code rather that 'sms' or 'email' 2016-06-30 15:41:51 +01:00
Rebecca Law
4e640eea6d Remove print 2016-06-17 11:01:26 +01:00
Rebecca Law
b6c6b25032 Use the send email task to send the password reset and invitation email.
Next PR can remove those tasks.
2016-06-16 17:34:33 +01:00
Rebecca Law
d6e920fa89 Use GOV.UK Notify service to send the forgot password email link using the template to create the message. 2016-06-16 10:43:41 +01:00
Adam Shimali
b33312b855 Change endpoint responses where there are marshalling, unmarshalling
or param errors to raise invalid data exception. That will cause
those responses to be handled in by errors.py, which will log
the errors.

Set most of schemas to strict mode so that marshmallow will raise
exception rather than checking for errors in return tuple from load.

Added handler to errors.py for marshmallow validation errors.
2016-06-15 14:37:51 +01:00
Rebecca Law
a6ce109c62 Rename first send_email to send_email_v1.
Fix the tests
2016-06-13 16:16:56 +01:00
Rebecca Law
cd2627e5ed Create a new task called send_email_v2 so that I can get rid of the from_address in the signature.
This is done to make sure we do not lose any messages in the queue during deployment.
2016-06-13 15:31:45 +01:00
Rebecca Law
5fc14940f3 Let the send_email task set the from address 2016-06-13 14:58:00 +01:00
Rebecca Law
ea80596e73 Correct template id for email verification template in the history table.
Correct personalisation name when sending registration message.
2016-06-13 14:57:59 +01:00
Rebecca Law
877fd6fdc4 Make template id a string in the json messge 2016-06-13 14:57:59 +01:00
Rebecca Law
cfd31541f4 Use notify to send email verification 2016-06-13 14:57:41 +01:00
Adam Shimali
e28ef237e4 When adding a user new with permissions to a service, the permissions
dao was deleting all permissions for that user (regardless of service
id) as the last filter on the permissions dao get_query method won.

I've added a replace flag to the set_user_service_permission method
so that it can handle adding new users + permissions and editing
of existing users' permissions.

Also by pass the get_query method until it can be refactored to work
correctly.

For now execute the filter query directly on the model.
2016-06-07 16:35:26 +01:00
Rebecca Law
dbc57e3b58 [WIP]
use send_sms task to send sms code.
Tests are broken because the template data for the Notify service is being delete after every test. Need a way to seed the data for the test.
2016-06-03 15:15:46 +01:00