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;
 }
Exemple #2
0
 /**
  * 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);
 }
 /**
  * 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));
 }