/**
  * Set user from session
  * @param Request $request
  */
 public function setRequestUser(Request $request)
 {
     $request->addUserCallback('accounts', function (Request $request) {
         $userid = $request->getSession()->get('catlab-user-id');
         if ($userid) {
             $user = MapperFactory::getUserMapper()->getFromId($userid);
             ExpectedType::check($user, User::class);
             if ($user) {
                 if ($accessToken = $request->getSession()->get('catlab-openid-access-token')) {
                     $user->setAccessToken($accessToken);
                 }
                 return $user;
             }
         }
         return null;
     });
 }
Пример #2
0
function doSomething(Foo $obj)
{
    \Neuron\Exceptions\ExpectedType::check($obj, Foo::class);
    $obj->doSomething();
}
Пример #3
0
 /**
  * @param $email
  * @param $username
  * @param $password
  * @return bool|string
  * @throws \Neuron\Exceptions\InvalidParameter
  */
 private function processRegister($email, $username, $password)
 {
     $mapper = MapperFactory::getUserMapper();
     ExpectedType::check($mapper, UserMapper::class);
     // Check email invalid
     if (!$email) {
         return 'EMAIL_INVALID';
     }
     // Check username input
     if (!$username) {
         return 'USERNAME_INVALID';
     }
     // Check if password is good
     if (!Tools::checkInput($password, 'password')) {
         return 'PASSWORD_INVALID';
     }
     // Check if email is unique
     $user = $mapper->getFromEmail($email);
     if ($user) {
         return 'EMAIL_DUPLICATE';
     }
     // Check if username is unique
     $user = $mapper->getFromUsername($username);
     if ($user) {
         return 'USERNAME_DUPLICATE';
     }
     // Create the user
     $user = new User();
     $user->setEmail($email);
     $user->setUsername($username);
     $user->setPassword($password);
     $user = $mapper->create($user);
     if ($user) {
         return $this->module->register($this->request, $user);
     } else {
         return $mapper->getError();
     }
 }
Пример #4
0
 public function setUserMapper()
 {
     try {
         $mapper = MapperFactory::getUserMapper();
         ExpectedType::check($mapper, UserMapper::class);
     } catch (DataNotSet $e) {
         MapperFactory::getInstance()->setMapper('user', new UserMapper());
     }
 }
 /**
  * Return an error (string) or redirect
  * @param DeligatedUser $deligatedUser
  * @param $email
  * @param $password
  * @return Response|string
  * @throws ExpectedType
  */
 private function processLogin(DeligatedUser $deligatedUser, $email, $password)
 {
     $mapper = \Neuron\MapperFactory::getUserMapper();
     ExpectedType::check($mapper, UserMapper::class);
     $user = $mapper->getFromLogin($email, $password);
     if ($user) {
         // Everything okay
         // Link the deligated user to this user.
         $deligatedUser->setUser($user);
         MapperFactory::getDeligatedMapper()->update($deligatedUser);
         return $this->module->login($this->request, $user);
     } else {
         // Check if we have this email address
         $user = $mapper->getFromEmail($email);
         if ($user) {
             return 'PASSWORD_INCORRECT';
         } else {
             return 'USER_NOT_FOUND';
         }
     }
 }
 private function touchUser($accessToken, $userdetails)
 {
     $mapper = MapperFactory::getUserMapper();
     ExpectedType::check($mapper, UserMapper::class);
     $user = $mapper->getFromSubject($userdetails['id']);
     if (!$user) {
         // First check by email
         $user = $mapper->getFromEmail($userdetails['email']);
         if (!$user) {
             // Create!
             $user = $mapper->getModelInstance();
             $user->setEmail($userdetails['email']);
             $mapper->create($user);
         }
         $user->setSub($userdetails['id']);
     }
     $user->mergeFromInput($userdetails);
     $user->setAccessToken($accessToken);
     $mapper->update($user);
     return $user;
 }