Activate a user based on the provided activation code
@param  string $code
@return Reply
978860
public function activate($code)
    {
        try {
            // Attempt to fetch the user via the activation code
            $activation = $this->activations
                           ->createModel()
                           ->newQuery()
                           ->where('code', $code)
                           ->where('completed', false)
                           ->where('created_at', '>', Carbon::now()->subSeconds(259200))
                           ->first();

            if (!$activation) {
                $message = $this->translate("activation_problem", "Invalid or expired activation code.");
                throw new InvalidArgumentException($message);
            }
            $user = $this->sentinel->findUserById($activation->user_id);

            // Complete the user's activation
            $this->activations->complete($user, $code);

            // While we are here, lets remove any expired activations
            $this->activations->removeExpired();
        } catch (Exception $e) {
            return $this->returnException($e);
        }

        if ($user) {
            $message = $this->translate("activation_success", "Activation successful.");
            return new SuccessReply($message);
        }

        $message = $this->translate('activation_failed', 'There was a problem activating your account.');
        return new FailureReply($message);
    }
324509
public function updateUserWithActivationCode($userId, $activationCode, $activationExpiry) {
        $authVars = Garp_Auth::getInstance()->getConfigValues('forgotpassword');
        $expiresColumn = $authVars['activation_code_expiration_date_column'];
        $tokenColumn   = $authVars['activation_token_column'];

        $quotedUserId = $this->getAdapter()->quote($userId);
        return $this->update(
            array(
            $expiresColumn => $activationExpiry,
            $tokenColumn => $activationCode
            ), "id = $quotedUserId"
        );
    }
596043
public function setCode(int $code, string $reasonPhrase = null): self
    {
        $this->code         = $code;
        $this->reasonPhrase = null === $reasonPhrase ? Http::reasonPhraseFor($code) : $reasonPhrase;
        return $this;
    }
1135575
public function onActivate($code = null)
    {
        try {
            $code = post('code', $code);

            $errorFields = ['code' => Lang::get(/*Invalid activation code supplied.*/'rainlab.user::lang.account.invalid_activation_code')];

            /*
             * Break up the code parts
             */
            $parts = explode('!', $code);
            if (count($parts) != 2) {
                throw new ValidationException($errorFields);
            }

            list($userId, $code) = $parts;

            if (!strlen(trim($userId)) || !strlen(trim($code))) {
                throw new ValidationException($errorFields);
            }

            if (!$user = Auth::findUserById($userId)) {
                throw new ValidationException($errorFields);
            }

            if (!$user->attemptActivation($code)) {
                throw new ValidationException($errorFields);
            }

            Flash::success(Lang::get(/*Successfully activated your account.*/'rainlab.user::lang.account.success_activation'));

            /*
             * Sign in the user
             */
            Auth::login($user);

        }
        catch (Exception $ex) {
            if (Request::ajax()) throw $ex;
            else Flash::error($ex->getMessage());
        }
    }
680625
public function actionAuthorise( $code, $state ) {

		// Get Token
		$accessToken	= $this->googleService->getAccessToken( $code, $state );
		$snsUser		= $this->googleService->getUser( $accessToken );

		if( isset( $snsUser ) ) {

			// Get User
			$user = $this->modelService->getUser( $snsUser, $accessToken );

			// Login and Redirect to home page
			$login = new GoogleLogin( $user );

			if( $login->login() ) {

				return $this->redirect( [ '/user/index' ] );
			}
		}

		// Model not found
		throw new NotFoundHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
    }
346348
public function findByActivationCode($code)
	{
		if ( ! $code)
		{
			throw new \InvalidArgumentException("No activation code passed.");
		}

		$model = $this->createModel();

		$result = $model->newQuery()->where('activation_code', '=', $code)->get();

		if (($count = $result->count()) > 1)
		{
			throw new \RuntimeException("Found [$count] users with the same activation code.");
		}

		if ( ! $user = $result->first())
		{
			throw new UserNotFoundException("A user was not found with the given activation code.");
		}

		return $user;
	}
99899
public function getActivate($userId, $activationCode)
    {
        // Is user logged in?
        if (Sentinel::check())
        {
            if (Sentinel::inRole('admin'))
                return Redirect::route('home');
            else
                return Redirect::route('user.home');
        }

        // Find the user using the password reset code
        if(!$user = Sentinel::findById($userId))
        {
            // Redirect to the forgot password page
            return Redirect::route('login')->with('error', Lang::get('base.auth.activate.error'));
        }
        // $activation = Activation::exists($user);

        if (Activation::complete($user, $activationCode))
        {
            $user->status = 1;
            $user->save();
            
            // Activation was successful
            // Redirect to the login page
            return Redirect::route('login')->with('success', Lang::get('base.auth.activate.success'));
        }
        else
        {
            // Activation not found or not completed.
            $error = Lang::get('base.auth.activate.error');
            return Redirect::route('login')->with('error', $error);
        }

    }
488087
public function actionConfirm($id, $code)
    {
        $user = User::findOne($id);
        if ($user === null || Yii::$app->settings->get('enableConfirmation','user') == false) {
            return $this->goBack();
        }
        $user->attemptEmailConfirmation($code);
        return $this->redirect(['/user/settings/profile']);
    }
864581
public function activate($activate_token) //@todo: rename to 'activateUserAccount'
    {
        $return['error'] = true;
        $block_status = $this->isBlocked();

        if ($block_status == "block") {
            $return['message'] = $this->__lang("user_blocked");

            return $return;
        }

        if (strlen($activate_token) !== self::TOKEN_LENGTH) {
            $this->addAttempt();
            $return['message'] = $this->__lang("activationkey_invalid");

            return $return;
        }

        // 'user is already activated' will never triggered, because after successful activation token removed from DB
        // NOW is no any way to determine, is this token used for activation or not?

        $request_result = $this->getRequest($activate_token, "activation");

        if ($request_result['error']) {
            $return['message'] = $request_result['message'];

            return $return;
        }

        if ($this->getBaseUser($request_result['uid'])['isactive'] == 1) {
            $this->addAttempt();
            $this->deleteRequest($request_result['id']);
            $return['message'] = $this->__lang("system_error") . " #02"; // user activated, but activate token not expired

            return $return;
        }

        $query = "UPDATE {$this->config->table_users} SET isactive = :isactive WHERE id = :id";
        $query_prepared = $this->dbh->prepare($query);
        $query_params = [
            'isactive' => 1,
            'id' => $request_result['uid']
        ];
        $query_prepared->execute($query_params);

        $this->deleteRequest($request_result['id']);

        $return['error'] = false;
        $return['message'] = $this->__lang("account_activated");

        return $return;
    }
287473
public function isActive($code)
    {
        return $code && (bool) Arr::get($this->getCurrency($code), 'active', false);
    }
147245
public function getVerify($code = null)
    {
        if ($code === null) {
            throw new NotFoundHttpException();
        }

        $subscriber = Subscriber::where('verify_code', '=', $code)->first();

        if (!$subscriber) {
            throw new BadRequestHttpException();
        }

        if (!$subscriber->is_verified) {
            execute(new VerifySubscriberCommand($subscriber));
        }

        return cachet_redirect('status-page')
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.verified')));
    }
192627
public function authenticate($provider, $code=False)
    {
        if($code){
            return $this->handleProviderCallback($provider);
        }

        return $this->redirectToProvider($provider);
    }
141970
def activate(self, auth, codetype, code, defer=False):
        

        return self._call('activate', auth, [codetype, code], defer)
699440
public function attemptActivation($activationCode)
	{
		if ($this->activated)
		{
			throw new UserAlreadyActivatedException('Cannot attempt activation on an already activated user.');
		}

		if ($activationCode == $this->activation_code)
		{
			$this->activation_code = null;
			$this->activated       = true;
			$this->activated_at    = new DateTime;
			return $this->save();
		}

		return false;
	}
1163523
public function setStatusCode($code)
    {
        $this->headerBag->setStatusCode($code);
        $this->statusCode = $code;

        return $this;
    }
1203361
public function statusCode($code = null, $reasonPhrase = null)
    {
        if (func_num_args() < 1 || empty($code)) {
            return $this->response->getStatusCode();
        }
        $this->response = $this->response->withStatus($code, $reasonPhrase);
        return $this;
    }
174508
public function generateToken($code)
    {
        $this->token = $this->provider->getAccessToken('authorization_code', [
            'code' => $code
        ]);

        return $this->token;
    }