Skip to content

Add optional on_login_success callback #90

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

floehopper
Copy link
Contributor

This adds a new on_login_success configuration option. If this option is set to a Proc and the login was successful, the Proc will be called in the context of the RpiAuth::AuthController#callback action, i.e. current_user will be available. This is intended to allow apps to record successful logins.

I'm not convinced that using instance_exec is the most sensible approach, but I decided it was better to be consistent with the way the success_redirect option is implemented.

If the Proc raises an exception, this will be rescued and the exception will be logged as a warning in the Rails log. This is so that the login will still complete successfully, even if there was a problem recording it.

The immediate motivation for adding this is so we can record successful student logins in experience-cs in order to be able to calculate the "active users" metric described in this issue. Unfortunately while this information is available in the profile app database for regular users; it's not available for student users.

This adds a new `on_login_success` configuration option. If this option
is set to a `Proc` and the login was successful, the `Proc` will be
called in the context of the `RpiAuth::AuthController#callback` action,
i.e. `current_user` will be available. This is intended to allow apps to
record successful logins.

I'm not convinced that using `instance_exec` is the most sensible
approach, but I decided it was better to be consistent with the way
the `success_redirect` option is implemented.

If the `Proc` raises an exception, this will be rescued and the
exception will be logged as a warning in the Rails log. This is so that
the login will still complete successfully, even if there was a problem
recording it.

The immediate motivation for adding this is so we can record successful
*student* logins in `experience-cs` in order to be able to calculate the
"active users" metric described in this issue [1]. Unfortunately while
this information is available in the `profile` app database for regular
users; it's not available for student users.

[1]: RaspberryPiFoundation/experience-cs#727
Copy link

Test coverage: 100.0%

Copy link

@fspeirs fspeirs left a comment

Choose a reason for hiding this comment

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

These changes make sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants