public function performAction()
 {
     try {
         $identity = new Identity();
         $identity->providerUserId = $this->login;
         $identity->providerId = Password::getProvider()->id;
         $identity->meta = Password::getPasswordHash($this->login, $this->password);
         if ($identity->findSaved()) {
             throw new \Exception('Login is already registered');
         }
         $identity->save();
         $user = new User();
         $user->urlName = $this->login;
         $user->save();
         $userIdentity = new UserIdentity();
         $userIdentity->userId = $user->id;
         $userIdentity->identityId = $identity->id;
         $userIdentity->addedAt = TimeMachine::getInstance()->now();
         $userIdentity->save();
         AuthService::getInstance()->signIn($identity);
         Router::redirect($this->io->makeAnchor(Catalog::createState()));
     } catch (\Exception $exception) {
         $this->response->error($exception->getMessage());
         $this->response->addContent(new Form(RegisterReceive::createState($this->io), $this->io));
     }
 }
Beispiel #2
0
 static function setUpColumns($columns)
 {
     $columns->userId = User::columns()->id;
     $columns->identityId = Identity::columns()->id;
     $columns->addedAt = Column::INTEGER + Column::UNSIGNED;
     $columns->priority = Column::INTEGER + Column::SIZE_1B;
 }
Beispiel #3
0
 public static function findIdentity($login, $password)
 {
     $cols = Identity::columns();
     /** @var Identity $identity */
     $identity = Identity::statement()->where('? = ?', $cols->providerId, self::getProvider()->id)->where('? = ?', $cols->providerUserId, $login)->query()->fetchRow();
     if (!$identity) {
         throw new \Exception('Identity not found');
     }
     if ($identity->meta !== self::getPasswordHash($login, $password)) {
         throw new \Exception('Wrong password');
     }
     return $identity;
 }
Beispiel #4
0
 public function signIn(Identity $identity)
 {
     // TODO multi identity login
     $session = new Session();
     $session->identityId = $identity->id;
     $users = $this->getUsersByIdentityId($identity->id);
     if (!$users) {
         // inactive identity
         $identity->delete();
         throw new Exception('Identity without users found, deleted', Exception::IDENTITY_WITHOUT_USERS);
     }
     if (isset($_COOKIE[$this->settings->sessionName])) {
         Session::statement()->delete()->where('? = ?', Session::columns()->token, $_COOKIE[$this->settings->sessionName])->query();
     }
     do {
         $token = $this->createSessionId();
     } while (Session::findByToken($token));
     setcookie($this->settings->sessionName, $token, time() + $this->settings->expireTime, '/', null, null, true);
     $session->identityId = $identity->id;
     $session->token = $token;
     $session->createdAt = TimeMachine::getInstance()->now();
     $session->save();
 }
Beispiel #5
0
 static function setUpColumns($columns)
 {
     $columns->identityId = Identity::columns()->id;
     $columns->token = Column::create(Column::STRING + Column::NOT_NULL)->setStringLength(32, true)->setUnique();
     $columns->createdAt = Column::INTEGER;
 }
 public function getTables()
 {
     /** @var Table[] $tables */
     $tables = array(Identity::table(), IdentityProvider::table(), Session::table(), User::table(), UserIdentity::table(), Album::table(), ExifTag::table(), Image::table(), ImageExif::table());
     return $tables;
 }