Commit Graph

89 Commits

Author SHA1 Message Date
Carlo Costino
9a83ba7475 Localize notification_utils to the admin
This changeset pulls in all of the notification_utils code directly into the admin and removes it as an external dependency. We are doing this to cut down on operational maintenance of the project and will begin removing parts of it no longer needed for the admin.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2024-05-16 10:37:37 -04:00
Kenneth Kehl
8c9721d8e2 notify-api-412 use black to enforce python coding style 2023-08-25 09:12:23 -07:00
Kenneth Kehl
c6eb007386 merge from main 2023-08-25 08:57:24 -07:00
Carlo Costino
9e609efa1c Remove webauthn hooks
This changeset removes webauthn from the Notify.gov admin app.  We are not using webauthn at all in our implementation and will be looking at an entirely different authentication system in the near future.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2023-08-14 16:59:38 -04:00
Andrew Shumway
e0d4fee515 Replaced 30 min email exp variable with 1 hour in config for consistency 2023-06-15 08:54:52 -06:00
Ben Thorner
7fafc18fb3 Remove unnecessary restriction for 2FA WebAuthn
It should be enough to check the user has it set as their auth type.
Even if a user is no longer eligible to register a security key, it
should still be OK for them to continue using the feature.
2021-06-30 14:54:20 +01:00
Leo Hemsted
71613dd942 remove old /two-factor endpoint and update test names
we redirect people to `/two-factor-sms` since #26ad20719
2021-06-29 16:19:24 +01:00
Leo Hemsted
92b6885224 ensure webauthn page aborts if user isn't allowed 2021-06-29 15:53:48 +01:00
Ben Thorner
c17d438de8 DRY-up email revalidation check
Previously this was duplicated between the "two_factor" and the
"webauthn" views, and required more test setup. This DRYs up the
check and tests it once, using mocks to simplify the view tests.

As part of DRYing up the check into a util module, I've also moved
the "is_less_than_days_ago" function it uses.
2021-06-14 12:52:54 +01:00
Ben Thorner
bf2e6802bf Extract login utils out of two_factor view
This better reflects how the code is reused in other views and is
not specific to two factor actions. We have a pattern of testing
utility functionality for each view (as opposed to testing the util
+ the view calls the util), so I'm leaving the tests as-is.
2021-06-14 11:19:06 +01:00
Ben Thorner
3250f2b3ed Move redirect_to_signin helper to new util module
We'll expand this module in later commits.
2021-06-14 11:09:42 +01:00
Leo Hemsted
26ad20719f send people to /two-factor-sms instead of /two-factor
both routes are already valid, however, the link from sign-in sends to
the old link. it fetches whichever URL is second in the route decorator
list when you call `url_for`. Swapping the order around keeps the routes
valid but starts pointing users to the new url.
2021-06-04 12:52:40 +01:00
Leo Hemsted
e864100be7 make sure error message flashes work properly
flashes are consumed by the jinja template calling get_flashed_messages
in flash_messages.html.

When you call `abort(403)` the 403 error page is rendered, with the
flashed message on it. However, the webauthn endpoints just return that
page to the ajax `fetch`, which ignores the response and just reloads
the page.

Instead of calling abort, we can just return an empty response body and
the 403 error code, so that the flashed messages stay in the session and
will be rendered when the `GET /two-factor-webauthn` request happens
after the js reloads the page.
2021-06-02 12:06:09 +01:00
Leo Hemsted
c203f624ca rename two_factor to two_factor_sms
it's a bit confusing now that there are three endpoints. the other two
are already renamed two_factor_email and two_factor_webauthn
2021-06-01 19:08:57 +01:00
Leo Hemsted
907a7dc363 create webauthn 2fa page
if user has `webauthn_auth` as their auth type, then redirect them to an
interstitial that prompts them to click on a button which right now just
logs to the JS console, but in a future commit will open up the webauthn
browser prompt

content is unsurprisingly not final.
2021-06-01 18:44:54 +01:00
David McDonald
3e80ba4734 Fix flake8 and isort errors
Note, isort now has default behaviour of searching recursively so we no
longer need the `-rc` flag
2021-03-08 18:48:56 +00:00
Pea M. Tyczynska
b60d25da67 Merge pull request #3670 from alphagov/show-broadcast-tour-when-password-reset
Take user to page they are meant to visit in various sign-in flow scenarios
2020-10-12 12:27:37 +01:00
Pea Tyczynska
2203fae195 Turn on redirects revalidate_email_sent
This is part of the work to make sure user is redirected
to the page they initially were meant to visit after
they sign in.
2020-10-09 12:39:23 +01:00
Pea Tyczynska
44ddee23ac Turn on redirects two_factor
This is part of the work to make sure user is redirected
to the page they initially were meant to visit after
they sign in.
2020-10-09 12:39:23 +01:00
Pea Tyczynska
a531c888ba Turn on redirects two_factor_email
This is part of the work to make sure user is redirected
to the page they initially were meant to visit after
they sign in.
2020-10-09 12:39:22 +01:00
Pea Tyczynska
5dd010ece8 Turn on redirects for two_factor_email_sent
This is part of the work to make sure user is redirected
to the page they initially were meant to visit after
they sign in.
2020-10-09 12:39:22 +01:00
Chris Hill-Scott
5c2469b24e Refactor to use shared date comparison function
This means we don’t have to repeatedly do timezone conversions or string
to datetime conversions in our business logic.
2020-09-29 13:38:00 +01:00
Chris Hill-Scott
3e6d9a564b Add interstitial page before using email auth token
Some email clients will pre-fetch links in emails to check whether
they’re safe. This has the unfortunate side effect of claiming the token
that’s in the link.

Long term, we don’t want to let the link be used multiple times, because
this reduces how secure it is (eg someone with access to your browser
history could re-use the link even if you’d signed out).

Instead, this commit adds an extra page which is served when the user
clicks the link from the email. This page includes a form which submits
to the actual URL that uses the token, thereby not claiming the token as
soon as the page is loaded.

For convenience, this page also includes some Javascript which clicks
the link on the user’s behalf. If the user has Javascript turned off
they will see the link and can click it themselves. This is going on the
assumption that whatever the email clients are doing when prefetching
the link doesn’t involve running any Javascript.

This Javascript is inlined so that:
- it is run as fast as possible
- it’s more resilient – even if our assets domain is unreachable or the
  connection is interrupted, it will still run
2020-05-04 15:53:27 +01:00
Chris Hill-Scott
ae2f8f9887 Add a second URL for the email auth endpoint
We’re going to add an interstitial page that redirects to this new URL.
But we don’t want that redirect to 404 while the change is deploying,
because some boxes will have the new URL and some won’t. So let’s deploy
the new URL to all the boxes first, then the redirect page can safely
take over the new one.

The new URL is going to be `post` not `get` because that feels more
HTTP-y, so we need to make sure that’s part of this change too.
2020-05-04 14:09:01 +01:00
Chris Hill-Scott
2a76fd9ee8 Reduce usage of the platform admin index page
This page is slow to load which means:
- it’s annoying for us
- it’s potentially causing load on the database

This commit does two things to reduce the amount we’re unnecessarily
looking at this page:

1. Avoid redirecting to it when signing in as a platform admin user
2. Don’t go directly to it when clicking ‘platform admin’ at the top,
   but instead show a holding page (there’s a fair chance you’ve clicked
   that link in order to go and manage some email branding or find a
   user, not wait for stats to load)
2020-03-19 10:59:21 +00:00
Pea Tyczynska
3a93fe6892 Fix reset password flow
It was broken because of mismatch in update password argument
2020-02-18 14:50:27 +00:00
Pea Tyczynska
7d460fe483 Move date-checking logic to utils and unit test it 2020-02-17 11:34:25 +00:00
Pea Tyczynska
caf77341b3 Send 2fa email and move user to waiting page when they need to re-validate email access 2020-02-17 11:34:24 +00:00
Chris Hill-Scott
628e344b36 Make user API client return JSON, not a model
The data flow of other bits of our application looks like this:
```
                         API (returns JSON)
                                  ⬇
          API client (returns a built in type, usually `dict`)
                                  ⬇
          Model (returns an instance, eg of type `Service`)
                                  ⬇
                         View (returns HTML)
```
The user API client was architected weirdly, in that it returned a model
directly, like this:

```
                         API (returns JSON)
                                  ⬇
    API client (returns a model, of type `User`, `InvitedUser`, etc)
                                  ⬇
                         View (returns HTML)
```

This mixing of different layers of the application is bad because it
makes it hard to write model code that doesn’t have circular
dependencies. As our application gets more complicated we will be
relying more on models to manage this complexity, so we should make it
easy, not hard to write them.

It also means that most of our mocking was of the User model, not just
the underlying JSON. So it would have been easy to introduce subtle bugs
to the user model, because it wasn’t being comprehensively tested. A lot
of the changed lines of code in this commit mean changing the tests to
mock only the JSON, which means that the model layer gets implicitly
tested.

For those reasons this commit changes the user API client to return
JSON, not an instance of `User` or other models.
2019-06-05 11:13:41 +01:00
Katie Smith
c30d94bf5c Stop automatically resending email verification links
This commit stops a new email verification link from being sent to a
user if they click on an email link which has expired or which has
already been used. Instead, they will be see an error message with a
link to the sign in page. This stops the situation where someone could
log in indefinitely (without the needing to enter their password) by
trying to use a used / expired email verification link and receiving a
valid link automatically.
2019-01-22 13:59:16 +00:00
Katie Smith
398aef6d4c Revert "Stop automatically resending email verification links" 2019-01-21 15:44:15 +00:00
Katie Smith
9095893e03 Stop automatically resending email verification links
This commit stops a new email verification link from being sent to a
user if they click on an email link which has expired or which has
already been used. Instead, they will be see an error message with a
link to the sign in page. This stops the situation where someone could
log in indefinitely (without the needing to enter their password) by
trying to use a used / expired email verification link and receiving a
valid link automatically.
2019-01-21 14:29:22 +00:00
Leo Hemsted
3551d36f32 bump reqs 2018-11-14 13:35:24 +00:00
Leo Hemsted
0dabd4ffc0 remove any old file upload data on sign in
if a user signs in again, clear their file upload data from any
aborted journeys from before, so that their cookies don't fill up

also add some temporary logging when the session starts getting full.
2018-04-03 14:58:50 +01:00
Leo Hemsted
e000552e56 redirect to show_accounts_or_dashboard on login
show_accounts_or_dashboard has logic about where you should redirect
to. If we let it do this, then that's nicer than duplicating its
logic. We found that it wasn't accounting for orgs in redirects
properly.
2018-03-19 16:41:16 +00:00
Leo Hemsted
2f37e37278 rename choose_service to choose_account 2018-03-14 15:39:55 +00:00
Chris Hill-Scott
f3a0c505bd Enforce order and style of imports
Done using isort[1], with the following command:
```
isort -rc ./app ./tests
```

Adds linting to the `run_tests.sh` script to stop badly-sorted imports
getting re-introduced.

Chosen style is ‘Vertical Hanging Indent’ with trailing commas, because
I think it gives the cleanest diffs, eg:
```
from third_party import (
    lib1,
    lib2,
    lib3,
    lib4,
)
```

1. https://pypi.python.org/pypi/isort
2018-02-27 16:35:13 +00:00
chrisw
04f6d0a5e0 Updated code used flow 2017-11-09 17:06:57 +00:00
chrisw
1effec78e5 alter login flow to allow for email auth login 2017-11-09 16:07:28 +00:00
Leo Hemsted
1cacd92411 Merge pull request #1153 from alphagov/forget-me
Remove remember me cookie
2017-03-06 09:39:52 +00:00
Leo Hemsted
85efe0d117 remove flask's builtin remember me functionality
we don't need it cos we do it all ourselves
2017-03-02 16:55:10 +00:00
Rebecca Law
35f61125e8 Fix the user flow when the user account is locked.
The user has 10 tries at the password, after which the account is locked.
The same is true for the verify code, the user will have 10 tries before the user account is locked.
2017-02-28 14:41:31 +00:00
Rebecca Law
2d4e0a0631 Added a reset of failed_login_count when the user is activated.
Update user from the update-password api call (which resets the failed_login_count)
2017-02-28 11:56:40 +00:00
Leo Hemsted
4df12f5f4e ensure other 2FA pages also handle session id
specifically, the 2FA page when you first create an account is different to the login 2FA page
and also the 2FA page when you change your phone number is different as well
2017-02-24 16:32:59 +00:00
Leo Hemsted
f14a836baa check users' session id.
when a user enters their 2FA code, the API will store a random UUID
against them in the database - this code is then stored on the cookie
on the front end.

At the beginning of each authenticated request, we do the following
steps:
  * Retrieve the user's cookie, and get the user_id from it
  * Request that user's details from the database
  * populate current_user with the DB model
  * run the login_required decorator, which calls
    current_user.is_authenticated

is_authenticated now also checks that the database model matches the
cookie for session_id. The potential states and meanings are as follows:

 database | cookie | meaning
----------+--------+---------
 None     | None   | New user, or system just been deployed.
          |        | Redirect to start page.
----------+--------+---------
 'abc'    | None   | New browser (or cleared cookies). Redirect to
          |        | start page.
----------+--------+---------
 None     | 'abc'  | Invalid state (cookie is set from user obj, so
          |        | would only happen if DB is cleared)
----------+--------+---------
 'abc'    | 'abc'  | Same browser. Business as usual
----------+--------+---------
 'abc'    | 'def'  | Different browser in cookie - db has been changed
          |        | since then. Redirect to start
2017-02-22 17:31:13 +00:00
Imdad Ahad
2c51792ae5 Update two-factor to use new update password endpoint and refactor tests 2017-02-20 14:55:28 +00:00
Rebecca Law
cf3a933b1e Updated error message is the code is not the right size or data type.
Updated two_factor to error is the user account is locked (locked = over 10 failed_login_count)
2017-02-15 14:56:22 +00:00
Leo Hemsted
08881e5bd1 add get_active_services method
* all current invocations of get_services now call get_active_services
  EXCEPT for platform admin page (where we want to see inactive services
* cleaned up parameter names and unpacking (since *params is unhelpful)
* fixed incorrect kwarg name in conftest
2016-11-16 11:08:20 +00:00
Chris Hill-Scott
14b99e5a24 Go to platform admin page when logging in
If you’re a platform admin, you should go straight to the platform admin
page when you log in.

The all services page is just a crappier version of the same thing,
without all the stats, etc.
2016-10-30 09:16:35 +00:00
Imdad Ahad
defa7ac2c8 Remove spacing 2016-09-09 15:24:56 +01:00