Finds user of given status by password reset token
@param string $token password reset token
@param string|null $status user status or null
@return static|null
508516
public static function findByPasswordResetToken($token, $status = self::STATUS_ACTIVE)
    {
        if (!static::isPasswordResetTokenValid($token)) {
            return null;
        }
        if ($status == null) {
            return static::find()->where(['password_reset_token' => $token])->limit(1)->one();
        }
        return static::find()->where(['password_reset_token' => $token, 'status' => $status])->limit(1)->one();
    }
215540
public function getUser($status = User::STATUS_ACTIVE)
    {
        if ($this->_user === false) {
            $this->_user = User::findByKeyfield($this->username, $status);
        }
        return $this->_user;
    }
1189650
public function getUserFromToken($token)
    {
        $expiration = U::unixToDb(time() - UserLink::$forgotLinkTimeframe);
        $link = UserLink::where('link', $token)
            ->where('type', UserLink::FORGOT_PASSWORD)
            ->where('created_at', $expiration, '>')
            ->first();

        if (!$link) {
            throw new AuthException('This link has expired or is invalid.');
        }

        $userClass = $this->auth->getUserClass();

        return $userClass::find($link->user_id);
    }
719578
public function setStatusUser($status)
    {
        $options = $id = $result = null;

        if ($this->getParam('all')) {
            $options = array();
        } else {

            $id = $this->getParam(0);

            if (!is_numeric($id)) { // Allow 0 for roleless users
                $this->errorAndExit($this->text('Invalid argument'));
            }

            if ($this->getParam('role')) {
                $options = array('role_id' => $id);
            } else if ($this->getParam('store')) {
                $options = array('store_id' => $id);
            }
        }

        if (isset($options)) {

            $updated = $count = 0;
            foreach ($this->user->getList($options) as $item) {
                $count++;
                $updated += (int) $this->user->update($item['user_id'], array('status' => (bool) $status));
            }

            $result = $count && $count == $updated;

        } else if (isset($id)) {
            $result = $this->user->update($id, array('status' => (bool) $status));
        }

        if (empty($result)) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
781987
public function index($token)
    {
        // Validate token
        /** @var $resetToken ResetPasswordModel */
        $resetToken = $this->resetPasswordRepository->getByToken($token);
        if (empty($resetToken) || $resetToken->isUsed()) {
            return view('nodes.api::reset-password.invalid');
        }

        // Check if token's expiry date has been exceed
        if ($resetToken->isExpired()) {
            return view('nodes.api::reset-password.expired');
        }

        return view('nodes.api::reset-password.form', compact('token'));
    }
505698
public function userFromTokenAndSecret($token, $secret)
    {
        $tokenCredentials = new TokenCredentials();

        $tokenCredentials->setIdentifier($token);
        $tokenCredentials->setSecret($secret);

        $user = $this->server->getUserDetails(
            $tokenCredentials, $this->shouldBypassCache($token, $secret)
        );

        $instance = (new User)->setRaw($user->extra)
            ->setToken($tokenCredentials->getIdentifier(), $tokenCredentials->getSecret());

        return $instance->map([
            'id' => $user->uid,
            'nickname' => $user->nickname,
            'name' => $user->name,
            'email' => $user->email,
            'avatar' => $user->imageUrl,
        ]);
    }
1371277
public function resetPassword($token, $password)
    {
        $this->cleanResetTokens = true;

        /** @var PasswordResetToken $token */
        $token = $this->getEntityManager()->find(PasswordResetToken::class, $token);

        if (!$token) {
            throw new TokenNotFoundException;
        }

        $user = $token->getUser();
        $user->setPassword($password);

        $em = $this->getEntityManager();
        $em->remove($token);
        $em->flush();

        return $user;
    }
881250
public function authenticatedUser($token = null)
    {
        $token = $this->getToken($token);

        $usersAPI = new Users($token);

        return $usersAPI->authenticatedUser();
    }
641447
public function sendPasswordResetNotification($token)
    {
        // Send SMS
        $url = url('password/reset', $token);
        $sms = "Reset password using this link: $url";
        $oxygen = new OxygenSms();
        $signup = Signup::where('user_id', $this->id )->first();
        $oxygen->send( $sms, $signup->mobile_number );

        $this->notify(new ResetPasswordNotification($token));
    }
764826
public function resetPasswordConfirm($token, $remoteIP, Event $event)
    {
        // Hash the remote caller's IP with the token
        $tokenHash = md5($token . '-' . str_replace('.', '-', $remoteIP));

        /** @var UsersRepository $repo */
        $repo = $this->em->getRepository(Entity\Users::class);
        if ($userEntity = $repo->getUserShadowAuth($tokenHash)) {
            $userAuth = $repo->getUserAuthData($userEntity->getId());
            // Update entries
            $userEntity->setPassword($userAuth->getShadowpassword());
            $userEntity->setShadowpassword(null);
            $userEntity->setShadowtoken(null);
            $userEntity->setShadowvalidity(null);

            $this->em->getRepository(Entity\Users::class)->save($userEntity);

            $this->app['logger.flash']->clear();
            $this->app['logger.flash']->success(Trans::__('general.access-control.reset-successful'));
            $this->app['dispatcher']->dispatch(AccessControlEvents::RESET_SUCCESS, $event);

            return true;
        }
        // That was not a valid token, or too late, or not from the correct IP.
        $this->app['logger.system']->error('Somebody tried to reset a password with an invalid token.', ['event' => 'authentication']);
        $this->app['logger.flash']->error(Trans::__('general.access-control.reset-failed'));
        $this->app['dispatcher']->dispatch(AccessControlEvents::RESET_FAILURE, $event);

        return false;
    }
1154350
public function activate($token = null)
    {
        $activated = false;
        if ($token === null) {
            $this->redirect('/');
        }

        $this->loadModel('User.Users');
        $user = $this->Users
            ->find()
            ->select(['id', 'name', 'token'])
            ->where(['status' => 0, 'token' => $token])
            ->limit(1)
            ->first();

        if ($user) {
            if ($this->Users->updateAll(['status' => 1], ['id' => $user->id])) {
                NotificationManager::activated($user)->send();
                $activated = true;
                $this->Flash->success(__d('user', 'Account successfully activated.'), ['key' => 'activate']);
            } else {
                $this->Flash->danger(__d('user', 'Account could not be activated, please try again later.'), ['key' => 'activate']);
            }
        } else {
            $this->Flash->warning(__d('user', 'Account not found or is already active.'), ['key' => 'activate']);
        }

        $this->title(__d('user', 'Account Activation'));
        $this->set(compact('activated', 'token'));
    }
858968
public function get($token)
    {
        foreach (
            $this->getEntityManager()->getConnection()->fetchAll(
                'SELECT * FROM oauth_access_token WHERE access_token=:token',
                ['token' => $token]
            ) as $row
        ) {
            return (new AccessTokenEntity($this->server))
                ->setId($row['access_token'])
                ->setExpireTime($row['expire_time']);
        };
        return null;
    }
187816
public function passwordReset($id, $token)
    {
        $tokenExists = $this->Token->check($token, ['type' => 'password_forgot', 'user_id' => $id]);
        is_true_or_fail($tokenExists, __d('me_cms', 'Invalid token'), RecordNotFoundException::class);

        $user = $this->Users->findActiveById($id)->select(['id'])->firstOrFail();

        if ($this->request->is(['patch', 'post', 'put'])) {
            $user = $this->Users->patchEntity($user, $this->request->getData());

            if ($user->isDirty() && $this->Users->save($user)) {
                $this->Token->delete($token);
                $this->Flash->success(__d('me_cms', 'The password has been edited'));

                return $this->redirect(['_name' => 'login']);
            }

            $this->Flash->error(__d('me_cms', 'The password has not been edited'));
        }

        $this->set(compact('user'));
        $this->viewBuilder()->setLayout('login');
    }
245309
public function renewToken(?Token $token) : Token
    {
        if ($token === null) {
            throw new NullValueException("Token cannot be null");
        }

        $token->updateExisting([
            'token' => $this->generateToken($this->config->get('app.key')),
        ]);

        $this->fireUpdatedEvent($token->user, $token);

        return $token;
    }
706262
public function getByApiToken(int $id, string $token) : ?Authenticatable
    {
        $model = $this->getModel();

        $user = $model->newQuery()
                      ->where($model->getAuthIdentifierName(), $id)
                      ->first();

        if ($user === null) {
            return null;
        }

        $apiToken = $user->getApiToken();

        return !empty($apiToken) && hash_equals($apiToken, $token) ? $user : null;
    }
1328062
public function setStatus($status = null)
    {
        switch ($status) {
            //TODO implement all status codes
            case '500':
                $this->setStatusCode('HTTP/1.0 500 Internal Server Error');
                break;
            case '404':
                $this->setStatusCode('HTTP/1.0 404 Not Found');
                break;
            case '403':
                $this->setStatusCode('HTTP/1.0 403 Forbidden');
                break;
            case '402':
                $this->setStatusCode('HTTP/1.0 402 Payment Required');
                break;
            case '401':
                $this->setStatusCode('HTTP/1.0 401 Unauthorized');
                break;
            case '400':
                $this->setStatusCode('HTTP/1.0 400 Bad Request');
                break;
            case '200':
                $this->setStatusCode(Template::STATUS_OK);
                break;
            default:
                $this->setStatusCode('HTTP/1.0 ' .($status ?: 200));
                break;
        }
        return $this;
    }
432495
public static function findByActivationToken($token)
    {
        if (!static::isActivationTokenValid($token)) {
            return null;
        }
        return static::find()->where(['activation_token' => $token, 'status' => self::STATUS_REGISTERED])->limit(1)->one();
    }