/** * @param $data * @return Email */ protected function getObjectFromData($data) { $email = new Email(intval($data['ue_id'])); $email->setUser(MapperFactory::getUserMapper()->getFromId($data['u_id'])); $email->setEmail($data['ue_email']); $email->setVerified($data['ue_verified'] == 1); $email->setToken($data['ue_token']); $email->setExpires(new DateTime($data['ue_expires'])); return $email; }
public function setRequestUser(\Neuron\Net\Request $request) { $request->addUserCallback('oauth2', function (\Neuron\Net\Request $request) { if (Verifier::isValid($request)) { $userid = Verifier::getUserId(); $user = \Neuron\MapperFactory::getUserMapper()->getFromId($userid); if ($user) { return $user; } } return null; }); }
/** * @return string */ public function helper() { $request = Application::getInstance()->getRouter()->getRequest(); $user = $request->getUser(); if (!$user) { // The helper should also check for non verified users. $userId = $request->getSession()->get('catlab-non-verified-user-id'); if ($userId) { $user = MapperFactory::getUserMapper()->getFromId($userId); } } if ($user) { $template = new Template('CatLab/Accounts/helpers/welcome.phpt'); $template->set('user', $user); $template->set('logout', URLBuilder::getURL($this->moduleController->getRoutePath() . '/logout')); return $template; } else { $template = new Template('CatLab/Accounts/helpers/form-small.phpt'); $authenticators = $this->moduleController->getAuthenticators(); $authenticators->setRequest($request); $template->set('authenticators', $authenticators); return $template; } }
protected function getObjectFromData($data) { $deligatedUser = new DeligatedUser(); $deligatedUser->setId(intval($data['ud_id'])); $deligatedUser->setType($data['ud_type']); $deligatedUser->setUniqueId($data['ud_unique_id']); if ($data['ud_name']) { $deligatedUser->setName($data['ud_name']); } if ($data['ud_access_token']) { $deligatedUser->setAccessToken($data['ud_access_token']); } if ($data['ud_gender']) { $deligatedUser->setGender($data['ud_gender']); } if ($data['ud_email']) { $deligatedUser->setEmail($data['ud_email']); } if ($data['ud_birthday']) { $deligatedUser->setBirthday(new Carbon($data['ud_birthday'])); } if ($data['ud_locale']) { $deligatedUser->setLocale($data['ud_locale']); } if ($data['ud_avatar']) { $deligatedUser->setAvatar($data['ud_avatar']); } if ($data['ud_firstname']) { $deligatedUser->setFirstname($data['ud_firstname']); } if ($data['ud_lastname']) { $deligatedUser->setLastname($data['ud_lastname']); } if ($data['u_id']) { $user = \Neuron\MapperFactory::getUserMapper()->getFromId($data['u_id']); if ($user) { $deligatedUser->setUser($user); } } $deligatedUser->setCreatedAt(strtotime($data['created_at'])); $deligatedUser->setUpdatedAt(strtotime($data['updated_at'])); return $deligatedUser; }
/** * @return Response */ public function requiresVerification() { $user = null; $userId = $this->request->getSession()->get('catlab-non-verified-user-id'); if ($userId) { $user = \Neuron\MapperFactory::getUserMapper()->getFromId($userId); } if (!$user || !$user instanceof User) { return Response::error('You are not logged in.'); } if ($user->isEmailVerified()) { return $this->module->login($this->request, $user); } $template = new Template('CatLab/Accounts/notverified.phpt'); // Send verification. if ($this->request->input('retry')) { $user->sendVerificationEmail($this->module); } $template->set('layout', $this->module->getLayout()); $template->set('user', $user); $template->set('resend_url', URLBuilder::getURL($this->module->getRoutePath() . '/notverified', array('retry' => 1))); return Response::template($template); }
/** * 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; }); }
/** * @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(); } }
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; }