Merge pull request #2490 from techAPJ/update_rake_task-2

Update admin create task
This commit is contained in:
Sam 2014-07-03 17:31:55 +10:00
commit 1ed97437ef

View file

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