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

Allow executing code after sign in and before sign out #61

Merged
merged 1 commit into from
Jan 1, 2016

Conversation

monfresh
Copy link
Collaborator

Why
In some cases, it might be necessary to run some code right after the user signs in, but before the OTP is sent, and also right before a user signs out.

For example, consider this scenario:

  • The app requires the user to confirm their phone number before it gets saved. This confirmation is done by sending an OTP to the phone and asking the user to enter it.
  • User mistypes the number, then closes the anonymous browser window, or signs out before confirming
  • User signs back in, and OTP is sent to the mistyped number. User is now unable to fully sign in since the OTP is being sent to the wrong number

In order to prevent this scenario, we need to be able to reset the unconfirmed_mobile to nil before the OTP is sent, and before they sign out so that they can type it in again.

How
Allow the gem user to define an OtpSender class with a reset_otp_state method

@Houdini
Copy link
Owner

Houdini commented Dec 30, 2015

Thatnks,

one thing I doubt about is that OtpSender says nothing about object.
If you use otp for user and admin_user, otp all goes to OtpSender.

What do you think about this:

def reset_otp_state_for(user)
  klass_string = "#{user.class}OtpSender"
  return unless Object.const_defined?(klass_string)

  klass = Object.const_get(klass_string)

  otp_sender = klass.new(user)

  otp_sender.reset_otp_state if otp_sender.respond_to?(:reset_otp_state)
end

@Houdini
Copy link
Owner

Houdini commented Dec 30, 2015

So OtpSender would be like service object.

UserOtpSender
AdminUserOtpSender

etc

@monfresh
Copy link
Collaborator Author

Good point. That way, you can have different logic for different types of users. I'll make the change.

**Why**
In some cases, it might be necessary to run some code right after the user signs in, but before the OTP is sent, and also right before a user signs out.

For example, consider this scenario:
- The app requires the user to confirm their phone number before it gets saved. This confirmation is done by sending an OTP to the phone and asking the user to enter it.
- User mistypes the number, then closes the anonymous browser window, or signs out before confirming
- User signs back in, and OTP is sent to the mistyped number. User is now unable to fully sign in since the OTP is being sent to the wrong number

In order to prevent this scenario, we need to be able to reset the `unconfirmed_mobile` to nil before the OTP is sent, and before they sign out so that they can type it in again.

**How**
Allow the gem user to define an OtpSender class with a `reset_otp_state` method
@monfresh
Copy link
Collaborator Author

I made the change. Let me know how it looks now. Thanks!

Houdini added a commit that referenced this pull request Jan 1, 2016
Allow executing code after sign in and before sign out
@Houdini Houdini merged commit d350b69 into Houdini:master Jan 1, 2016
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