Example #1
0
 /**
  * {@inheritdoc}.
  */
 protected function getValidator($model)
 {
     $user = $model->toArray();
     if ($this->updatedPassword) {
         $user['password'] = $this->updatedPassword;
         $user['password_confirmation'] = $this->updatedPassword;
     }
     return Validator::make($user, User::updateRules($model));
 }
Example #2
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method) {
         case 'GET':
             break;
         case 'DELETE':
             break;
         case 'POST':
             return User::createRules();
         case 'PUT':
             break;
         case 'PATCH':
             return User::updateRules($this);
         default:
             break;
     }
     return [];
 }
Example #3
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method) {
         case 'GET':
             break;
         case 'DELETE':
             break;
         case 'POST':
             return response('Unauthorized.', 401);
         case 'PUT':
             break;
         case 'PATCH':
             return User::updateRules($this);
         default:
             break;
     }
     return [];
 }
Example #4
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('user'))) {
         $this->warn('the required user argument was not passed, try --help');
         return false;
     }
     $user = false;
     if (!is_object($user)) {
         $user = User::where('email', $this->option('user'))->first();
     }
     if (!is_object($user)) {
         $user = User::find($this->option('user'));
     }
     if (!is_object($user)) {
         $this->error('Unable to find user with this criteria');
         return false;
     }
     // Apply changes to the user object
     if (!empty($this->option('email'))) {
         $user->email = $this->option('email');
     }
     if (!empty($this->option('password'))) {
         $user->password = $this->option('password');
     }
     if (!empty($this->option('autopassword'))) {
         $generatedPassword = substr(md5(rand()), 0, 8);
         $this->info("Using auto generated password: {$generatedPassword}");
         $user->password = $generatedPassword;
     }
     if (!empty($this->option('firstname'))) {
         $user->first_name = $this->option('firstname');
     }
     if (!empty($this->option('lastname'))) {
         $user->last_name = $this->option('lastname');
     }
     if (!empty($this->option('account'))) {
         $account = Account::where('name', '=', $this->option('account'))->first();
         if (!is_object($account)) {
             $this->error("The account named {$this->option('account')} was not found");
             return false;
         }
         $user->account_id = $account->id;
     }
     if (!empty($this->option('language'))) {
         $user->locale = $this->option('language');
     }
     if (!empty($this->option('disable'))) {
         $user->disabled = true;
     }
     if (!empty($this->option('enable'))) {
         $user->disabled = false;
     }
     // Validate the changes
     $validation = Validator::make($user->toArray(), User::updateRules($user));
     if ($validation->fails()) {
         foreach ($validation->messages()->all() as $message) {
             $this->warn($message);
         }
         $this->error('Failed to create the user due to validation warnings');
         return false;
     }
     // Save the object
     $user->save();
     $this->info("User has been successfully updated");
     return true;
 }