Class: Cli::UsersCommand
- Inherits:
-
Thor
- Object
- Thor
- Cli::UsersCommand
- Defined in:
- app/lib/cli/users_command.rb
Constant Summary collapse
- DESCRIPTION =
"manage users"
Instance Method Summary collapse
Instance Method Details
#approve ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/lib/cli/users_command.rb', line 10 def approve u = User.find_by(email: [:email]) raise "User not found" if u.nil? u.update(approved: true) puts "\nUser #{u.email} approved" rescue RuntimeError puts "\nUser #{[:email]} not found" end |
#create ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/lib/cli/users_command.rb', line 45 def create u = User.create( username: [:username], email: [:email], password: [:password], password_confirmation: [:password_confirmation] ) if u.valid? u.add_role([:role].to_sym) if [:role] puts "\nNew user created OK" else puts "\nError when creating user:\n" puts u.errors..inspect end end |
#password ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/lib/cli/users_command.rb', line 22 def password u = User.find_by(email: [:email]) raise "User not found" if u.nil? if [:interactive] || !SiteSettings.email_configured? u.password = ask("Enter password: ", echo: false) puts "\n" u.password_confirmation = ask("Confirm password: ", echo: false) puts "\nPassword changed!" if u.save! else u.send_reset_password_instructions puts "\nPassword reset email sent!" end rescue ActiveRecord::RecordInvalid => e puts "\n#{e}" rescue RuntimeError => e puts "\n#{e}" end |