Update admin create task

This commit is contained in:
Arpit Jalan 2014-07-02 13:30:38 +05:30
parent 198731de23
commit 7cb67b028d

View File

@ -7,10 +7,10 @@ task "admin:create" => :environment do
existing_user = User.find_by_email(email)
# check if user account already exixts
if !existing_user.nil?
if existing_user
# user already exists, ask for password reset
admin = existing_user
reset_password = ask("User with this email already exists! Do you want to reset the password for this email? Type 'Y' for Yes, 'N' for No.")
reset_password = ask("User with this email already exists! Do you want to reset the password for this email? (y/n) ")
if (reset_password.downcase == 'y')
begin
password = ask("Password: ") {|q| q.echo = false}
@ -39,15 +39,15 @@ task "admin:create" => :environment do
end
end while !saved
if !existing_user.nil?
if existing_user
say("\nAccount updated successfully!")
else
say("\nAccount created successfully with username #{admin.username}")
end
# grant admin privileges
reset_password = ask("Do you want to grant Admin privileges to this account? Type 'Y' for Yes, 'N' for No.")
if (reset_password.downcase == 'y')
grant_admin = ask("Do you want to grant Admin privileges to this account? (y/n) ")
if (grant_admin.downcase == 'y')
admin.grant_admin!
admin.change_trust_level!(TrustLevel.levels.max_by{|k, v| v}[0])
admin.email_tokens.update_all confirmed: true