/** * 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)); }
/** * 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; }
/** * 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; } }
/** * 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)); }
/** * 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)); }
/** * 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)); }
/** * 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)); }
/** * 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; }
/** * 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; }
public function actionIndex() { $needApproval = 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'; /////////////////////////////////////////////////////// // Generate a random first name $firstNameOptions = explode("\n", Setting::GetText('anonAccountsFirstNameOptions')); $randomFirstName = trim(ucfirst($firstNameOptions[array_rand($firstNameOptions)])); // Generate a random last name $lastNameOptions = explode("\n", Setting::GetText('anonAccountsLastNameOptions')); $randomLastName = trim(ucfirst($lastNameOptions[array_rand($lastNameOptions)])); // Pre-set the random first and last name $profileModel->lastname = $randomLastName; $profileModel->firstname = $randomFirstName; // Make the username from the first and lastnames (only first 25 chars) $userModel->username = substr(str_replace(" ", "_", strtolower($profileModel->firstname . "_" . $profileModel->lastname)), 0, 25); /////////////////////////////////////////////////////// // 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 Identicon Form $identiconForm = new IdenticonForm(); $definition['elements']['IdenticonForm'] = array('type' => 'form', 'elements' => array('image' => array('type' => 'hidden', 'class' => 'form-control', 'id' => 'image'))); // Add Profile Form $definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition()); // Add User Form $definition['elements']['User'] = array('type' => 'form', 'title' => Yii::t('UserModule.controllers_AuthController', 'Account'), 'elements' => array('username' => array('type' => 'hidden', '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))); // 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; $form->models['IdenticonForm'] = $identiconForm; if ($form->submitted('save') && $form->validate() && $identiconForm->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) { $user = $form->models['User']; Yii::$app->user->login($user); // Prepend Data URI scheme (stripped out for safety) $identiconForm->image = str_replace("[removed]", "data:image/png;base64,", $identiconForm->image); // Upload new Profile Picture for user $this->uploadProfilePicture(Yii::$app->user->guid, $identiconForm->image); // Redirect to dashboard 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)); }