halogenandtoast/oath

sign_up helper issues

lifeiscontent opened this issue · 6 comments

is there any way to update a user rather than create one?

I want to do a look up in the DB to see if a user has already be created via text message, look up their phone number and if they're in the database populate the rest of the fields with user information.

Can you go into a bit more details. My assumption is you would just interface with your user model since this doesn't seem to be operating at the authentication level.

# in Rails 4
if user = User.find_by(phone_number: params[:user][:phone_number])
  user.update(user_params) # permitted user_params
else
  sign_up(user_params) # permitted user_params
end

@halogenandtoast during the signup flow, a user may already have interacted with my application via a text message, if they have I've already created their account.

I want to do a lookup into their account and finish building their user, e.g. password_digest, email, etc.

I'm assuming your sign_up method is the only thing that knows how to add a password_digest to a user.

Actually I think in this case the PasswordReset service is your best bet then, that or implement the calls performed in PasswordReset on your model.

https://github.com/halogenandtoast/monban/blob/master/lib/monban/services/password_reset.rb

Looking at the password reset you'll still need to save your model yourself so something like the following in your case

if user = User.find_by(phone_number: params[:user][:phone_number])
  PasswordReset.new(user, password_param).perform
  user.update(user_params_without_password)
end

@halogenandtoast thanks for the help, I'll play around with it maybe later this week.

@lifeiscontent let me know if you have any additional questions.

It's been a month, no questions, so I'm closing this.