/** * Crops the space image */ public function actionCrop() { $space = $this->getSpace(); $model = new \humhub\models\forms\CropProfileImage(); $profileImage = new \humhub\libs\ProfileImage($space->guid); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $profileImage->cropOriginal($model->cropX, $model->cropY, $model->cropH, $model->cropW); return $this->htmlRedirect($space->getUrl()); } return $this->renderAjax('crop', array('model' => $model, 'profileImage' => $profileImage, 'space' => $space)); }
/** * Sample Data */ public function actionSampleData() { if (Yii::$app->getModule('installer')->settings->get('sampleData') == 1) { // Sample Data already created return $this->redirect(Yii::$app->getModule('installer')->getNextConfigStepUrl()); } $form = new \humhub\modules\installer\forms\SampleDataForm(); $form->sampleData = 1; if ($form->load(Yii::$app->request->post()) && $form->validate()) { Yii::$app->getModule('installer')->settings->set('sampleData', $form->sampleData); if (Yii::$app->getModule('installer')->settings->get('sampleData') == 1) { // Add sample image to admin $admin = User::find()->where(['id' => 1])->one(); $adminImage = new \humhub\libs\ProfileImage($admin->guid); $adminImage->setNew(Yii::getAlias("@webroot/resources/installer/user_male_1.jpg")); // Create second user $userModel = new User(); $userModel->scenario = 'registration'; $profileModel = $userModel->profile; $profileModel->scenario = 'registration'; $userModel->status = User::STATUS_ENABLED; $userModel->username = "******"; $userModel->email = "*****@*****.**"; $userModel->language = ''; $userModel->tags = "Microsoft Office, Marketing, SEM, Digital Native"; $userModel->last_activity_email = new \yii\db\Expression('NOW()'); $userModel->save(); $profileImage = new \humhub\libs\ProfileImage($userModel->guid); $profileImage->setNew(Yii::getAlias("@webroot/resources/installer/user_male_2.jpg")); $profileModel->user_id = $userModel->id; $profileModel->firstname = "David"; $profileModel->lastname = "Roberts"; $profileModel->title = "Late riser"; $profileModel->street = "2443 Queens Lane"; $profileModel->zip = "24574"; $profileModel->city = "Allwood"; $profileModel->country = "Virginia"; $profileModel->save(); // Create third user $userModel2 = new User(); $userModel2->scenario = 'registration'; $profileModel2 = $userModel2->profile; $profileModel2->scenario = 'registration'; $userModel2->status = User::STATUS_ENABLED; $userModel2->username = "******"; $userModel2->email = "*****@*****.**"; $userModel2->language = ''; $userModel2->tags = "Yoga, Travel, English, German, French"; $userModel2->last_activity_email = new \yii\db\Expression('NOW()'); $userModel2->save(); $profileImage2 = new \humhub\libs\ProfileImage($userModel2->guid); $profileImage2->setNew(Yii::getAlias("@webroot/resources/installer/user_female_1.jpg")); $profileModel2->user_id = $userModel2->id; $profileModel2->firstname = "Sara"; $profileModel2->lastname = "Schuster"; $profileModel2->title = "Do-gooder"; $profileModel2->street = "Schmarjestrasse 51"; $profileModel2->zip = "17095"; $profileModel2->city = "Friedland"; $profileModel2->country = "Niedersachsen"; $profileModel2->save(); // Switch Identity $user = User::find()->where(['id' => 1])->one(); Yii::$app->user->switchIdentity($user); $space = Space::find()->where(['id' => 1])->one(); // Create a sample post $post = new \humhub\modules\post\models\Post(); $post->message = Yii::t("InstallerModule.controllers_ConfigController", "We're looking for great slogans of famous brands. Maybe you can come up with some samples?"); $post->content->container = $space; $post->content->visibility = \humhub\modules\content\models\Content::VISIBILITY_PRIVATE; $post->save(); // Switch Identity Yii::$app->user->switchIdentity($userModel); $comment = new \humhub\modules\comment\models\Comment(); $comment->message = Yii::t("InstallerModule.controllers_ConfigController", "Nike – Just buy it. ;Wink;"); $comment->object_model = $post->className(); $comment->object_id = $post->getPrimaryKey(); $comment->save(); // Switch Identity Yii::$app->user->switchIdentity($userModel2); $comment2 = new \humhub\modules\comment\models\Comment(); $comment2->message = Yii::t("InstallerModule.controllers_ConfigController", "Calvin Klein – Between love and madness lies obsession."); $comment2->object_model = $post->className(); $comment2->object_id = $post->getPrimaryKey(); $comment2->save(); // Create Like Object $like = new \humhub\modules\like\models\Like(); $like->object_model = $comment->className(); $like->object_id = $comment->getPrimaryKey(); $like->save(); $like = new \humhub\modules\like\models\Like(); $like->object_model = $post->className(); $like->object_id = $post->getPrimaryKey(); $like->save(); // trigger install sample data event $this->trigger(self::EVENT_INSTALL_SAMPLE_DATA); } return $this->redirect(Yii::$app->getModule('installer')->getNextConfigStepUrl()); } return $this->render('sample-data', array('model' => $form)); }
/** * 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)); }
/** * Crops the profile image of the user */ public function actionCropProfileImage() { $model = new \humhub\models\forms\CropProfileImage(); $profileImage = new \humhub\libs\ProfileImage(Yii::$app->user->guid); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $profileImage->cropOriginal($model->cropX, $model->cropY, $model->cropH, $model->cropW); return $this->htmlRedirect(Yii::$app->user->getModel()->getUrl()); } return $this->renderAjax('cropProfileImage', array('model' => $model, 'profileImage' => $profileImage, 'user' => Yii::$app->user->getIdentity())); }