Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This will generate something like "jfonda51", and a password like "0be21405590f",
- # which is completely secure.
- if client.first_name? && client.last_name?
- new_credentials = Credentials.new([client.first_name[0..0], client.last_name].join.downcase)
- # Replace the username, if it is blank
- if client.username.blank?
- # Check for existing usernames, and regenerate until unique
- until Client.exists?(:username => new_credentials.username) == false
- new_credentials = Credentials.new([client.first_name[0..0], client.last_name].join.downcase)
- end
- client.username = new_credentials.username
- end
- # Replace the password, if it is blank
- if client.crypted_password.blank?
- client.password = new_credentials.password
- client.password_confirmation = new_credentials.password
- end
- # Save the client
- client.save
- end
Add Comment
Please, Sign In to add comment