Reputation: 773
How can I create a Signup
using Devise
where instead of the user entering both his email
and password
during sign up, all he needs to enter is an email and then get the Password
generated through his email?
I'm trying to make sign up as simple as possible and I figured out that since devise is capable of sending out an activation email already, why not just piggy back on that and send a generated Password and confirm at the time of login?
Thanks for any help :)
Upvotes: 0
Views: 748
Reputation: 2143
You can use the Devise's friendly token in your controller:
password = Devise.friendly_token.first(8)
User.create(email: '[email protected]', password: password, password_confirmation: password)
The friendly_token is a string containing A-Z, a-z, 0-9, “-” and “_”.
Source code here:
def self.friendly_token
SecureRandom.urlsafe_base64(15).tr('lIO0', 'sxyz')
end
and here for more info:
def self.urlsafe_base64(n=nil, padding=false)
s = [random_bytes(n)].pack("m*")
s.delete!("\n")
s.tr!("+/", "-_")
s.delete!("=") if !padding
s
end
Upvotes: 1