Пример #1
0
 /**
  * Edit Users Profile
  */
 public function actionEdit()
 {
     $user = Yii::$app->user->getIdentity();
     // Get Form Definition
     $definition = $user->profile->getFormDefinition();
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => Yii::t('UserModule.controllers_AccountController', 'Save profile'), 'class' => 'btn btn-primary'));
     $form = new \humhub\compat\HForm($definition, $user->profile);
     $form->showErrorSummary = true;
     if ($form->submitted('save') && $form->validate() && $form->save()) {
         // Trigger search refresh
         $user->save();
         Yii::$app->getSession()->setFlash('data-saved', Yii::t('UserModule.controllers_AccountController', 'Saved'));
         return $this->redirect(Url::to(['edit']));
     }
     return $this->render('edit', array('hForm' => $form));
 }
Пример #2
0
 /**
  * Setup Administrative User
  *
  * This should be the last step, before the user is created also the
  * application secret will created.
  */
 public function actionAdmin()
 {
     $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();
     // 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['User']->group_id = 1;
     $form->models['Password'] = $userPasswordModel;
     $form->models['Profile'] = $profileModel;
     if ($form->submitted('save') && $form->validate()) {
         if (Setting::Get('secret') == "") {
             Setting::Set('secret', \humhub\libs\UUID::v4());
         }
         $form->models['User']->status = User::STATUS_ENABLED;
         $form->models['User']->super_admin = true;
         $form->models['User']->language = '';
         $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;
         // Switch Identity
         Yii::$app->user->switchIdentity($form->models['User']);
         // Create Welcome Space
         $space = new Space();
         $space->name = 'Welcome Space';
         $space->description = 'Your first sample space to discover the platform.';
         $space->join_policy = Space::JOIN_POLICY_FREE;
         $space->visibility = Space::VISIBILITY_ALL;
         $space->created_by = $userId;
         $space->auto_add_new_members = 1;
         $space->save();
         $profileImage = new \humhub\libs\ProfileImage($space->guid);
         $profileImage->setNew(Yii::getAlias("@webroot/resources/installer/welcome_space.jpg"));
         // Add Some Post to the Space
         $post = new \humhub\modules\post\models\Post();
         $post->message = "Yay! I've just installed HumHub :-)";
         $post->content->container = $space;
         $post->content->visibility = \humhub\modules\content\models\Content::VISIBILITY_PUBLIC;
         $post->save();
         return $this->redirect(Url::to(['finished']));
     }
     return $this->render('admin', array('hForm' => $form));
 }
Пример #3
0
 /**
  * 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));
 }