src/controllers/UserController.php
public function putShow($userId)
    {
        try {
            $validator = new UserValidator(Input::all(), 'update');

            if(!$validator->passes()) {
                return Response::json(array('userUpdated' => false, 'errorMessages' => $validator->getErrors()));
            }

            $permissionsValues = Input::get('permission');
            $permissions = $this->_formatPermissions($permissionsValues);

            // Find the user using the user id
            $user = Sentry::getUserProvider()->findById($userId);
            $user->username = Input::get('username');
            $user->email = Input::get('email');
            $user->last_name = Input::get('last_name');
            $user->first_name = Input::get('first_name');
            $user->permissions = $permissions;

            $currentUser = Sentry::getUser();
            $permissions = (empty($permissions)) ? '' : json_encode($permissions);
            $hasPermissionManagement = $currentUser->hasAccess(Config::get('syntara::permissions.addUserPermission')) || $currentUser->hasAccess('superuser');
            if($hasPermissionManagement === true) {
                DB::table('users')
                    ->where('id', $userId)
                    ->update(array('permissions' => $permissions));
            }

            $pass = Input::get('pass');
            if(!empty($pass)) {
                $user->password = $pass;
            }

            // Update the user
            if($user->save()) {
                // if the user has permission to update
                $banned = Input::get('banned');
                if(isset($banned) && Sentry::getUser()->getId() !== $user->getId()) {
                    $this->_banUser($userId, $banned);
                }

                if($currentUser->hasAccess(Config::get('syntara::permissions.addUserGroup'))) {
                    $groups = (Input::get('groups') === null) ? array() : Input::get('groups');
                    $userGroups = $user->getGroups()->toArray();

                    foreach($userGroups as $group) {
                        if(!in_array($group['id'], $groups)) {
                            $group = Sentry::getGroupProvider()->findById($group['id']);
                            $user->removeGroup($group);
                        }
                    }
                    if(isset($groups) && is_array($groups)) {
                        foreach($groups as $groupId) {
                            $group = Sentry::getGroupProvider()->findById($groupId);
                            $user->addGroup($group);
                        }
                    }
                }

                return Response::json(array('userUpdated' => true, 'message' => trans('syntara::users.messages.update-success'), 'messageType' => 'success'));
            } else {
                return Response::json(array('userUpdated' => false, 'message' => trans('syntara::users.messages.update-fail'), 'messageType' => 'danger'));
            }
        } catch(\Cartalyst\Sentry\Users\UserExistsException $e) {
            return Response::json(array('userUpdated' => false, 'message' => trans('syntara::users.messages.user-email-exists'), 'messageType' => 'danger'));
        } catch(\Exception $e) {
            return Response::json(array('userUpdated' => false, 'message' => trans('syntara::users.messages.user-name-exists'), 'messageType' => 'danger'));
        }
    }
public function putShow($userId)
    {
        try {
            $validator = new UserValidator(Input::all(), 'update');

            if(!$validator->passes()) {
                return Response::json(array('userUpdated' => false, 'errorMessages' => $validator->getErrors()));
            }

            $permissionsValues = Input::get('permission');
            $permissions = $this->_formatPermissions($permissionsValues);

            // Find the user using the user id
            $user = Sentry::getUserProvider()->findById($userId);
            $user->username = Input::get('username');
            $user->email = Input::get('email');
            $user->last_name = Input::get('last_name');
            $user->first_name = Input::get('first_name');
            $user->permissions = $permissions;

            $currentUser = Sentry::getUser();
            $permissions = (empty($permissions)) ? '' : json_encode($permissions);
            $hasPermissionManagement = $currentUser->hasAccess(Config::get('syntara::permissions.addUserPermission')) || $currentUser->hasAccess('superuser');
            if($hasPermissionManagement === true) {
                DB::table('users')
                    ->where('id', $userId)
                    ->update(array('permissions' => $permissions));
            }

            $pass = Input::get('pass');
            if(!empty($pass)) {
                $user->password = $pass;
            }

            // Update the user
            if($user->save()) {
                // if the user has permission to update
                $banned = Input::get('banned');
                if(isset($banned) && Sentry::getUser()->getId() !== $user->getId()) {
                    $this->_banUser($userId, $banned);
                }

                if($currentUser->hasAccess(Config::get('syntara::permissions.addUserGroup'))) {
                    $groups = (Input::get('groups') === null) ? array() : Input::get('groups');
                    $userGroups = $user->getGroups()->toArray();

                    foreach($userGroups as $group) {
                        if(!in_array($group['id'], $groups)) {
                            $group = Sentry::getGroupProvider()->findById($group['id']);
                            $user->removeGroup($group);
                        }
                    }
                    if(isset($groups) && is_array($groups)) {
                        foreach($groups as $groupId) {
                            $group = Sentry::getGroupProvider()->findById($groupId);
                            $user->addGroup($group);
                        }
                    }
                }

                return Response::json(array('userUpdated' => true, 'message' => trans('syntara::users.messages.update-success'), 'messageType' => 'success'));
            } else {
                return Response::json(array('userUpdated' => false, 'message' => trans('syntara::users.messages.update-fail'), 'messageType' => 'danger'));
            }
        } catch(\Cartalyst\Sentry\Users\UserExistsException $e) {
            return Response::json(array('userUpdated' => false, 'message' => trans('syntara::users.messages.user-email-exists'), 'messageType' => 'danger'));
        } catch(\Exception $e) {
            return Response::json(array('userUpdated' => false, 'message' => trans('syntara::users.messages.user-name-exists'), 'messageType' => 'danger'));
        }
    }
Update user account
@param int $userId
@return Response