/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($this->scenario == self::SCENARIO_EDIT) { $managerGuids = explode(",", $this->managerGuids); foreach ($managerGuids as $managerGuid) { // Ensure guids valid characters $managerGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $managerGuid); // Try to load user and get/create the GroupUser relation with isManager $user = \humhub\modules\user\models\User::findOne(['guid' => $managerGuid]); if ($user != null) { $groupUser = GroupUser::findOne(['group_id' => $this->id, 'user_id' => $user->id]); if ($groupUser != null && !$groupUser->is_group_manager) { $groupUser->is_group_manager = true; $groupUser->save(); } else { $this->addUser($user, true); } } } //Remove admins not contained in the selection foreach ($this->getManager()->all() as $admin) { if (!in_array($admin->guid, $managerGuids)) { $groupUser = GroupUser::findOne(['group_id' => $this->id, 'user_id' => $admin->id]); if ($groupUser != null) { $groupUser->is_group_manager = false; $groupUser->save(); } } } } parent::afterSave($insert, $changedAttributes); }
/** * Edit a karma record */ public function actionEdit() { $id = (int) Yii::$app->request->get('id'); $user = User::findOne(['id' => $id]); $karma = Karma::findOne(['id' => $id]); if ($karma == null) { throw new \yii\web\HttpException(404, "Karma record not found!"); } // Build Form Definition $definition = array(); $definition['elements'] = array(); // Define Form Eleements $definition['elements']['Karma'] = array('type' => 'form', 'title' => 'Karma', 'elements' => array('name' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'points' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 10), 'description' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 1000))); // Get Form Definition $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => 'Save', 'class' => 'btn btn-primary'), 'delete' => array('type' => 'submit', 'label' => 'Delete', 'class' => 'btn btn-danger')); $form = new HForm($definition); $form->models['Karma'] = $karma; if ($form->submitted('save') && $form->validate()) { if ($form->save()) { return $this->redirect(Url::toRoute(['edit', 'id' => $karma->id])); } } if ($form->submitted('delete')) { return $this->redirect(Url::toRoute(['delete', 'id' => $karma->id])); } return $this->render('edit', array('hForm' => $form)); }
/** * Gets a user setting * * @see \humhub\modules\content\components\ContentContainerSettingsManager::get * @param int $userId * @param string $name * @param string $moduleId * @param string $defaultValue * @return string the value */ public static function Get($userId, $name, $moduleId = "", $defaultValue = "") { $user = User::findOne(['id' => $userId]); $value = self::getModule($moduleId)->settings->contentContainer($user)->get($name); if ($value === null) { return $defaultValue; } return $value; }
/** * Returns an list of all friends of a user */ public function actionPopup() { $user = User::findOne(['id' => Yii::$app->request->get('userId')]); if ($user === null) { throw new \yii\web\HttpException(404, 'Could not find user!'); } $query = Friendship::getFriendsQuery($user); $title = '<strong>' . Yii::t('FriendshipModule.base', "Friends") . '</strong>'; return $this->renderAjaxContent(UserListBox::widget(['query' => $query, 'title' => $title])); }
/** * Declines or Deletes Friendship */ public function actionDelete() { $this->forcePostRequest(); $friend = User::findOne(['id' => Yii::$app->request->get('userId')]); if ($friend === null) { throw new \yii\web\HttpException(404, 'User not found!'); } Friendship::cancel(Yii::$app->user->getIdentity(), $friend); return $this->redirect($friend->getUrl()); }
/** * Gets usernameby given guid * * @param string $guid * @return string|null the username */ public static function getUrlByUserGuid($guid) { if (isset(static::$userUrlMap[$guid])) { return static::$userUrlMap[$guid]; } $user = User::findOne(['guid' => $guid]); if ($user !== null) { static::$userUrlMap[$user->guid] = $user->username; return static::$userUrlMap[$user->guid]; } return null; }
public function getUser() { if ($this->user != null) { return $this->user; } $guid = Yii::$app->request->getQuery('uguid'); $this->user = User::findOne(['guid' => $guid]); if ($this->user == null) { throw new HttpException(404, Yii::t('UserModule.behaviors_ProfileControllerBehavior', 'User not found!')); } $this->checkAccess(); return $this->user; }
/** * Returns the user object which is linked against given authClient * * @param ClientInterface $authClient the authClient * @return User the user model or null if not found */ public static function getUserByAuthClient(ClientInterface $authClient) { $attributes = $authClient->getUserAttributes(); if ($authClient instanceof interfaces\PrimaryClient) { /** * @var interfaces\PrimaryClient $authClient */ return User::findOne([$authClient->getUserTableIdAttribute() => $attributes['id'], 'auth_mode' => $authClient->getId()]); } $auth = Auth::find()->where(['source' => $authClient->getId(), 'source_id' => $attributes['id']])->one(); if ($auth !== null) { return $auth->user; } }
/** * Sends this user a new password by E-Mail * */ public function recover() { $user = User::findOne(array('email' => $this->email)); // Switch to users language - if specified if ($user->language !== "") { Yii::$app->language = $user->language; } $token = \humhub\libs\UUID::v4(); Yii::$app->getModule('user')->settings->contentContainer($user)->set('passwordRecoveryToken', $token . '.' . time()); $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword', 'text' => '@humhub/modules/user/views/mails/plaintext/RecoverPassword'], ['user' => $user, 'linkPasswordReset' => Url::to(["/user/password-recovery/reset", 'token' => $token, 'guid' => $user->guid], true)]); $mail->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')]); $mail->setTo($user->email); $mail->setSubject(Yii::t('UserModule.forms_AccountRecoverPasswordForm', 'Password Recovery')); $mail->send(); return true; }
/** * Checks a comma separated list of e-mails which should invited. * E-Mails needs to be valid and not already registered. * * @param string $attribute * @param array $params */ public function checkEmails($attribute, $params) { if ($this->{$attribute} != "") { foreach ($this->getEmails() as $email) { $validator = new \yii\validators\EmailValidator(); if (!$validator->validate($email)) { $this->addError($attribute, Yii::t('UserModule.invite', '{email} is not valid!', array("{email}" => $email))); continue; } if (User::findOne(['email' => $email]) != null) { $this->addError($attribute, Yii::t('UserModule.invite', '{email} is already registered!', array("{email}" => $email))); continue; } } } }
/** * Sends this user a new password by E-Mail * */ public function recover() { $user = User::findOne(array('email' => $this->email)); // Switch to users language - if specified if ($user->language !== "") { Yii::$app->language = $user->language; } $token = \humhub\libs\UUID::v4(); $user->setSetting('passwordRecoveryToken', $token . '.' . time(), 'user'); $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword'], ['user' => $user, 'linkPasswordReset' => Url::to(["/user/auth/reset-password", 'token' => $token, 'guid' => $user->guid], true)]); $mail->setFrom([\humhub\models\Setting::Get('systemEmailAddress', 'mailing') => \humhub\models\Setting::Get('systemEmailName', 'mailing')]); $mail->setTo($user->email); $mail->setSubject(Yii::t('UserModule.forms_AccountRecoverPasswordForm', 'Password Recovery')); $mail->send(); return true; }
/** * Resets users password based on given token */ public function actionReset() { $user = User::findOne(array('guid' => Yii::$app->request->get('guid'))); if ($user === null || !$this->checkPasswordResetToken($user, Yii::$app->request->get('token'))) { throw new HttpException('500', 'It looks like you clicked on an invalid password reset link. Please try again.'); } $model = new Password(); $model->scenario = 'registration'; if ($model->load(Yii::$app->request->post()) && $model->validate()) { Yii::$app->getModule('user')->settings->contentContainer($user)->delete('passwordRecoveryToken'); $model->user_id = $user->id; $model->setPassword($model->newPassword); $model->save(); return $this->render('reset_success'); } return $this->render('reset', array('model' => $model)); }
/** * Form Validator which checks the recipient field * * @param type $attribute * @param type $params */ public function checkRecipient($attribute, $params) { // Check if email field is not empty if ($this->{$attribute} != "") { $recipients = explode(",", $this->{$attribute}); foreach ($recipients as $userGuid) { $userGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $userGuid); // Try load user $user = User::findOne(['guid' => $userGuid]); if ($user != null) { if ($user->id == Yii::$app->user->id) { $this->addError($attribute, Yii::t('MailModule.forms_InviteRecipientForm', "You cannot send a email to yourself!")); } else { $this->recipients[] = $user; } } } } }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($this->scenario == 'edit') { \humhub\modules\user\models\GroupAdmin::deleteAll(['group_id' => $this->id]); $adminUsers = array(); foreach (explode(",", $this->adminGuids) as $adminGuid) { // Ensure guids valid characters $adminGuid = preg_replace("/[^A-Za-z0-9\\-]/", '', $adminGuid); // Try load user $user = \humhub\modules\user\models\User::findOne(['guid' => $adminGuid]); if ($user != null) { $groupAdmin = new GroupAdmin(); $groupAdmin->user_id = $user->id; $groupAdmin->group_id = $this->id; $groupAdmin->save(); } } } parent::afterSave($insert, $changedAttributes); }
public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); foreach (explode(",", $this->assignedUserGuids) as $userGuid) { $f = false; foreach ($this->assignedUsers as $user) { if ($user->guid == trim($userGuid)) { $f = true; } } if ($f == false) { $this->assignUser(User::findOne(['guid' => trim($userGuid)])); } } foreach ($this->assignedUsers as $user) { if (strpos($this->assignedUserGuids, $user->guid) === false) { $this->unassignUser($user); } } }
public function actionDecline() { $user = User::findOne(['id' => (int) Yii::$app->request->get('id')]); if ($user == null) { throw new HttpException(404, Yii::t('AdminModule.controllers_ApprovalController', 'User not found!')); } $model = new ApproveUserForm(); $model->subject = Yii::t('AdminModule.controllers_ApprovalController', 'Account Request for \'{displayName}\' has been declined.', array('{displayName}' => Html::encode($user->displayName))); $model->message = Yii::t('AdminModule.controllers_ApprovalController', 'Hello {displayName},<br><br> your account request has been declined.<br><br> Kind Regards<br> {AdminName}<br><br>', array('{displayName}' => Html::encode($user->displayName), '{AdminName}' => Yii::$app->user->getIdentity()->displayName)); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->send($user->email); $user->delete(); return $this->redirect(['index']); } return $this->render('decline', ['model' => $user, 'approveFormModel' => $model]); }
/** * Parses a given text for mentioned users and creates an mentioning for them. * * @param HActiveRecordContent|HActiveRecordContentAddon $record * @param string $text */ public static function parse($record, $text) { if ($record instanceof ContentActiveRecord || $record instanceof ContentAddonActiveRecord) { preg_replace_callback('@\\@\\-u([\\w\\-]*?)($|\\s|\\.)@', function ($hit) use(&$record) { $user = User::findOne(['guid' => $hit[1]]); if ($user !== null) { // Check the user was already mentioned (e.g. edit) $mention = self::findOne(['object_model' => get_class($record), 'object_id' => $record->getPrimaryKey(), 'user_id' => $user->id]); if ($mention === null) { $mention = new Mentioning(); $mention->object_model = $record->className(); $mention->object_id = $record->getPrimaryKey(); $mention->user_id = $user->id; $mention->save(); $mention->setPolymorphicRelation($record); // Mentioned users automatically follows the content $record->content->getPolymorphicRelation()->follow($user->id); } } }, $text); } else { throw new Exception("Mentioning can only used in HActiveRecordContent or HActiveRecordContentAddon objects!"); } }
public function actionEditManagerRole() { Yii::$app->response->format = 'json'; $this->forcePostRequest(); $group = Group::findOne(Yii::$app->request->post('id')); $value = Yii::$app->request->post('value'); if ($group == null) { throw new \yii\web\HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group not found!')); } else { if ($value == null) { throw new \yii\web\HttpException(400, Yii::t('AdminModule.controllers_GroupController', 'No value found!')); } } $groupUser = $group->getGroupUser(User::findOne(Yii::$app->request->post('userId'))); if ($groupUser == null) { throw new \yii\web\HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group user not found!')); } $groupUser->is_group_manager = $value ? true : false; $groupUser->save(); return []; }
/** * After Save Addons */ public function afterSave($insert, $changedAttributes) { Yii::$app->search->update($this); $user = \humhub\modules\user\models\User::findOne(['id' => $this->created_by]); if ($insert) { // Create new wall record for this space $wall = new Wall(); $wall->object_model = $this->className(); $wall->object_id = $this->id; $wall->save(); $this->wall_id = $wall->id; $this->update(false, ['wall_id']); // Auto add creator as admin $membership = new Membership(); $membership->space_id = $this->id; $membership->user_id = $user->id; $membership->status = Membership::STATUS_MEMBER; $membership->invite_role = 1; $membership->admin_role = 1; $membership->share_role = 1; $membership->save(); $activity = new \humhub\modules\space\activities\Created(); $activity->source = $this; $activity->originator = $user; $activity->create(); } Yii::$app->cache->delete('userSpaces_' . $user->id); return parent::afterSave($insert, $changedAttributes); }
private function iCalParseTmpFile($path) { $user = $container = $this->content->container; $public = false; if ($container instanceof Space) { $public = $container->getDefaultContentVisibility(); $user = User::findOne(['id' => $this->content->user_id]); } Yii::$app->user->setIdentity($user); $config = array("unique_id" => "ical{$this->id}", "filename" => basename($path), "directory" => dirname($path)); $vcalendar = new vcalendar($config); $vcalendar->parse(); while ($event = $vcalendar->getComponent('vevent')) { $dtstart = $event->getProperty("dtstart"); $dtend = $event->getProperty("dtend"); $all_day = !isset($dtstart["hour"]); if ($all_day) { $st = mktime(0, 0, 0, $dtstart['month'], $dtstart['day'], $dtstart['year']); $start_date = date("Y-m-d H:i:s", $st); $end_date = date("Y-m-d H:i:s", mktime(23, 59, 59, $dtend['month'], $dtend['day'] - 1, $dtend['year'])); } else { $st = gmmktime($dtstart['hour'], $dtstart['min'], $dtstart['sec'], $dtstart['month'], $dtstart['day'], $dtstart['year']); $start_date = date('Y-m-d H:i:s', $st); $end_date = date('Y-m-d H:i:s', gmmktime($dtend['hour'], $dtend['min'], $dtend['sec'], $dtend['month'], $dtend['day'], $dtend['year'])); } if (time() - $st > 60 * 60 * 24 * 30 * 2) { continue; } // ignore events older than 2 months $uid = $event->getProperty("uid"); $entry = CalendarEntry::findOne(["external_source_id" => $this->id, "external_uid" => $uid]); if (!$entry) { $entry = new CalendarEntry(['participation_mode' => CalendarEntry::PARTICIPATION_MODE_NONE, 'color' => $this->color, 'external_source_id' => $this->id, 'external_uid' => $uid]); } $entry->content->container = $container; $entry->title = $event->getProperty("summary"); $entry->description = $event->getProperty("description"); $entry->start_datetime = $start_date; $entry->end_datetime = $end_date; $entry->all_day = $all_day; $entry->is_public = $public; $entry->validate(); $entry->save(); } }
/** * Returns the current user of this account * * An administration can also pass a user id via GET parameter to change users * accounts settings. * * @return User the user */ public function getUser() { if (Yii::$app->request->get('userGuid') != '' && Yii::$app->user->getIdentity()->isSystemAdmin()) { $user = User::findOne(['guid' => Yii::$app->request->get('userGuid')]); if ($user === null) { throw new HttpException(404, 'Could not find user!'); } return $user; } return Yii::$app->user->getIdentity(); }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { Yii::$app->search->update($this); $user = \humhub\modules\user\models\User::findOne(['id' => $this->created_by]); if ($insert) { // Auto add creator as admin $membership = new Membership(); $membership->space_id = $this->id; $membership->user_id = $user->id; $membership->status = Membership::STATUS_MEMBER; $membership->group_id = self::USERGROUP_ADMIN; $membership->save(); $activity = new \humhub\modules\space\activities\Created(); $activity->source = $this; $activity->originator = $user; $activity->create(); } Yii::$app->cache->delete('userSpaces_' . $user->id); return parent::afterSave($insert, $changedAttributes); }
/** * Translate guids from users to username * * @param strint $text Contains the complete message * @param boolean $buildAnchors Wrap the username with a link to the profile, if it's true */ public static function translateMentioning($text, $buildAnchors = true) { return preg_replace_callback('@\\@\\-([us])([\\w\\-]*?)($|\\s|\\.|")@', function ($hit) use(&$buildAnchors) { if ($hit[1] == 'u') { $user = \humhub\modules\user\models\User::findOne(['guid' => $hit[2]]); if ($user !== null) { if ($buildAnchors) { return ' <span contenteditable="false"><a href="' . $user->getUrl() . '" target="_self" class="atwho-user" data-user-guid="@-u' . $user->guid . '">@' . Html::encode($user->getDisplayName()) . '</a></span>' . $hit[3]; } return " @" . Html::encode($user->getDisplayName()) . $hit[3]; } } elseif ($hit[1] == 's') { $space = \humhub\modules\space\models\Space::findOne(['guid' => $hit[2]]); if ($space !== null) { if ($buildAnchors) { return ' <span contenteditable="false"><a href="' . $space->getUrl() . '" target="_self" class="atwho-user" data-user-guid="@-s' . $space->guid . '">@' . Html::encode($space->name) . '</a></span>' . $hit[3]; } return " @" . Html::encode($space->name) . $hit[3]; } } return $hit[0]; }, $text); }
/** * Creates the given ContentActiveRecord based on given submitted form information. * * - Automatically assigns ContentContainer * - Access Check * - User Notification / File Uploads * - Reloads Wall after successfull creation or returns error json * * [See guide section](guide:dev-module-stream.md#CreateContentForm) * * @param ContentActiveRecord $record * @return string json */ public static function create(ContentActiveRecord $record) { Yii::$app->response->format = 'json'; // Set Content Container $contentContainer = null; $containerClass = Yii::$app->request->post('containerClass'); $containerGuid = Yii::$app->request->post('containerGuid', ""); if ($containerClass === User::className()) { $contentContainer = User::findOne(['guid' => $containerGuid]); $record->content->visibility = 1; } elseif ($containerClass === Space::className()) { $contentContainer = Space::findOne(['guid' => $containerGuid]); $record->content->visibility = Yii::$app->request->post('visibility'); } $record->content->container = $contentContainer; // Handle Notify User Features of ContentFormWidget // ToDo: Check permissions of user guids $userGuids = Yii::$app->request->post('notifyUserInput'); if ($userGuids != "") { foreach (explode(",", $userGuids) as $guid) { $user = User::findOne(['guid' => trim($guid)]); if ($user) { $record->content->notifyUsersOfNewContent[] = $user; } } } // Store List of attached Files to add them after Save $record->content->attachFileGuidsAfterSave = Yii::$app->request->post('fileList'); if ($record->validate() && $record->save()) { return array('wallEntryId' => $record->content->getFirstWallEntryId()); } return array('errors' => $record->getErrors()); }
private function becomeUser($userName) { $user = User::findOne(['username' => $userName]); Yii::$app->user->switchIdentity($user); }
/** * Updates or creates user by given ldap node * * @param Zend_Ldap_Node $node * @return User User Object */ public function handleLdapUser($node) { $usernameAttribute = Setting::Get('usernameAttribute', 'authentication_ldap'); if ($usernameAttribute == '') { $usernameAttribute = 'sAMAccountName'; } $emailAttribute = Setting::Get('emailAttribute', 'authentication_ldap'); if ($emailAttribute == '') { $emailAttribute = 'mail'; } $username = $node->getAttribute($usernameAttribute, 0); $email = $node->getAttribute($emailAttribute, 0); $guid = $this->binToStrGuid($node->getAttribute('objectGUID', 0)); // Try to load User: $userChanged = false; $user = null; if ($guid != "") { $user = User::findOne(array('guid' => $guid, 'auth_mode' => User::AUTH_MODE_LDAP)); } else { // Fallback use e-mail $user = User::findOne(array('email' => $email, 'auth_mode' => User::AUTH_MODE_LDAP)); } if ($user === null) { $user = new User(); if ($guid != "") { $user->guid = $guid; } $user->status = User::STATUS_ENABLED; $user->auth_mode = User::AUTH_MODE_LDAP; $user->group_id = 1; Yii::info('Create ldap user ' . $username . '!'); } // Update Users Field if ($user->username != $username) { $userChanged = true; $user->username = $username; } if ($user->email != $email) { $userChanged = true; $user->email = $email; } if ($user->validate()) { // Only Save user when something is changed if ($userChanged || $user->isNewRecord) { $user->save(); } // Update Profile Fields foreach (ProfileField::find()->andWhere(['!=', 'ldap_attribute', ''])->all() as $profileField) { $ldapAttribute = $profileField->ldap_attribute; $profileFieldName = $profileField->internal_name; $user->profile->{$profileFieldName} = $node->getAttribute($ldapAttribute, 0); } if ($user->profile->validate() && $user->profile->save()) { $this->trigger(self::EVENT_UPDATE_USER, new ParameterEvent(['user' => $user, 'node' => $node])); } else { Yii::error('Could not create or update ldap user profile! (' . print_r($user->profile->getErrors(), true) . ")"); } } else { Yii::error('Could not create or update ldap user! (' . print_r($user->getErrors(), true) . ")"); } return $user; }
/** * Creates a new Message * and redirects to it. */ public function actionCreate() { $userGuid = Yii::$app->request->get('userGuid'); $model = new CreateMessage(); // Preselect user if userGuid is given if ($userGuid != "") { $user = User::findOne(array('guid' => $userGuid)); if (isset($user)) { $model->recipient = $user->guid; } } if ($model->load(Yii::$app->request->post()) && $model->validate()) { // Create new Message $message = new Message(); $message->title = $model->title; $message->save(); // Attach Message Entry $messageEntry = new MessageEntry(); $messageEntry->message_id = $message->id; $messageEntry->user_id = Yii::$app->user->id; $messageEntry->content = $model->message; $messageEntry->save(); File::attachPrecreated($messageEntry, Yii::$app->request->post('fileUploaderHiddenGuidField')); // Attach also Recipients foreach ($model->getRecipients() as $recipient) { $userMessage = new UserMessage(); $userMessage->message_id = $message->id; $userMessage->user_id = $recipient->id; $userMessage->save(); } // Inform recipients (We need to add all before) foreach ($model->getRecipients() as $recipient) { $message->notify($recipient); } // Attach User Message $userMessage = new UserMessage(); $userMessage->message_id = $message->id; $userMessage->user_id = Yii::$app->user->id; $userMessage->is_originator = 1; $userMessage->last_viewed = new \yii\db\Expression('NOW()'); $userMessage->save(); return $this->htmlRedirect(['index', 'id' => $message->id]); } return $this->renderAjax('create', array('model' => $model)); }
/** * Deletes a user permanently */ public function actionDelete() { $id = (int) Yii::$app->request->get('id'); $doit = (int) Yii::$app->request->get('doit'); $user = User::findOne(['id' => $id]); if ($user == null) { throw new HttpException(404, Yii::t('AdminModule.controllers_UserController', 'User not found!')); } elseif (Yii::$app->user->id == $id) { throw new HttpException(400, Yii::t('AdminModule.controllers_UserController', 'You cannot delete yourself!')); } if ($doit == 2) { $this->forcePostRequest(); foreach (\humhub\modules\space\models\Membership::GetUserSpaces($user->id) as $space) { if ($space->isSpaceOwner($user->id)) { $space->addMember(Yii::$app->user->id); $space->setSpaceOwner(Yii::$app->user->id); } } $user->delete(); return $this->redirect(['/admin/user']); } return $this->render('delete', array('model' => $user)); }
public function getUserByPk($id) { return User::findOne(['id' => $id]); }
/** * Automatically loads the underlying contentContainer (User/Space) by using * the uguid/sguid request parameter * * @return boolean */ public function init() { $spaceGuid = Yii::$app->request->get('sguid', ''); $userGuid = Yii::$app->request->get('uguid', ''); if ($spaceGuid != "") { $this->contentContainer = Space::findOne(['guid' => $spaceGuid]); if ($this->contentContainer == null) { throw new \yii\web\HttpException(404, Yii::t('base', 'Space not found!')); } $this->attachBehavior('SpaceControllerBehavior', array('class' => \humhub\modules\space\behaviors\SpaceController::className(), 'space' => $this->contentContainer)); $this->subLayout = "@humhub/modules/space/views/space/_layout"; } elseif ($userGuid != "") { $this->contentContainer = User::findOne(['guid' => $userGuid]); if ($this->contentContainer == null) { throw new \yii\web\HttpException(404, Yii::t('base', 'User not found!')); } $this->attachBehavior('ProfileControllerBehavior', ['class' => \humhub\modules\user\behaviors\ProfileController::className(), 'user' => $this->contentContainer]); $this->subLayout = "@humhub/modules/user/views/profile/_layout"; } else { throw new \yii\web\HttpException(500, Yii::t('base', 'Could not determine content container!')); } /** * Auto check access rights to this container */ if ($this->contentContainer != null) { if ($this->autoCheckContainerAccess) { $this->checkContainerAccess(); } } if (!$this->checkModuleIsEnabled()) { throw new HttpException(405, Yii::t('base', 'Module is not enabled on this content container!')); } return parent::init(); }