Activates the user or returns an error message

@access protected
@param string $uuid
@param string $activationToken
@return array
430043
protected function activateUser($uuid, $activationToken)
    {
        // Check the uuid
        if (!$this->userManager->hasUserForUuid($uuid)) {
            return array('result' => false, 'message' => $this->translate('Account with the given UUID does not exist.', '\\Zepi\\Web\\AccessControl'));
        }
        
        // Compare the activation token
        $user = $this->userManager->getUserForUuid($uuid);
        if ($user->getMetaData('activationToken') !== $activationToken) {
            return array('result' => false, 'message' => $this->translate('The given activation token is not valid.', '\\Zepi\\Web\\AccessControl'));
        }
        
        // Remove the disabled access level
        $this->accessControlManager->revokePermission($uuid, get_class($user), '\\Global\\Disabled');
        $this->accessControlManager->grantPermission($uuid, get_class($user), '\\Global\\Active', 'Activation');
        
        return array('result' => true, 'message' => $this->translate('Your account was activated successfully.', '\\Zepi\\Web\\AccessControl'));
    }
424589
function getUIDCallback (err, uid) {
		if (err) {
			return onDone('UID_ERROR');
		}
		var ip = (extra) ? extra.conn.host : "server";
		// NOTE: by default a user is a normal user, user 'groups' can later be customized
		var reg = {
			uid: 		uid,
			account:	args.account,
			password:	l_encryptPass(args.password),
			email:		args.email,
			// verify:		{email_verify: false, phone_verify: false},
			tokens: 	{reset: '', pass: {}},
			enc_type:	l_enc_type,
			control:	{groups: args.groups || [], permissions: []},
			data: 		args.data || {},
			login: 		{IP: ip, count: 1}
		};

		// special handling (by default 'admin' account is special and will be part of the 'admin' group by default
		if (!args.authWP && reg.account === 'admin') {
			reg.control.groups.push('admin');
		}

		LOG.warn('creating new account [' + args.account + ']...', l_name);
		l_accounts.add(reg, function (err) {
			if (err) {
				return onDone('DB_ERROR', err);
			}
			// register success
			LOG.warn('account register success', l_name);
			onDone(null);
		});
	}
1222421
public function postTriggerAction(Request $request, $uuid, $version)
    {
        $action = $this->getRequestParameter($request, 'action', true);
        $language = $this->getLocale($request);

        switch ($action) {
            case 'restore':
                $document = $this->getDocumentManager()->find($uuid, $language);
                $this->getDocumentManager()->restore(
                    $document,
                    $language,
                    str_replace('_', '.', $version)
                );
                $this->getDocumentManager()->flush();

                $data = $this->getDocumentManager()->find($uuid, $language);
                break;
        }

        $view = $this->view($data, null !== $data ? 200 : 204);

        $context = new Context();
        $context->setGroups(['defaultPage']);

        return $this->handleView($view->setContext($context));
    }
197057
public function setUUid($uuid = null)
    {
        $notAllowedNames = [
            ListRepositoryInterface::CHUNK,
            ListRepositoryInterface::HEADERS,
            ListRepositoryInterface::INDEX,
            ListRepositoryInterface::SEPARATOR,
            ListRepositoryInterface::STATISTICS,
        ];

        foreach ($notAllowedNames as $notAllowedName) {
            if (strpos($uuid, $notAllowedName) !== false) {
                throw new ListElementNotAllowedUuidException('You can\'t assign "'.$uuid.'" as element uuid.');
            }
        }

        $this->uuid = str_replace(' ', '-', $uuid) ?: Uuid::uuid4()->toString();
    }
371607
public function sendActivationMail($user)
    {
        if( ! $this->shouldSend($user) ) {
            return trans('HCACL::users.activation.check_email');
        }

        \DB::beginTransaction();

        try {
            $token = $this->createActivation($user);

            $user->sendActivationLinkNotification($token);
        } catch ( \Exception $e ) {
            \DB::rollback();

            throw new \Exception('Activation code or mail sending failed');
        }

        \DB::commit();

        return trans('HCACL::users.activation.resent_activation');
    }
54815
function user_activate($username) {
        $extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);

        $ldapconnection = $this->ldap_connect();

        $userdn = $this->ldap_find_userdn($ldapconnection, $extusername);
        switch ($this->config->user_type)  {
            case 'edir':
                $newinfo['loginDisabled'] = 'FALSE';
                break;
            case 'rfc2307':
            case 'rfc2307bis':
                // Remember that we add a '*' character in front of the
                // external password string to 'disable' the account. We just
                // need to remove it.
                $sr = ldap_read($ldapconnection, $userdn, '(objectClass=*)',
                                array('userPassword'));
                $info = ldap_get_entries($ldapconnection, $sr);
                $info[0] = array_change_key_case($info[0], CASE_LOWER);
                $newinfo['userPassword'] = ltrim($info[0]['userpassword'][0], '*');
                break;
            case 'ad':
                // We need to unset the ACCOUNTDISABLE bit in the
                // userAccountControl attribute ( see
                // http://support.microsoft.com/kb/305144 )
                $sr = ldap_read($ldapconnection, $userdn, '(objectClass=*)',
                                array('userAccountControl'));
                $info = ldap_get_entries($ldapconnection, $sr);
                $info[0] = array_change_key_case($info[0], CASE_LOWER);
                $newinfo['userAccountControl'] = $info[0]['useraccountcontrol'][0]
                                                 & (~AUTH_AD_ACCOUNTDISABLE);
                break;
            default:
                print_error('user_activatenotsupportusertype', 'auth_ldap', '', $this->config->user_type_name);
        }
        $result = ldap_modify($ldapconnection, $userdn, $newinfo);
        $this->ldap_close();
        return $result;
    }
712023
public function get(Uuid $uuid)
    {
        if (!isset($this->map[$uuid->toString()])) {
            throw new OutOfBoundsException(sprintf(
                'The binding with UUID "%s" does not exist.',
                $uuid->toString()
            ));
        }

        return $this->map[$uuid->toString()];
    }
879974
public function activationAction($uuid) {
        $request = $this->container->get('request');
        if ($this->container->get('haven_security.user_registration_manager')->activate($uuid)) {
            $this->container->get('session')->getFlashBag()->add("success", "activation.reussi");
        } else {
            throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException("page.pas.trouve");
        }

//        $templating = $this->container->get("templating");
        return new \Symfony\Component\HttpFoundation\RedirectResponse($this->container->get("router")->generate("haven_security_login_login", array("_locale" => $request->get("_locale"))));
    }
825015
public function activate_confirm($pThemeID, $token)
    {
        $l = Theme::getByID($pThemeID);
        $val = Loader::helper('validation/error');
        $valt = Loader::helper('validation/token');
        if (!$valt->validate('activate', $token)) {
            $val->add($valt->getErrorMessage());
            $this->set('error', $val);
        } elseif (!is_object($l)) {
            $val->add('Invalid Theme');
            $this->set('error', $val);
        } else {
            $l->applyToSite();
            $this->redirect('/dashboard/pages/themes/inspect', $l->getThemeID(), 'activate');
        }
        $this->view();
    }
181628
public function deleteUserForced($uid)
    {
        $return['error'] = true;

        $query = "DELETE FROM {$this->config->table_users} WHERE id = :uid";
        $query_prepared = $this->dbh->prepare($query);

        if (!$query_prepared->execute(['uid' => $uid])) {
            $return['message'] = $this->__lang("system_error") . " #05";

            return $return;
        }

        $query = "DELETE FROM {$this->config->table_sessions} WHERE uid = :uid";
        $query_prepared = $this->dbh->prepare($query);

        if (!$query_prepared->execute(['uid' => $uid])) {
            $return['message'] = $this->__lang("system_error") . " #06";

            return $return;
        }

        $query = "DELETE FROM {$this->config->table_requests} WHERE uid = :uid";
        $query_prepared = $this->dbh->prepare($query);

        if (!$query_prepared->execute(['uid' => $uid])) {
            $return['message'] = $this->__lang("system_error") . " #07";

            return $return;
        }

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

        return $return;
    }
1212360
public static function getByUuid(string $uuid): ?WebhookEvent
    {
        $event = WebhookEvent::get("/webhook-events/:uuid", [ "uuid" => $uuid ])->first();

        /** @var WebhookEvent $event */
        return $event;
    }
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'));
    }
728579
public function showActivation(string $token)
    {
        $message = null;

        $tokenRecord = DB::table('hc_users_activations')->where('token', $token)->first();

        if( is_null($tokenRecord) ) {
            $message = trans('HCACL::users.activation.token_not_exists');
        } else {
            if( strtotime($tokenRecord->created_at) + 60 * 60 * 24 < time() ) {
                $message = trans('HCACL::users.activation.token_expired');
            }
        }

        return hcview('HCACL::auth.activation', ['token' => $token, 'message' => $message]);
    }
1193252
public function start($uuid)
    {
        if ($uuid instanceof Service) {
            $uuid = $uuid->getUuid();
        }

        $response = $this->httpClient->post(
            $this->getResourceUrl($uuid) . 'start/',
            []
        );

        return ServiceResponse::createFromHttpResponse($response);
    }
239979
public function byUuid(AggregateUuid $uuid, $returnType = self::RETURN_AS_ARRAY)
    {
        $uuid = (string) $uuid;
        $query = 'SELECT
                  `uuid`,
                  `version`,
                  `payload`,
                  `type`,
                  `body`,
                  `occurred_on`
                FROM `'.PdoDriver::EVENTSTORE_TABLE_NAME.'` 
                WHERE `uuid` = :uuid
                ORDER BY `occurred_on` ASC';
        $stmt = $this->pdo->prepare($query);
        $stmt->bindParam(':uuid', $uuid);
        $stmt->execute();

        $row = $stmt->fetchAll(\PDO::FETCH_ASSOC);

        if (!empty($row)) {
            return $this->buildEventAggregate($row, $returnType);
        }

        return null;
    }
1088814
public function getSelection($uuid)
    {
        foreach ($this->selections as $selection) {
            if ($selection->getUuid() === $uuid) {
                return $selection;
            }
        }
    }
120531
protected function addRequest($uid, $email, $type, &$use_email_activation)
    {
        $return['error'] = true;

        $dictionary_key__request_exists = '';

        if ($type == 'activation') {

            $dictionary_key__request_exists = 'activation_exists';

        } elseif ($type == 'reset') {

            $dictionary_key__request_exists = 'reset_exists';

        } else {
            $return['message'] = $this->__lang("system_error") . " #08";

            return $return;
        }

        $send_email = true;

        // if not set up manually, check config data
        if (false !== $use_email_activation) {
            $use_email_activation = true;

            if ($type == "reset" && !! $this->config->emailmessage_suppress_reset) {
	            $send_email = false;
            }

            if ($type == "activation" && !! $this->config->emailmessage_suppress_activation) {
	            $send_email = false;
            }
        }

        $query = "SELECT id, expire FROM {$this->config->table_requests} WHERE uid = :uid AND type = :type";
        $query_prepared = $this->dbh->prepare($query);
        $query_prepared->execute(['uid' => $uid, 'type' => $type]);

        $row_count = $query_prepared->rowCount();

        if ($row_count > 0) {

            $row = $query_prepared->fetch(\PDO::FETCH_ASSOC);

            $expiredate  = strtotime($row['expire']);
            $currentdate = strtotime(date("Y-m-d H:i:s"));

            if ($currentdate < $expiredate) {
                $return['message'] = $this->__lang($dictionary_key__request_exists, date("Y-m-d H:i:s", $expiredate));
                return $return;
            }

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

        /*// uneffective call. And, never be called, 'cause "Activation key is incorrect." throwen before
        if ($type == "activation" && $this->getBaseUser($uid)['isactive'] == 1) {
            $return['message'] = $this->__lang("already_activated");

            return $return;
        }
        */

        $token = $this->getRandomKey(self::TOKEN_LENGTH); // use GUID for tokens?
        $expire = date("Y-m-d H:i:s", strtotime($this->config->request_key_expiration));

        $query = "INSERT INTO {$this->config->table_requests} (uid, token, expire, type) VALUES (:uid, :token, :expire, :type)";
        $query_prepared = $this->dbh->prepare($query);

        $query_params = [
            'uid' => $uid,
            'token' => $token,
            'expire' => $expire,
            'type' => $type
        ];

        if (!$query_prepared->execute($query_params)) {
            $return['message'] = $this->__lang("system_error") . " #09";

            return $return;
        }

        $request_id = $this->dbh->lastInsertId();

        if ($use_email_activation === true && $send_email) {
            $sendmail_status = $this->do_SendMail($email, $type, $token);

            if ($sendmail_status['error']) {
                $this->deleteRequest($request_id);

                $return['message'] = $this->__lang("system_error") . ' ' . $sendmail_status['message'] . " #10";
                return $return;
            }
        }

        $return['error'] = false;

        return $return;
    }