Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <?php namespace Labkod\CMS\Console;
  2.  
  3. use Illuminate\Console\Command;
  4. use Symfony\Component\Console\Input\InputOption;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use App\User;
  7.  
  8. class UserCreateCommand extends Command {
  9.  
  10. /**
  11. * The console command name.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'cms:user:create
  16. {email? : E-mail of new user}
  17. {password? : Password of new user}
  18. {name? : Name of new user}
  19. {--A|admin : Set as admin role} ';
  20.  
  21. /**
  22. * The console command description.
  23. *
  24. * @var string
  25. */
  26. protected $description = 'Create new user';
  27.  
  28. /**
  29. * Create a new command instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. parent::__construct();
  36. }
  37.  
  38. /**
  39. * Execute the console command.
  40. *
  41. * @return mixed
  42. */
  43. public function handle()
  44. {
  45. $email = $this->argument('email') ? $this->argument('email') : $this->ask("Email?");
  46. $password = $this->argument('password') ? $this->argument('password') : $this->secret('Password?');
  47. $name = $this->argument('name') ? $this->argument('name') : null;
  48. $is_admin = $this->option('admin') ? true : false;
  49.  
  50. while(User::where("email", $email)->count() > 0){
  51. $this->error("This email is already in use. Please select another one.");
  52. $email = $this->ask("Email?");
  53. }
  54.  
  55. $user = new User;
  56. $user->name = $name;
  57. $user->email = $email;
  58. $user->password = bcrypt($password);
  59. $user->is_admin = $is_admin;
  60. $user->save();
  61.  
  62. $this->info(sprintf("User '%s' successfully created!", $email));
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement