Refresh the state of the current user, or add if not exists.

@param User $user
@param string $route
@return bool
549812
public static function refreshUser(User $user, $route)
    {
        // skip the process if an api user is try to refresh.
        if ($user->is_api_user) {
            return;
        }
        
        $model = self::findOne(['user_id' => $user->id]);
        
        if ($model) {
            return (bool) $model->updateAttributes(['last_timestamp' => time(), 'invoken_route' => $route]);
        }
        
        $model = new self(['last_timestamp' => time(), 'user_id' => $user->id, 'invoken_route' => $route]);
        return $model->save();
    }
1135462
public function update(User $user, User $entity)
    {
        if ($entity->id === $user->id) {
            return true;
        }
        return $user->hasPermission('user-update');
    }
627275
public static function addBlock($template, $user)
    {
        $blocker = static::where([
            'template' => $template,
            'user_id'  => $user->id
        ])->first();

        if ($blocker && $blocker->email == $user->email) {
            return false;
        }

        if (!$blocker) {
            $blocker = new static;
            $blocker->template = $template;
            $blocker->user_id = $user->id;
        }

        $blocker->email = $user->email;
        $blocker->save();

        return true;
    }
754150
public function deleted(User $user)
    {
        \DB::table((new Revision())->getTable())->insert([
            [
                'revisionable_type' => $user->getMorphClass(),
                'revisionable_id' => $user->id,
                'key' => 'deleted_at',
                'old_value' => $user,
                'new_value' => new \DateTime(),
                'user_id' => (\Auth::check() ? \Auth::user()->id : null),
                'created_at' => new \DateTime(),
                'updated_at' => new \DateTime(),
            ]
        ]);
    }
965420
public function isUnread(User $user)
    {
        if ($this->posts->count() === 0) {
            return false;
        }

        return $this->posts->last()->isUnread($user);
    }
1273014
public function resetPasswordAction(Request $request, User $user)
    {
        $form = $this->createFormBuilder(null, $this->getDefaultFormOptions($request, $user->getId()))->getForm();

        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $this->get(UserManagerInterface::class)->requestNewPassword($user);
            $this->saveEntity($user);

            if ($request->isXmlHttpRequest()) {
                return array_merge(
                    $this->getViewParameters($request, $form, $user),
                    [
                        'dataId' => $user->getId(),
                        'success' => 1,
                    ]
                );
            }

            return $this->redirectToAction('list');
        }

        return $this->renderAction(
            array_merge(
                $this->getViewParameters($request, $form, $user),
                [
                    'dataId' => $user->getId(),
                ]
            )
        );
    }
386278
public function edit(Request $request, $user)
    {
        // Set roles that have access
        $request->user()->authorizeRoles(['admin']);

        // Return view with user object
        $user = User::findOrFail($user);
        return view('user::edit', ['user' => $user]);
    }
162991
public function changePasswordUpdate(ChangePasswordRequest $request, User $user)
    {
        $password = $request->get('password');
        $user->update(['password' => bcrypt($password)]);
        Mail::to($user->email)->send(new ChangePasswordMail($user, $password));

        return redirect()->route('admin.user.index');
    }
1146233
public function getUserRoute($route, array $user) {
        $route = Configure::read('User.routes.' . $route);

        if (!$route) {
            return null;
        }

        $route = (array) $route;

        foreach ($route as &$value) {
            if ($value === '{id}') {
                $value = $user['id'];

            } else if ($value === '{slug}' && isset($user['slug'])) {
                $value = $user['slug'];

            } else if ($value === '{username}') {
                $value = $user[Configure::read('User.fieldMap.username')];
            }
        }

        return $this->url($route);
    }
46287
public function updateUserRefreshToken(BaseUser $user)
    {
        if (!$user->isRefreshTokenValid()) {
            $user->setRefreshToken(bin2hex(random_bytes(90)));
        }

        $expirationDate = new \DateTime();
        $expirationDate->modify('+' . $this->refreshTokenTTL . ' seconds');
        $user->setRefreshTokenExpire($expirationDate);
        $this->save($user);

        return $user;
    }
298897
public function activate(User $user)
    {
        $user->is_activated = ! $user->is_activated;
        $user->save();

        if ($user->is_activated) {
            return $this->notifySuccess('User ' . $user->name . ' activated!');
        } else {
            return $this->notifySuccess('User ' . $user->name . ' deactivated!');
        }
    }
980514
public function update(User $user, Block $block)
    {

        if ($user->canDo('block.block.update') && $user->isAdmin()) {
            return true;
        }

        return $user->id == $block->user_id;
    }
172711
public function addUser($user)
    {
        if (!$this->hasUser($user)) {
            return RoleUser::create(['role_id' => $this->id, 'user_id' => $user->id]);
        }

        return false;
    }
324320
public function store(CreateUser $request)
    {
        $request->merge(['password' => bcrypt($request->get('password'))]);

        try {
            $user = UserProxy::create($request->except('roles'));
            $user->syncRoles($request->roles());

            flash()->success(__('User has been created'));
        } catch (\Exception $e) {
            flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
            return redirect()->back();
        }

        //@todo process route prefixes based on box config
        return redirect(route('appshell.user.index'));
    }
558229
public static function accessPossible(User $user, $controller, $action) {
        return self::getImplementation()->accessPossible($user, $controller, $action);
    }
1169724
public function socialUpdate($provider, User $user)
    {
        $this->getProviderDetails($provider);

        // Get the users.
        $socialUser = $this->getSocialUser();

        // Update or create provider details.
        $this->updateFromProvider($user, $socialUser);

        return $socialUser;
    }
843622
public function deleteAction(User $user)
    {
        if ($user === $this->currentUser) {
            $this->addFlashMessage('You can not delete the currently logged in user', 'Current user can\'t be deleted', Message::SEVERITY_WARNING, [], 1412374546);
            $this->redirect('index');
        }
        $this->userService->deleteUser($user);
        $this->addFlashMessage('The user "%s" has been deleted.', 'User deleted', Message::SEVERITY_NOTICE, [htmlspecialchars($user->getName()->getFullName())], 1412374546);
        $this->redirect('index');
    }