/**
  * @param  array $data
  *
  * @return \Platform\User\Model\User
  */
 public function addUser($data)
 {
     $data = array_merge($data, ['created_at' => KENDO_DATE_TIME, 'modified_at' => KENDO_DATE_TIME]);
     if (empty($data['profile_name'])) {
         $data['profile_name'] = uniqid();
     }
     $data['role_id'] = $this->getDefaultRoleId();
     $user = new User($data);
     $user->save();
     if (!$user instanceof User) {
         throw new \InvalidArgumentException("Could not create user");
     }
     $password = null;
     if (!empty($data['password'])) {
         $password = (string) $data['password'];
     } else {
         $password = uniqid();
     }
     $this->setPassword($user->getId(), $password);
     if (!empty($data['remote_uid']) && !empty($data['remote_service'])) {
         $this->addRemoteUser($user, $data['remote_uid'], $data['remote_service']);
     }
     app()->emitter()->emit('onCompleteCreatePoster', ['poster' => $user, 'data' => $data]);
     return $user;
 }
Example #2
0
 /**
  * @param \Platform\User\Model\User $user
  *
  * @return $this
  */
 public function setUser($user)
 {
     if (empty($user)) {
         $this->user = null;
     } else {
         if ($user instanceof User) {
             $this->user = $user;
         } else {
             $this->user = null;
         }
     }
     if (false == $this->user->getActive()) {
         if (!$user->getVerified()) {
             $this->setResult(self::UNVERIFIED);
         } else {
             if (!$user->getApproved()) {
                 $this->setResult(self::UNAPPROVED);
             } else {
                 $this->setResult(self::DISABLED);
             }
         }
     }
     return $this;
 }
 /**
  * @return int|null|string
  */
 public function getUserId()
 {
     return null != $this->user ? $this->user->getId() : 0;
 }