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

@ -3,18 +3,18 @@ task "admin:create" => :environment do
require 'highline/import'
begin
email = ask("Email:")
email = ask("Email: ")
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}
password_confirmation = ask("Repeat password:") {|q| q.echo = false}
password = ask("Password: ") {|q| q.echo = false}
password_confirmation = ask("Repeat password: ") {|q| q.echo = false}
end while password != password_confirmation
admin.password = password
end
@ -25,8 +25,8 @@ task "admin:create" => :environment do
username_random = Random.new()
admin.username = "admin_#{username_random.rand(9999)}"
begin
password = ask("Password:") {|q| q.echo = false}
password_confirmation = ask("Repeat password:") {|q| q.echo = false}
password = ask("Password: ") {|q| q.echo = false}
password_confirmation = ask("Repeat password: ") {|q| q.echo = false}
end while password != password_confirmation
admin.password = password
end
@ -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