Guest User

Untitled

a guest
Apr 16th, 2018
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. # This will generate something like "jfonda51", and a password like "0be21405590f",
  2. # which is completely secure.
  3. if client.first_name? && client.last_name?
  4. new_credentials = Credentials.new([client.first_name[0..0], client.last_name].join.downcase)
  5.  
  6. # Replace the username, if it is blank
  7. if client.username.blank?
  8. # Check for existing usernames, and regenerate until unique
  9. until Client.exists?(:username => new_credentials.username) == false
  10. new_credentials = Credentials.new([client.first_name[0..0], client.last_name].join.downcase)
  11. end
  12.  
  13. client.username = new_credentials.username
  14. end
  15.  
  16. # Replace the password, if it is blank
  17. if client.crypted_password.blank?
  18. client.password = new_credentials.password
  19. client.password_confirmation = new_credentials.password
  20. end
  21.  
  22. # Save the client
  23. client.save
  24. end
Add Comment
Please, Sign In to add comment