Ejemplo n.º 1
0
 /**
  * Creates a new Space
  */
 public function actionCreate()
 {
     if (!Yii::$app->user->getIdentity()->canCreateSpace()) {
         throw new HttpException(400, 'You are not allowed to create spaces!');
     }
     $model = new Space();
     $model->scenario = 'create';
     $model->visibility = Setting::Get('defaultVisibility', 'space');
     $model->join_policy = Setting::Get('defaultJoinPolicy', 'space');
     if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) {
         Yii::$app->getSession()->setFlash('ws', 'created');
         return $this->htmlRedirect($model->getUrl());
     }
     return $this->renderAjax('create', array('model' => $model));
 }
 /** 
  * Registers a user
  * @param $data
  * @return Bool
  */
 private function registerUser($data)
 {
     $userModel = new User();
     $userModel->scenario = 'registration';
     $profileModel = $userModel->profile;
     $profileModel->scenario = 'registration';
     // User: Set values
     $userModel->username = $data['username'];
     $userModel->email = $data['email'];
     $userModel->group_id = $data['group_id'];
     $userModel->status = User::STATUS_ENABLED;
     // Profile: Set values
     $profileModel->firstname = $data['firstname'];
     $profileModel->lastname = $data['lastname'];
     // Password: Set values
     $userPasswordModel = new Password();
     $userPasswordModel->setPassword($data['password']);
     if ($userModel->save()) {
         // Save user profile
         $profileModel->user_id = $userModel->id;
         $profileModel->save();
         // Save user password
         $userPasswordModel->user_id = $userModel->id;
         $userPasswordModel->save();
         // Join space / create then join space
         foreach ($data['space_names'] as $key => $space_name) {
             // Find space by name attribute
             $space = Space::findOne(['name' => $space_name]);
             // Create the space if not found
             if ($space == null) {
                 $space = new Space();
                 $space->name = $space_name;
                 $space->save();
             }
             // Add member into space
             $space->addMember($userModel->id);
         }
         return true;
     } else {
         Yii::$app->session->setFlash('error', Html::errorSummary($userModel));
         return false;
     }
 }
Ejemplo n.º 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()
 {
     $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));
 }
Ejemplo n.º 4
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));
 }