public function actionAuto() { $this->stdout("Install:\n\n", Console::FG_YELLOW); \humhub\modules\installer\libs\InitialData::bootstrap(); Yii::$app->settings->set('name', "HumHub Test"); Yii::$app->settings->set('mailer.systemEmailName', "*****@*****.**"); Yii::$app->settings->set('mailer.systemEmailName', "*****@*****.**"); Yii::$app->settings->set('secret', \humhub\libs\UUID::v4()); $user = new User(); //$user->group_id = 1; $user->username = "******"; $user->email = '*****@*****.**'; $user->status = User::STATUS_ENABLED; $user->language = ''; $user->last_activity_email = new \yii\db\Expression('NOW()'); if (!$user->save()) { throw new \yii\base\Exception("Could not save user"); } $user->profile->title = "System Administration"; $user->profile->firstname = "John"; $user->profile->lastname = "Doe"; $user->profile->save(); $password = new Password(); $password->user_id = $user->id; $password->setPassword('test'); $password->save(); // Assign to system admin group Group::getAdminGroup()->addUser($user); return self::EXIT_CODE_NORMAL; }
/** * Check if there is a new Humhub Version available and sends a notification * to super admins * * @param \yii\base\Event $event */ public static function onCronDailyRun($event) { $controller = $event->sender; if (!Yii::$app->getModule('admin')->dailyCheckForNewVersion) { return; } if (!Yii::$app->params['humhub']['apiEnabled']) { return; } $controller->stdout("Checking for new HumHub version... "); $latestVersion = libs\HumHubAPI::getLatestHumHubVersion(); if ($latestVersion != "") { $adminUsers = \humhub\modules\user\models\Group::getAdminGroup()->users; $latestNotifiedVersion = Yii::$app->getModule('admin')->settings->get('lastVersionNotify'); $adminsNotified = !($latestNotifiedVersion == "" || version_compare($latestVersion, $latestNotifiedVersion, ">")); $newVersionAvailable = version_compare($latestVersion, Yii::$app->version, ">"); $updateNotification = new notifications\NewVersionAvailable(); // Cleanup existing notifications if (!$newVersionAvailable || $newVersionAvailable && !$adminsNotified) { foreach ($adminUsers as $admin) { $updateNotification->delete($admin); } } // Create new notification if ($newVersionAvailable && !$adminsNotified) { $updateNotification->sendBulk($adminUsers); Yii::$app->getModule('admin')->settings->set('lastVersionNotify', $latestVersion); } } $controller->stdout('done. ' . PHP_EOL, \yii\helpers\Console::FG_GREEN); }
/** * Get approval groups */ public function getGroups() { if (Yii::$app->user->isAdmin()) { return \humhub\modules\user\models\Group::find()->all(); } else { return Yii::$app->user->getIdentity()->managerGroups; } }
/** * Executes the widgets */ public function run() { $groups = Group::find()->count(); $users = User::find()->count(); $statsAvgMembers = $users / $groups; $statsTopGroup = Group::find()->where('id = (SELECT group_id FROM user GROUP BY group_id ORDER BY count(*) DESC LIMIT 1)')->one(); // Render widgets view return $this->render('groupStats', array('statsTotalGroups' => $groups, 'statsAvgMembers' => round($statsAvgMembers, 1), 'statsTopGroup' => $statsTopGroup, 'statsTotalUsers' => $users)); }
public function init() { $this->addItemGroup(array('id' => 'directory', 'label' => Yii::t('DirectoryModule.views_directory_layout', '<strong>Directory</strong> menu'), 'sortOrder' => 100)); if (Group::find()->count() > 1) { $this->addItem(array('label' => Yii::t('DirectoryModule.views_directory_layout', 'Groups'), 'group' => 'directory', 'url' => Url::to(['/directory/directory/groups']), 'sortOrder' => 100, 'isActive' => Yii::$app->controller->action->id == "groups")); } $this->addItem(array('label' => Yii::t('DirectoryModule.views_directory_layout', 'Members'), 'group' => 'directory', 'url' => Url::to(['/directory/directory/members']), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->action->id == "members")); $this->addItem(array('label' => Yii::t('DirectoryModule.views_directory_layout', 'Spaces'), 'group' => 'directory', 'url' => Url::to(['/directory/directory/spaces']), 'sortOrder' => 300, 'isActive' => Yii::$app->controller->action->id == "spaces")); $this->addItem(array('label' => Yii::t('DirectoryModule.views_directory_layout', 'User profile posts'), 'group' => 'directory', 'url' => Url::to(['/directory/directory/user-posts']), 'sortOrder' => 400, 'isActive' => Yii::$app->controller->action->id == "user-posts")); parent::init(); }
public function actionAdd() { $userModel = new User(); $userModel->scenario = 'registration'; $userPasswordModel = new Password(); $userPasswordModel->scenario = 'registration'; $profileModel = $userModel->profile; $profileModel->scenario = 'registration'; // Build Form Definition $definition = array(); $definition['elements'] = array(); $groupModels = \humhub\modules\user\models\Group::find()->orderBy('name ASC')->all(); $defaultUserGroup = \humhub\models\Setting::Get('defaultUserGroup', 'authentication_internal'); $groupFieldType = "dropdownlist"; if ($defaultUserGroup != "") { $groupFieldType = "hidden"; } else { if (count($groupModels) == 1) { $groupFieldType = "hidden"; $defaultUserGroup = $groupModels[0]->id; } } if ($groupFieldType == 'hidden') { $userModel->group_id = $defaultUserGroup; } // Add User Form $definition['elements']['User'] = array('type' => 'form', 'title' => Yii::t('UserModule.controllers_AuthController', 'Account'), 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => \yii\helpers\ArrayHelper::map($groupModels, 'id', 'name'), 'value' => $defaultUserGroup))); // Add User Password Form $definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255))); // Add Profile Form $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition()); // Get Form Definition $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account'))); $form = new HForm($definition); $form->models['User'] = $userModel; $form->models['UserPassword'] = $userPasswordModel; $form->models['Profile'] = $profileModel; if ($form->submitted('save') && $form->validate()) { $this->forcePostRequest(); $form->models['User']->status = User::STATUS_ENABLED; if ($form->models['User']->save()) { // Save User Profile $form->models['Profile']->user_id = $form->models['User']->id; $form->models['Profile']->save(); // Save User Password $form->models['UserPassword']->user_id = $form->models['User']->id; $form->models['UserPassword']->setPassword($form->models['UserPassword']->newPassword); $form->models['UserPassword']->save(); return $this->redirect(Url::to(['index'])); } } return $this->render('add', array('hForm' => $form)); }
/** * Tests if user automatically added to the group´s default space */ public function testCreateGroupSpaceAdd() { Yii::$app->getModule('user')->settings->set('auth.needApproval', 0); $space = Space::findOne(['id' => 1]); $user = new User(); $user->username = "******"; $user->email = "*****@*****.**"; $this->assertTrue($user->save()); $group = Group::findOne(['id' => 1]); $group->addUser($user); $this->assertTrue($space->isMember($user->id)); }
/** * Get approval groups */ public function getGroups() { if (Yii::$app->user->isAdmin()) { return \humhub\modules\user\models\Group::find()->all(); } else { $groups = []; foreach (\humhub\modules\user\models\GroupAdmin::find()->joinWith('group')->where(['user_id' => Yii::$app->user->id])->all() as $groupAdmin) { if ($groupAdmin->group !== null) { $groups[] = $groupAdmin->group; } } return $groups; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Group::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]); $dataProvider->setSort(['attributes' => ['name', 'descriptions']]); $this->load($params); if (!$this->validate()) { $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', 'name', $this->name]); $query->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Validator for group field during registration */ public function validateGroupId() { if ($this->scenario == static::SCENARIO_REGISTRATION) { if ($this->group_id != '') { $registrationGroups = Group::getRegistrationGroups(); foreach ($registrationGroups as $group) { if ($this->group_id == $group->id) { return; } } // Not found group in groups available during registration $this->addError('group_id', 'Invalid group given!'); } } }
/** * Aligns the given group selection with the db * @return boolean */ public function save() { //Check old group selection and remove non selected groups foreach ($this->currentGroups as $userGroup) { if (!$this->isInGroupSelection($userGroup)) { $this->user->getGroupUsers()->where(['group_id' => $userGroup->id])->one()->delete(); } } //Add all selectedGroups to the given user foreach ($this->groupSelection as $groupId) { if (!$this->isCurrentlyMemberOf($groupId)) { Group::findOne($groupId)->addUser($this->user); } } return true; }
/** * Returns a List of Users */ public function actionIndex() { $form = new \humhub\modules\admin\models\forms\AuthenticationSettingsForm(); if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) { Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved')); } // Build Group Dropdown $groups = []; $groups[''] = Yii::t('AdminModule.controllers_SettingController', 'None - shows dropdown in user registration.'); foreach (\humhub\modules\user\models\Group::find()->all() as $group) { if (!$group->is_admin_group) { $groups[$group->id] = $group->name; } } return $this->render('authentication', array('model' => $form, 'groups' => $groups)); }
/** * Deletes a group * * On deletion all group members will be moved to another group. */ public function actionDelete() { $group = Group::findOne(['id' => Yii::$app->request->get('id')]); if ($group == null) { throw new \yii\web\HttpException(404, Yii::t('AdminModule.controllers_GroupController', 'Group not found!')); } $model = new \humhub\modules\admin\models\forms\AdminDeleteGroupForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { foreach (User::findAll(['group_id' => $group->id]) as $user) { $user->group_id = $model->group_id; $user->save(); } $group->delete(); $this->redirect(Url::toRoute("/admin/group")); } $alternativeGroups = \yii\helpers\ArrayHelper::map(Group::find()->where('id != :id', array(':id' => $group->id))->all(), 'id', 'name'); return $this->render('delete', array('group' => $group, 'model' => $model, 'alternativeGroups' => $alternativeGroups)); }
public function setUpApproved() { $userInvite = Invite::findOne(['email' => $this->email]); if ($userInvite !== null) { // User was invited to a space if ($userInvite->source == Invite::SOURCE_INVITE) { $space = \humhub\modules\space\models\Space::findOne(['id' => $userInvite->space_invite_id]); if ($space != null) { $space->addMember($this->id); } } // Delete/Cleanup Invite Entry $userInvite->delete(); } // Auto Assign User to the Group Space $group = Group::findOne(['id' => $this->group_id]); if ($group != null && $group->space_id != "") { $space = \humhub\modules\space\models\Space::findOne(['id' => $group->space_id]); if ($space !== null) { $space->addMember($this->id); } } // Auto Add User to the default spaces foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) { $space->addMember($this->id); } }
public function testGroupAssignment() { $group2 = new Group(); $group2->name = "TestGrp1"; $group2->description = "test"; $this->assertTrue($group2->save()); \humhub\models\Setting::Set('defaultUserGroup', $group2->id, 'authentication_internal'); $user = new User(); $user->username = "******"; $user->email = "*****@*****.**"; $this->assertTrue($user->save()); $this->assertEquals($user->group_id, $group2->id); }
/** * Group Section of the directory * * Shows a list of all groups in the application. */ public function actionGroups() { $groups = \humhub\modules\user\models\Group::find()->all(); \yii\base\Event::on(Sidebar::className(), Sidebar::EVENT_INIT, function ($event) { $event->sender->addWidget(\humhub\modules\directory\widgets\GroupStatistics::className(), [], ['sortOrder' => 10]); }); return $this->render('groups', array('groups' => $groups)); }
/** * 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 Group Mapping foreach (Group::find()->andWhere(['!=', 'ldap_dn', ""])->all() as $group) { if (in_array($group->ldap_dn, $node->getAttribute('memberOf'))) { if ($user->group_id != $group->id) { $userChanged = true; $user->group_id = $group->id; } } } // 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(); // Update Space Mapping foreach (Space::find()->andWhere(['!=', 'ldap_dn', ''])->all() as $space) { if (in_array($space->ldap_dn, $node->getAttribute('memberOf')) || strpos($node->getDn(), $space->ldap_dn) !== false) { $space->addMember($user->id); } } } 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; }
/** * Declares the validation rules. */ public function rules() { return array(array(['internalUsersCanInvite', 'internalAllowAnonymousRegistration', 'internalRequireApprovalAfterRegistration', 'allowGuestAccess'], 'boolean'), array('defaultUserGroup', 'exist', 'targetAttribute' => 'id', 'targetClass' => \humhub\modules\user\models\Group::className()), array('defaultUserProfileVisibility', 'in', 'range' => [1, 2]), array('defaultUserIdleTimeoutSec', 'integer', 'min' => 20), array('defaultUserIdleTimeoutSec', 'string', 'max' => 10)); }
/** * Returns Password model * * @return Password */ public function getGroupUser() { if ($this->_groupUser === null) { $this->_groupUser = new GroupUser(); $this->_groupUser->scenario = GroupUser::SCENARIO_REGISTRATION; // assign default value for group_id $registrationGroups = \humhub\modules\user\models\Group::getRegistrationGroups(); if (count($registrationGroups) == 1) { $this->_groupUser->group_id = $registrationGroups[0]->id; } } return $this->_groupUser; }
/** * After Save Addons * * @return type */ public function afterSave($insert, $changedAttributes) { // Make sure we get an direct User model instance // (e.g. not UserEditForm) for search rebuild $user = User::findOne(['id' => $this->id]); if ($this->status == User::STATUS_ENABLED) { Yii::$app->search->update($user); } else { Yii::$app->search->delete($user); } if ($insert) { if ($this->status == User::STATUS_ENABLED) { $this->setUpApproved(); } else { Group::notifyAdminsForUserApproval($this); } $this->profile->user_id = $this->id; } if (Yii::$app->user->id == $this->id) { Yii::$app->user->setIdentity($user); } return parent::afterSave($insert, $changedAttributes); }
public function actionAdminUserSearch() { Yii::$app->response->format = 'json'; $keyword = Yii::$app->request->get('keyword'); $group = Group::findOne(Yii::$app->request->get('id')); return UserPicker::filter(['query' => $group->getUsers(), 'keyword' => $keyword, 'fillQuery' => User::find(), 'disableFillUser' => false]); }
/** * Create an account * * This action is called after e-mail validation. */ public function actionCreateAccount() { $needApproval = \humhub\models\Setting::Get('needApproval', 'authentication_internal'); if (!Yii::$app->user->isGuest) { throw new HttpException(401, 'Your are already logged in! - Logout first!'); } $userInvite = Invite::findOne(['token' => Yii::$app->request->get('token')]); if (!$userInvite) { throw new HttpException(404, 'Token not found!'); } if ($userInvite->language) { Yii::$app->language = $userInvite->language; } $userModel = new User(); $userModel->scenario = 'registration'; $userModel->email = $userInvite->email; $userPasswordModel = new Password(); $userPasswordModel->scenario = 'registration'; $profileModel = $userModel->profile; $profileModel->scenario = 'registration'; // Build Form Definition $definition = array(); $definition['elements'] = array(); $groupModels = \humhub\modules\user\models\Group::find()->orderBy('name ASC')->all(); $defaultUserGroup = \humhub\models\Setting::Get('defaultUserGroup', 'authentication_internal'); $groupFieldType = "dropdownlist"; if ($defaultUserGroup != "") { $groupFieldType = "hidden"; } else { if (count($groupModels) == 1) { $groupFieldType = "hidden"; $defaultUserGroup = $groupModels[0]->id; } } if ($groupFieldType == 'hidden') { $userModel->group_id = $defaultUserGroup; } // Add User Form $definition['elements']['User'] = array('type' => 'form', 'title' => Yii::t('UserModule.controllers_AuthController', 'Account'), 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'group_id' => array('type' => $groupFieldType, 'class' => 'form-control', 'items' => \yii\helpers\ArrayHelper::map($groupModels, 'id', 'name'), 'value' => $defaultUserGroup))); // Add User Password Form $definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255))); // Add Profile Form $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition()); // Get Form Definition $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('UserModule.controllers_AuthController', 'Create account'))); $form = new HForm($definition); $form->models['User'] = $userModel; $form->models['UserPassword'] = $userPasswordModel; $form->models['Profile'] = $profileModel; if ($form->submitted('save') && $form->validate()) { $this->forcePostRequest(); // Registe User $form->models['User']->email = $userInvite->email; $form->models['User']->language = Yii::$app->language; if ($form->models['User']->save()) { // Save User Profile $form->models['Profile']->user_id = $form->models['User']->id; $form->models['Profile']->save(); // Save User Password $form->models['UserPassword']->user_id = $form->models['User']->id; $form->models['UserPassword']->setPassword($form->models['UserPassword']->newPassword); $form->models['UserPassword']->save(); // Autologin user if (!$needApproval) { Yii::$app->user->switchIdentity($form->models['User']); return $this->redirect(Url::to(['/dashboard/dashboard'])); } return $this->render('createAccount_success', array('form' => $form, 'needApproval' => $needApproval)); } } return $this->render('createAccount', array('hForm' => $form, 'needAproval' => $needApproval)); }
/** * @inheritdoc */ public function beforeDelete() { foreach (Setting::findAll(['space_id' => $this->id]) as $spaceSetting) { $spaceSetting->delete(); } foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } Yii::$app->search->delete($this); $this->getProfileImage()->delete(); \humhub\modules\user\models\Follow::deleteAll(['object_id' => $this->id, 'object_model' => 'Space']); foreach (Membership::findAll(['space_id' => $this->id]) as $spaceMembership) { $spaceMembership->delete(); } \humhub\modules\user\models\Invite::deleteAll(['space_invite_id' => $this->id]); // When this workspace is used in a group as default workspace, delete the link foreach (\humhub\modules\user\models\Group::findAll(['space_id' => $this->id]) as $group) { $group->space_id = ""; $group->save(); } return parent::beforeDelete(); }
public static function bootstrap() { // Seems database is already initialized if (Setting::Get('paginationSize') == 10) { return; } //Yii::$app->search->rebuild(); Setting::Set('baseUrl', \yii\helpers\BaseUrl::base(true)); Setting::Set('paginationSize', 10); Setting::Set('displayNameFormat', '{profile.firstname} {profile.lastname}'); // Authentication Setting::Set('authInternal', '1', 'authentication'); Setting::Set('authLdap', '0', 'authentication'); Setting::Set('refreshUsers', '1', 'authentication_ldap'); Setting::Set('needApproval', '0', 'authentication_internal'); Setting::Set('anonymousRegistration', '1', 'authentication_internal'); Setting::Set('internalUsersCanInvite', '1', 'authentication_internal'); // Mailing Setting::Set('transportType', 'php', 'mailing'); Setting::Set('systemEmailAddress', '*****@*****.**', 'mailing'); Setting::Set('systemEmailName', 'My Social Network', 'mailing'); Setting::Set('receive_email_activities', User::RECEIVE_EMAIL_DAILY_SUMMARY, 'mailing'); Setting::Set('receive_email_notifications', User::RECEIVE_EMAIL_WHEN_OFFLINE, 'mailing'); // File Setting::Set('maxFileSize', '1048576', 'file'); Setting::Set('maxPreviewImageWidth', '200', 'file'); Setting::Set('maxPreviewImageHeight', '200', 'file'); Setting::Set('hideImageFileInfo', '0', 'file'); // Caching Setting::Set('type', 'CFileCache', 'cache'); Setting::Set('expireTime', '3600', 'cache'); Setting::Set('installationId', md5(uniqid("", true)), 'admin'); // Design Setting::Set('theme', "HumHub"); Setting::Set('spaceOrder', 0, 'space'); // Basic Setting::Set('enable', 1, 'tour'); Setting::Set('defaultLanguage', Yii::$app->language); // Notification Setting::Set('enable_html5_desktop_notifications', 0, 'notification'); // Add Categories $cGeneral = new ProfileFieldCategory(); $cGeneral->title = "General"; $cGeneral->sort_order = 100; $cGeneral->visibility = 1; $cGeneral->is_system = 1; $cGeneral->description = ''; if (!$cGeneral->save()) { throw new Exception(print_r($cGeneral->getErrors(), true)); } $cCommunication = new ProfileFieldCategory(); $cCommunication->title = "Communication"; $cCommunication->sort_order = 200; $cCommunication->visibility = 1; $cCommunication->is_system = 1; $cCommunication->description = ''; $cCommunication->save(); $cSocial = new ProfileFieldCategory(); $cSocial->title = "Social bookmarks"; $cSocial->sort_order = 300; $cSocial->visibility = 1; $cSocial->is_system = 1; $cSocial->description = ''; $cSocial->save(); // Add Fields $field = new ProfileField(); $field->internal_name = "firstname"; $field->title = 'Firstname'; $field->sort_order = 100; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->ldap_attribute = 'givenName'; $field->is_system = 1; $field->required = 1; $field->show_at_registration = 1; if ($field->save()) { $field->fieldType->maxLength = 20; $field->fieldType->save(); } else { throw new Exception(print_r($field->getErrors(), true)); } $field = new ProfileField(); $field->internal_name = "lastname"; $field->title = 'Lastname'; $field->sort_order = 200; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->ldap_attribute = 'sn'; $field->show_at_registration = 1; $field->required = 1; $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 30; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "title"; $field->title = 'Title'; $field->sort_order = 300; $field->ldap_attribute = 'title'; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 50; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "gender"; $field->title = 'Gender'; $field->sort_order = 300; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeSelect'; $field->is_system = 1; if ($field->save()) { $field->fieldType->options = "male=>Male\nfemale=>Female\ncustom=>Custom"; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "street"; $field->title = 'Street'; $field->sort_order = 400; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 150; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "zip"; $field->title = 'Zip'; $field->sort_order = 500; $field->profile_field_category_id = $cGeneral->id; $field->is_system = 1; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); if ($field->save()) { $field->fieldType->maxLength = 10; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "city"; $field->title = 'City'; $field->sort_order = 600; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "country"; $field->title = 'Country'; $field->sort_order = 700; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "state"; $field->title = 'State'; $field->sort_order = 800; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "birthday"; $field->title = 'Birthday'; $field->sort_order = 900; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Birthday::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "about"; $field->title = 'About'; $field->sort_order = 900; $field->profile_field_category_id = $cGeneral->id; $field->field_type_class = 'ProfileFieldTypeTextArea'; $field->is_system = 1; if ($field->save()) { #$field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "phone_private"; $field->title = 'Phone Private'; $field->sort_order = 100; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "phone_work"; $field->title = 'Phone Work'; $field->sort_order = 200; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "mobile"; $field->title = 'Mobile'; $field->sort_order = 300; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "fax"; $field->title = 'Fax'; $field->sort_order = 400; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "im_skype"; $field->title = 'Skype Nickname'; $field->sort_order = 500; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "im_msn"; $field->title = 'MSN'; $field->sort_order = 600; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->maxLength = 100; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "im_icq"; $field->title = 'ICQ Number'; $field->sort_order = 700; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = 'ProfileFieldTypeNumber'; $field->is_system = 1; if ($field->save()) { $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "im_xmpp"; $field->title = 'XMPP Jabber Address'; $field->sort_order = 800; $field->profile_field_category_id = $cCommunication->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'email'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url"; $field->title = 'Url'; $field->sort_order = 100; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_facebook"; $field->title = 'Facebook URL'; $field->sort_order = 200; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_linkedin"; $field->title = 'LinkedIn URL'; $field->sort_order = 300; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_xing"; $field->title = 'Xing URL'; $field->sort_order = 400; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_youtube"; $field->title = 'Youtube URL'; $field->sort_order = 500; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_vimeo"; $field->title = 'Vimeo URL'; $field->sort_order = 600; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_flickr"; $field->title = 'Flickr URL'; $field->sort_order = 700; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_myspace"; $field->title = 'MySpace URL'; $field->sort_order = 800; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_googleplus"; $field->title = 'Google+ URL'; $field->sort_order = 900; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $field = new ProfileField(); $field->internal_name = "url_twitter"; $field->title = 'Twitter URL'; $field->sort_order = 1000; $field->profile_field_category_id = $cSocial->id; $field->field_type_class = \humhub\modules\user\models\fieldtype\Text::className(); $field->is_system = 1; if ($field->save()) { $field->fieldType->validator = 'url'; $field->fieldType->save(); } $group = new Group(); $group->name = "Users"; $group->description = "Example Group by Installer"; $group->save(); }
/** * Returns an id => groupname array representation of the given $groups array. * @param array $groups array of Group models * @return type array in form of id => groupname */ public static function getGroupItems($groups = null) { if ($groups == null) { $groups = \humhub\modules\user\models\Group::find()->all(); } $result = []; foreach ($groups as $group) { $result[$group->id] = $group->name; } return $result; }
/** * Show groups in directory * * @return boolean */ public function isGroupListingEnabled() { return \humhub\modules\user\models\Group::find()->where(['show_at_directory' => 1])->count() > 1; }
/** * Returns a List of Users */ public function actionAuthentication() { $form = new \humhub\modules\admin\models\forms\AuthenticationSettingsForm(); $form->internalUsersCanInvite = Setting::Get('internalUsersCanInvite', 'authentication_internal'); $form->internalRequireApprovalAfterRegistration = Setting::Get('needApproval', 'authentication_internal'); $form->internalAllowAnonymousRegistration = Setting::Get('anonymousRegistration', 'authentication_internal'); $form->defaultUserGroup = Setting::Get('defaultUserGroup', 'authentication_internal'); $form->defaultUserIdleTimeoutSec = Setting::Get('defaultUserIdleTimeoutSec', 'authentication_internal'); $form->allowGuestAccess = Setting::Get('allowGuestAccess', 'authentication_internal'); $form->defaultUserProfileVisibility = Setting::Get('defaultUserProfileVisibility', 'authentication_internal'); if ($form->load(Yii::$app->request->post()) && $form->validate()) { $form->internalUsersCanInvite = Setting::Set('internalUsersCanInvite', $form->internalUsersCanInvite, 'authentication_internal'); $form->internalRequireApprovalAfterRegistration = Setting::Set('needApproval', $form->internalRequireApprovalAfterRegistration, 'authentication_internal'); $form->internalAllowAnonymousRegistration = Setting::Set('anonymousRegistration', $form->internalAllowAnonymousRegistration, 'authentication_internal'); $form->defaultUserGroup = Setting::Set('defaultUserGroup', $form->defaultUserGroup, 'authentication_internal'); $form->defaultUserIdleTimeoutSec = Setting::Set('defaultUserIdleTimeoutSec', $form->defaultUserIdleTimeoutSec, 'authentication_internal'); $form->allowGuestAccess = Setting::Set('allowGuestAccess', $form->allowGuestAccess, 'authentication_internal'); if (Setting::Get('allowGuestAccess', 'authentication_internal')) { $form->defaultUserProfileVisibility = Setting::Set('defaultUserProfileVisibility', $form->defaultUserProfileVisibility, 'authentication_internal'); } // set flash message Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved')); Yii::$app->response->redirect(Url::toRoute('/admin/setting/authentication')); } // Build Group Dropdown $groups = array(); $groups[''] = Yii::t('AdminModule.controllers_SettingController', 'None - shows dropdown in user registration.'); foreach (\humhub\modules\user\models\Group::find()->all() as $group) { $groups[$group->id] = $group->name; } return $this->render('authentication', array('model' => $form, 'groups' => $groups)); }
public function setUpApproved() { $userInvite = Invite::findOne(['email' => $this->email]); if ($userInvite !== null) { // User was invited to a space if ($userInvite->source == Invite::SOURCE_INVITE) { $space = \humhub\modules\space\models\Space::findOne(['id' => $userInvite->space_invite_id]); if ($space != null) { $space->addMember($this->id); } } // Delete/Cleanup Invite Entry $userInvite->delete(); } // Auto Assign User to the Group Space $group = Group::findOne(['id' => $this->group_id]); if ($group != null && $group->space_id != "") { $space = \humhub\modules\space\models\Space::findOne(['id' => $group->space_id]); if ($space !== null) { $space->addMember($this->id); } } // Auto Add User to the default spaces foreach (\humhub\modules\space\models\Space::findAll(['auto_add_new_members' => 1]) as $space) { $space->addMember($this->id); } // Create new wall record for this user $wall = new \humhub\modules\content\models\Wall(); $wall->object_model = $this->className(); $wall->object_id = $this->id; $wall->save(); $this->wall_id = $wall->id; $this->update(false, ['wall_id']); }
/** * After Save Addons * * @return type */ public function afterSave($insert, $changedAttributes) { if ($this->status == User::STATUS_ENABLED) { Yii::$app->search->update($this); } else { Yii::$app->search->delete($this); } if ($insert) { if ($this->status == User::STATUS_ENABLED) { $this->setUpApproved(); } else { Group::notifyAdminsForUserApproval($this); } $this->profile->user_id = $this->id; } if (Yii::$app->user->id == $this->id) { Yii::$app->user->setIdentity($this); } return parent::afterSave($insert, $changedAttributes); }
/** * Setup Administrative User * * This should be the last step, before the user is created also the * application secret will created. */ public function actionAdmin() { // Admin account already created if (User::find()->count() > 0) { return $this->redirect(Yii::$app->getModule('installer')->getNextConfigStepUrl()); } $userModel = new User(); $userModel->scenario = 'registration_email'; $userPasswordModel = new Password(); $userPasswordModel->scenario = 'registration'; $profileModel = $userModel->profile; $profileModel->scenario = 'registration'; // Build Form Definition $definition = array(); $definition['elements'] = array(); // Add User Form $definition['elements']['User'] = array('type' => 'form', 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100))); // Add User Password Form $definition['elements']['Password'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255))); // Add Profile Form $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition()); // Get Form Definition $definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('InstallerModule.controllers_ConfigController', 'Create Admin Account'))); $form = new \humhub\compat\HForm($definition); $form->models['User'] = $userModel; $form->models['Password'] = $userPasswordModel; $form->models['Profile'] = $profileModel; if ($form->submitted('save') && $form->validate()) { $form->models['User']->status = User::STATUS_ENABLED; $form->models['User']->language = ''; $form->models['User']->tags = 'Administration, Support, HumHub'; $form->models['User']->last_activity_email = new \yii\db\Expression('NOW()'); $form->models['User']->save(); $form->models['Profile']->user_id = $form->models['User']->id; $form->models['Profile']->title = "System Administration"; $form->models['Profile']->save(); // Save User Password $form->models['Password']->user_id = $form->models['User']->id; $form->models['Password']->setPassword($form->models['Password']->newPassword); $form->models['Password']->save(); $userId = $form->models['User']->id; Group::getAdminGroup()->addUser($form->models['User']); // Reload User $adminUser = User::findOne(['id' => 1]); // Switch Identity Yii::$app->user->switchIdentity($adminUser); // Create Welcome Space $space = new Space(); $space->name = Yii::t("InstallerModule.controllers_ConfigController", "Welcome Space"); $space->description = Yii::t("InstallerModule.controllers_ConfigController", "Your first sample space to discover the platform."); $space->join_policy = Space::JOIN_POLICY_FREE; $space->visibility = Space::VISIBILITY_ALL; $space->created_by = $adminUser->id; $space->auto_add_new_members = 1; $space->color = '#6fdbe8'; $space->save(); // activate all available modules for this space foreach ($space->getAvailableModules() as $module) { $space->enableModule($module->id); } // Add Some Post to the Space $post = new \humhub\modules\post\models\Post(); $post->message = Yii::t("InstallerModule.controllers_ConfigController", "Yay! I've just installed HumHub ;Cool;"); $post->content->container = $space; $post->content->visibility = \humhub\modules\content\models\Content::VISIBILITY_PUBLIC; $post->save(); return $this->redirect(Yii::$app->getModule('installer')->getNextConfigStepUrl()); } return $this->render('admin', array('hForm' => $form)); }