How to use setNamespace in multiple authentication?

Notice: This thread is very old.
netteman
Member | 126
+
0
-

Hi all,

I want to be able to tell between users who logged into my Admin module and users who logged into the Front module.

I added this code to the SignInFormFactory

$this->user->getStorage()->setNamespace('backend');
\Tracy\Debugger::barDump($this->user);
		$form->onSuccess[] = function (Form $form, $values) use ($onSuccess) {
			try {
				$this->user->setExpiration($values->remember ? '14 days' : '20 minutes');
				$this->user->login($values->username, $values->password);

				//MY CODE
				$this->user->getStorage()->setNamespace('backend');
\Tracy\Debugger::barDump($this->user);
				//MY CODE

			} catch (Nette\Security\AuthenticationException $e) {
				$form->addError('The username or password you entered is incorrect.');
				return;
			}
			$onSuccess();
		};

When I dump $this->user the namespace is set to ‘backend’ but when I dump the logged user elsewhere, the namespace is set back to ''.

Could you tell me how to use the setNamespace to differentiate between logged users?

Thanks :)

David Matějka
Moderator | 6445
+
0
-

you have to set the namespace in your base presenter for backend (e.g. in startup) – so the setNamespace method will be called in every request

netteman
Member | 126
+
0
-

And how does it help to differentiate between users when I'm setting the namespace every time instead of checking the namespace every time?

CZechBoY
Member | 3608
+
0
-

Checking? You set application to choose user from XXX namespace. Then you can check whether is user logged or not.

netteman
Member | 126
+
0
-

Thanks for your help. In the end I decided to use information from database to mark user as allowed in my admin module.