Activate a user account

@return User
199410
public function activate($token)
    {
        if ($this->service->activateUser($token)) {
            return redirect('dashboard')->with('message', 'Your account was activated');
        }

        return view('auth.activate.email')->withErrors(['Could not validate your token']);
    }
1083280
public function getUser()
    {
        if ($this->_oActiveUser == null) {
            $this->_oActiveUser = false;
            $sOxId = $this->getEditObjectId();
            if (isset($sOxId) && $sOxId != "-1") {
                // load object
                $this->_oActiveUser = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
                $this->_oActiveUser->load($sOxId);
            }
        }

        return $this->_oActiveUser;
    }
787769
public function registerUser()
    {
        // Create the new user
        $user = $this->user->create($this->getUserFromRequest());

        if (! $user) {
            return $user;
        }

        // Fire the registering event.
        event(new UserRegistering($user));

        // Add the extra details needed to finish them.
        // Add the user details.
        $this->userDetails->create($this->getUserDetailsFromRequest($user));

        // Assign the user to the default group
        $user->assignRole(config('jumpgate.users.default_role'));

        // If we do not require activation, set the user as active.
        if (! config('jumpgate.users.require_email_activation')) {
            $user->setStatus(Status::ACTIVE);
        }

        // Fire the registered event.
        event(new UserRegistered($user));

        return $user;
    }
67097
static function currentUser()
    {
        $user = self::instance();
        if ( $user->isAnonymous() || $user->isEnabled() )
        {
            return $user;
        }
        self::logoutCurrent();
        return self::instance();
    }
1296789
public function activate()
    {
        if ($this->status == self::STATUS_REGISTERED) {
            $transaction = static::getDb()->beginTransaction();
            try {
                $this->removeActivationToken();
                $this->status = self::STATUS_ACTIVE;
                if (!$this->save()) {
                    throw new Exception('User saving error!');
                }
                if (!Podium::getInstance()->rbac->assign(Podium::getInstance()->rbac->getRole(Rbac::ROLE_USER), $this->id)) {
                    throw new Exception('User role assigning error!');
                }
                $transaction->commit();
                return true;
            } catch (Exception $e) {
                $transaction->rollBack();
                Log::error($e->getMessage(), null, __METHOD__);
            }
        }
        return false;
    }
143909
public function user()
    {
        if ($this->user !== null) {
            return $this->user;
        }

        if ($this->jwT->setRequest($this->request)->getToken() &&
            ($payload = $this->jwT->check(true)) &&
            $this->jwT->checkProvider($this->provider->getModel())
        ) {
            return $this->user = $this->provider->retrieveById($payload['sub']);
        }
    }
1097571
function doUpdateActivate(Userinfo $userinfo, Userinfo &$existinguser, $overwrite)
	{
		$changed = false;
		//check the activation status
		if (isset($existinguser->activation)) {
			if ($existinguser->activation != $userinfo->activation) {

				$update_activation = $this->params->get('update_activation', false);
				if ($update_activation || $overwrite) {
					if ($userinfo->activation) {
						//inactive the user
						try {
							$this->inactivateUser($userinfo, $existinguser);
							$changed = true;
						} catch (Exception $e) {
							$this->debugger->addError(Text::_('ACTIVATION_UPDATE_ERROR') . ' ' . $e->getMessage());
						}
					} else {
						//activate the user
						try {
							$this->activateUser($userinfo, $existinguser);
							$changed = true;
						} catch (Exception $e) {
							$this->debugger->addError(Text::_('ACTIVATION_UPDATE_ERROR') . ' ' . $e->getMessage());
						}
					}
				} else {
					//return a debug to inform we skipped this step
					$this->debugger->addDebug(Text::_('SKIPPED_ACTIVATION_UPDATE') . ': ' . $existinguser->activation . ' -> ' . $userinfo->activation);
				}
			}
		}
		return $changed;
	}
616112
def activate_user(query):
    
    user = _query_to_user(query)
    if click.confirm(f'Are you sure you want to activate {user!r}?'):
        user.active = True
        user_manager.save(user, commit=True)
        click.echo(f'Successfully activated {user!r}')
    else:
        click.echo('Cancelled.')
871101
public function activate($id)
    {
        $this->loadModel('User.Users');
        $user = $this->Users->get($id, ['fields' => ['id', 'name', 'email']]);

        if ($this->Users->updateAll(['status' => 1], ['id' => $user->id])) {
            NotificationManager::activated($user)->send();
            $this->Flash->success(__d('user', 'User {0} was successfully activated!', $user->name));
        } else {
            $this->Flash->danger(__d('user', 'User could not be activated, please try again.'));
        }

        $this->title(__d('user', 'Unblock User Account'));
        $this->redirect($this->referer());
    }
698046
public function activateUser(string $key)
    {

        // Get tokendate from db
        $tokenhandler = new ActivationToken($this->db);
        $tokenhandler->setSelectorTokenString($key);

        // Store the current to extracted from selector:token string ($key)
        $token_from_key = $tokenhandler->getActivationToken();

        // Load the tokendata by using the selector from selector:token string ($key)
        $tokenhandler->loadTokenData();

        // Get user id
        $id_user = $tokenhandler->getUserId();

        // No user id means the activation must fail
        if (empty($id_user)) {
            return false;
        }

        // Get the token loaded from db via selector from selector:token string ($key)
        $token_from_db = $tokenhandler->getActivationToken();

        // Matching hashes?
        if (!hash_equals($token_from_key, $token_from_db)) {
            return false;
        }

        // Activate user
        $this->db->qb([
            'table' => $this->table,
            'method' => 'UPDATE',
            'fields' => 'state',
            'filter' => 'id_user=:id_user',
            'params' => [
                ':state' => 0,
                ':id_user' => $id_user
            ]
        ], true);

        // and delete the token of this user
        $tokenhandler->deleteActivationToken();

        // And finally return user id
        return $id_user;
    }
1020100
public function createActivationToken()
    {
        // No token without user id!
        if ($this->checkMissingUserId() === true) {
            return;
        }

        // First: clean all expired tokens!
        $this->removeExpiredTokens();

        // Delete all existing tokens of this user
        $this->db->delete($this->table, 'id_user=:id_user', [
            'id_user' => $this->id_user
        ]);

        $data = [
            'id_user' => $this->id_user,
            'selector' => $this->getSelector(),
            'token' => $this->getActivationToken(),
            'expires' => $this->getExpires()
        ];

        $this->db->qb([
            'table' => $this->table,
            'data' => $data
        ], true);

        return $this->selector . ':' . $this->activation_token;
    }
1051795
public function activateUser($userId): NgUserSetting
    {
        $ngUserSetting = $this->findOneBy(['userId' => $userId]);

        if ($ngUserSetting instanceof NgUserSetting) {
            $ngUserSetting->setIsActivated(true);
        } else {
            $ngUserSetting = new NgUserSetting($userId, true);
        }

        $this->getEntityManager()->persist($ngUserSetting);
        $this->getEntityManager()->flush();

        return $ngUserSetting;
    }
563614
public function convertGuestToUser($user, $credentials, $activate = false)
    {
        $user->fill($credentials);
        $user->convertToRegistered(false);

        // Remove user from guest group
        if ($group = UserGroupModel::getGuestGroup()) {
            $user->groups()->remove($group);
        }

        if ($activate) {
            $user->attemptActivation($user->getActivationCode());
        }

        // Prevents revalidation of the password field
        // on subsequent saves to this model object
        $user->password = null;

        return $this->user = $user;
    }
522471
public function getSelectedUser()
    {
        static $user = null;

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

        $staffId = $this->_getIdParam();
        if ($staffId) {
            $user   = $this->loader->getUserLoader()->getUserByStaffId($staffId);
            $source = $this->menu->getParameterSource();
            $user->applyToMenuSource($source);
        } else {
            $user = false;
        }

        return $user;
    }
119535
public function activate($username)
    {
        $user = $this->findUserByUsernameOrThrowException($username);
        $user->setEnabled(true);
        $this->userManager->updateUser($user);

        $event = new UserEvent($user, $this->getRequest());
        $this->dispatcher->dispatch(Events::USER_ACTIVATED, $event);
    }
1370728
public function onRegister()
    {
        try {
            if (!$this->canRegister()) {
                throw new ApplicationException(Lang::get(/*Registrations are currently disabled.*/'rainlab.user::lang.account.registration_disabled'));
            }

            /*
             * Validate input
             */
            $data = post();

            if (!array_key_exists('password_confirmation', $data)) {
                $data['password_confirmation'] = post('password');
            }

            $rules = [
                'email'    => 'required|email|between:6,255',
                'password' => 'required|between:4,255|confirmed'
            ];

            if ($this->loginAttribute() == UserSettings::LOGIN_USERNAME) {
                $rules['username'] = 'required|between:2,255';
            }

            $validation = Validator::make($data, $rules);
            if ($validation->fails()) {
                throw new ValidationException($validation);
            }

            /*
             * Register user
             */
            Event::fire('rainlab.user.beforeRegister', [&$data]);

            $requireActivation = UserSettings::get('require_activation', true);
            $automaticActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_AUTO;
            $userActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_USER;
            $user = Auth::register($data, $automaticActivation);

            Event::fire('rainlab.user.register', [$user, $data]);

            /*
             * Activation is by the user, send the email
             */
            if ($userActivation) {
                $this->sendActivationEmail($user);

                Flash::success(Lang::get(/*An activation email has been sent to your email address.*/'rainlab.user::lang.account.activation_email_sent'));
            }

            /*
             * Automatically activated or not required, log the user in
             */
            if ($automaticActivation || !$requireActivation) {
                Auth::login($user);
            }

            /*
             * Redirect to the intended page after successful sign in
             */
            if ($redirect = $this->makeRedirection(true)) {
                return $redirect;
            }
        }
        catch (Exception $ex) {
            if (Request::ajax()) throw $ex;
            else Flash::error($ex->getMessage());
        }
    }
689301
public function activate($tokenString)
    {
        $token = $this->findToken($tokenString);

        // If we could not find a token or it has expired, fail the attempt.
        if (is_null($token) || $token->isExpired()) {
            return Response::failed('Activation failed.')
                           ->route('auth.invitation.failed', $tokenString);
        }

        // Activate the user and log them in.
        $token->user->activateInvitation();

        auth()->login($token->user);

        return Response::passed('Your account has been activated.')
                       ->route('home');
    }