Esempio n. 1
0
 /**
  * Store a newly created user in storage.
  * @param  Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->checkPermission('users-manage');
     $validationRules = ['name' => 'required', 'email' => 'required|email|unique:users,email'];
     $authMethod = config('auth.method');
     if ($authMethod === 'standard') {
         $validationRules['password'] = '******';
         $validationRules['password-confirm'] = 'required|same:password';
     } elseif ($authMethod === 'ldap') {
         $validationRules['external_auth_id'] = 'required';
     }
     $this->validate($request, $validationRules);
     $user = $this->user->fill($request->all());
     if ($authMethod === 'standard') {
         $user->password = bcrypt($request->get('password'));
     } elseif ($authMethod === 'ldap') {
         $user->external_auth_id = $request->get('external_auth_id');
     }
     $user->save();
     if ($request->has('roles')) {
         $roles = $request->get('roles');
         $user->roles()->sync($roles);
     }
     // Get avatar from gravatar and save
     if (!config('services.disable_services')) {
         $avatar = \Images::saveUserGravatar($user);
         $user->avatar()->associate($avatar);
         $user->save();
     }
     return redirect('/settings/users');
 }
Esempio n. 2
0
 /**
  * Creates a new user and attaches a role to them.
  * @param array $data
  * @return User
  */
 public function registerNew(array $data)
 {
     $user = $this->create($data);
     $this->attachDefaultRole($user);
     // Get avatar from gravatar and save
     if (!config('services.disable_services')) {
         $avatar = \Images::saveUserGravatar($user);
         $user->avatar()->associate($avatar);
         $user->save();
     }
     return $user;
 }
Esempio n. 3
0
 /**
  * Store a newly created user in storage.
  * @param  Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->checkPermission('user-create');
     $this->validate($request, ['name' => 'required', 'email' => 'required|email|unique:users,email', 'password' => 'required|min:5', 'password-confirm' => 'required|same:password', 'role' => 'required|exists:roles,id']);
     $user = $this->user->fill($request->all());
     $user->password = bcrypt($request->get('password'));
     $user->save();
     $user->attachRoleId($request->get('role'));
     // Get avatar from gravatar and save
     if (!env('DISABLE_EXTERNAL_SERVICES', false)) {
         $avatar = \Images::saveUserGravatar($user);
         $user->avatar()->associate($avatar);
         $user->save();
     }
     return redirect('/users');
 }
Esempio n. 4
0
 /**
  * Creates a new user and attaches a role to them.
  * @param array $data
  * @return User
  */
 public function registerNew(array $data)
 {
     $user = $this->create($data);
     $this->attachDefaultRole($user);
     // Get avatar from gravatar and save
     if (!config('services.disable_services')) {
         try {
             $avatar = \Images::saveUserGravatar($user);
             $user->avatar()->associate($avatar);
             $user->save();
         } catch (Exception $e) {
             $user->save();
             \Log::error('Failed to save user gravatar image');
         }
     }
     return $user;
 }