/** * @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; }