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