Assigning a random password while using Devise -
Assigning a random password while using Devise -
here's breakdown of situation -
desired behavior: user can sign_up through devise gem providing email address only. web app generates , db stores temporary password, unknown user.
logic: meant 'gradual sign-up' process web application still under construction (we want begin capturing potential users without providing access web app it's still in partial development). email used communication purposes until final release.
problem: devise gem requires user input email && password during sign_up process. we've found no obvious way circumvent dual requirement. user failing provide password generates error.
potential solution: after searches , many tries, seems closest alternative (found here).
generated_password = devise.friendly_token.first(8) user = user.create!(:email => email, :password => generated_password) question: while potential solution makes sense, we're new , don't understand in file place code within devise configuration, , how phone call it.
all help appreciated.
lm
ok, kept digging until found looking (here) - maybe can help too.
in model:
before_validation :generate_password, :on => :create def generate_password o = [('a'..'z'), ('a'..'z'), (0..9)].map{|i| i.to_a}.flatten self.password = self.password_confirmation = (0..16).map{ o[rand(o.length)] }.join if self.password.blank? end devise passwords
Comments
Post a Comment