public function getFromUser(User $user, $type = null)
 {
     $where = array('u_id' => $user->getId());
     if ($type) {
         $where['ud_type'] = $type;
     }
     $query = Query::select('neuron_users_deligated', array('*'), $where);
     return $this->getObjectsFromData($query->execute());
 }
 /**
  * @param DeligatedUser $deligatedUser
  * @param $email
  * @param $username
  * @return bool|string
  * @throws ExpectedType
  * @throws \Neuron\Exceptions\InvalidParameter
  */
 private function processRegister(DeligatedUser $deligatedUser, $email, $username)
 {
     $mapper = \Neuron\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 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 = $mapper->create($user);
     // Link the deligated user to this user.
     $deligatedUser->setUser($user);
     MapperFactory::getDeligatedMapper()->update($deligatedUser);
     if ($user) {
         return $this->module->register($this->request, $user);
     } else {
         return $mapper->getError();
     }
 }
Esempio n. 3
0
 /**
  * @param User $user
  * @throws InvalidParameter
  * @return \CatLab\Accounts\Models\User
  */
 public function create(User $user)
 {
     // Check for duplicate
     if ($this->getFromEmail($user->getEmail())) {
         throw new InvalidParameter("A user with this email address already exists.");
     }
     $data = $this->prepareFields($user);
     // Insert
     $id = Query::insert($this->table_users, $data)->execute();
     $user->setId($id);
     return $user;
 }
Esempio n. 4
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();
     }
 }
Esempio n. 5
0
 /**
  * Login a specific user
  * @param Request $request
  * @param User $user
  * @param bool $registration
  * @return \Neuron\Net\Response
  */
 public function login(Request $request, User $user, $registration = false)
 {
     // Check for email validation
     if ($this->requiresEmailValidation()) {
         if (!$user->isEmailVerified()) {
             $request->getSession()->set('catlab-non-verified-user-id', $user->getId());
             return Response::redirect(URLBuilder::getURL($this->routepath . '/notverified'));
         }
     }
     $request->getSession()->set('catlab-user-id', $user->getId());
     return $this->postLogin($request, $user, $registration);
 }