Ejemplo n.º 1
0
 /**
  * @param ReadableUser $user
  * @return int
  * @throws InsertUserException
  * @throws \Exception
  * @throws \mtoolkit\entity\model\role\exception\InsertRoleException
  */
 public function save(ReadableUser $user)
 {
     $sql = "CALL mt_user_save(?, ?, ?, ?, ?, ?, ?, ?);";
     $query = new MPDOQuery($sql, $this->connection);
     // $query->bindValue($user->getId());
     $query->bindValue($user->getEmail());
     $query->bindValue($user->getPassword());
     $query->bindValue($user->getPhoneNumber());
     $query->bindValue((int) $user->isTwoFactorEnabled());
     $query->bindValue($user->getEnabledDate()->format("Y-m-d H:i:s"));
     $query->bindValue((int) $user->isEnabled());
     $query->bindValue($user->getAccessFailedCount());
     $query->bindValue($user->getUserName());
     $queryResult = $query->exec();
     if ($queryResult == false) {
         throw new InsertUserException($query->getLastError()->getDriverText());
     }
     $result = $query->getResult();
     $id = (int) $result[0]["id"];
     for ($k = 0; $k < count($user->getRoleList()); $k++) {
         $role = $user->getRoleList()[$k];
         $this->roleBook->saveRole($id, $role);
     }
     for ($k = 0; $k < count($user->getProviderUserList()); $k++) {
         $providerUser = $user->getProviderUserList()[$k];
         $this->providerUserBook->save($id, $providerUser);
     }
     return (int) $id;
 }
Ejemplo n.º 2
0
 /**
  * @param User $user
  * @param \PDO|null $connection
  * @return User
  * @throws InsertUserException
  * @throws \Exception
  */
 public function save(User $user, \PDO $connection = null)
 {
     $sql = "CALL mentity_user_save(?, ?, ?, ?, ?, ?, ?, ?);";
     $query = new MPDOQuery($sql, $connection);
     $query->bindValue($user->getId());
     $query->bindValue($user->getEmail());
     $query->bindValue($user->getPassword());
     $query->bindValue($user->getPhoneNumber());
     $query->bindValue($user->isTwoFactorEnabled());
     $query->bindValue($user->getLockoutEndDateUtc());
     $query->bindValue($user->isLockoutEnabled());
     $query->bindValue($user->getAccessFailedCount());
     $queryResult = $query->exec();
     if ($queryResult == false) {
         throw new InsertUserException($query->getLastError());
     }
     $result = $query->getResult();
     $id = $result[0]["id"];
     $user->setId($id);
     for ($k = 0; $k < count($user->getRoleList()); $k++) {
         $role = $user->getRoleList()[$k];
         $user->getRoleList()[$k] = RoleBook::saveRole($id, $role);
     }
     for ($k = 0; $k < count($user->getUserLoginsList()); $k++) {
         $role = $user->getUserLoginsList()[$k];
         $user->getRoleList()[$k] = RoleBook::saveLoginsList($id, $role);
     }
     return $user;
 }
Ejemplo n.º 3
0
 /**
  * @param int $userId
  * @param Role $role
  * @param \PDO|null $connection
  * @return Role
  * @throws InsertRoleException
  * @throws \Exception
  */
 public static function saveRole($userId, Role $role, \PDO $connection = null)
 {
     $role = self::save($role);
     $sql = "CALL mentity_user_save_role(?,?);";
     $query = new MPDOQuery($sql, $connection);
     $query->bindValue($userId, $role->getId());
     $queryResult = $query->exec();
     if ($queryResult == false) {
         throw new InsertRoleException($query->getLastError());
     }
     return $role;
 }
Ejemplo n.º 4
0
 /**
  * @param $userId
  * @param Provider $userLogins
  * @param \PDO|null $connection
  * @return Provider
  * @throws InsertProviderException
  * @throws \Exception
  */
 public static function saveUserLogins($userId, Provider $userLogins, \PDO $connection = null)
 {
     $userLogins = self::save($userLogins);
     $sql = "CALL mentity_user_save_provider(?,?);";
     $query = new MPDOQuery($sql, $connection);
     $query->bindValue($userId, $userLogins->getId());
     $queryResult = $query->exec();
     if ($queryResult == false) {
         throw new InsertProviderException($query->getLastError());
     }
     return $userLogins;
 }
Ejemplo n.º 5
0
 public function delete($userId = null, $providerId = null, $providerUserId = null)
 {
     MDataType::mustBeNullableInt($userId);
     MDataType::mustBeNullableInt($providerId);
     MDataType::mustBeNullableString($providerUserId);
     $sql = "CALL mt_provider_user_delete(?,?, ?);";
     $query = new MPDOQuery($sql, $this->connection);
     $query->bindValue($userId);
     $query->bindValue($providerId);
     $query->bindValue($providerUserId);
     $queryResult = $query->exec();
     if ($queryResult == false) {
         throw new DeleteProviderException($query->getLastError());
     }
 }
Ejemplo n.º 6
0
 /**
  * @param ReadableProviderInfo $provider
  * @return int Provider id
  * @throws InsertProviderException
  * @throws \Exception
  */
 public function save(ReadableProviderInfo $provider)
 {
     $sql = "CALL mt_provider_save(?, ?, ?);";
     $query = new MPDOQuery($sql, $this->connection);
     $query->bindValue($provider->getName());
     $query->bindValue($provider->getAppKey());
     $query->bindValue($provider->getSecretKey());
     $queryResult = $query->exec();
     if ($queryResult == false) {
         throw new InsertProviderException($query->getLastError()->getDriverText());
     }
     $result = $query->getResult();
     $id = $result[0]["id"];
     return (int) $id;
 }
Ejemplo n.º 7
0
 /**
  * @param int $userId
  * @param ReadableRole $role
  * @return Role
  * @throws InsertRoleException
  * @throws \Exception
  */
 public function saveRole($userId, ReadableRole $role)
 {
     MDataType::mustBeInt($userId);
     $id = (int) $this->save($role);
     $sql = "CALL mt_user_save_role(?,?);";
     $query = new MPDOQuery($sql, $this->connection);
     $query->bindValue($userId);
     $query->bindValue($id);
     $queryResult = $query->exec();
     if ($queryResult == false) {
         throw new InsertRoleException($query->getLastError());
     }
 }