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; }
public function up() { $spaces = Space::find()->all(); $users = User::find()->all(); $containers = array_merge($users == null ? [] : $users, $spaces == null ? [] : $spaces); foreach ($containers as $container) { $created_by = $container instanceof User ? $container->id : $container instanceof Space ? $container->created_by : 1; $created_by = $created_by == null ? 1 : $created_by; if ($container->isModuleEnabled('cfiles')) { $this->insert('cfiles_folder', ['title' => Module::ROOT_TITLE, 'description' => Module::ROOT_DESCRIPTION, 'parent_folder_id' => 0, 'has_wall_entry' => false, 'type' => Folder::TYPE_FOLDER_ROOT]); $root_id = Yii::$app->db->getLastInsertID(); $this->insert('content', ['guid' => \humhub\libs\UUID::v4(), 'object_model' => Folder::className(), 'object_id' => $root_id, 'visibility' => 0, 'sticked' => 0, 'archived' => 0, 'created_at' => new \yii\db\Expression('NOW()'), 'created_by' => $created_by, 'updated_at' => new \yii\db\Expression('NOW()'), 'updated_by' => $created_by, 'contentcontainer_id' => $container->contentcontainer_id]); $this->insert('cfiles_folder', ['title' => Module::ALL_POSTED_FILES_TITLE, 'description' => Module::ALL_POSTED_FILES_DESCRIPTION, 'parent_folder_id' => $root_id, 'has_wall_entry' => false, 'type' => Folder::TYPE_FOLDER_POSTED]); $allpostedfiles_id = Yii::$app->db->getLastInsertID(); $this->insert('content', ['guid' => \humhub\libs\UUID::v4(), 'object_model' => Folder::className(), 'object_id' => $allpostedfiles_id, 'visibility' => 0, 'sticked' => 0, 'archived' => 0, 'created_at' => new \yii\db\Expression('NOW()'), 'created_by' => $created_by, 'updated_at' => new \yii\db\Expression('NOW()'), 'updated_by' => $created_by, 'contentcontainer_id' => $container->contentcontainer_id]); $posted_content_id = Yii::$app->db->getLastInsertID(); $filesQuery = File::find()->joinWith('baseFile')->contentContainer($container); $foldersQuery = Folder::find()->contentContainer($container); $filesQuery->andWhere(['cfiles_file.parent_folder_id' => 0]); // user maintained folders $foldersQuery->andWhere(['cfiles_folder.parent_folder_id' => 0]); // do not return any folders here that are root or allpostedfiles $foldersQuery->andWhere(['cfiles_folder.type' => null]); $rootsubfiles = $filesQuery->all(); $rootsubfolders = $foldersQuery->all(); foreach ($rootsubfiles as $file) { $this->update('cfiles_file', ['cfiles_file.parent_folder_id' => $root_id], ['id' => $file->id]); } foreach ($rootsubfolders as $folder) { $this->update('cfiles_folder', ['parent_folder_id' => $root_id], ['id' => $folder->id]); } } } }
public function beforeValidate($event) { if ($this->owner->isNewRecord) { if ($this->owner->guid == "") { $this->owner->guid = \humhub\libs\UUID::v4(); } } }
public function setGuid($event) { if ($this->owner->isNewRecord) { if ($this->owner->guid == "") { $this->owner->guid = \humhub\libs\UUID::v4(); } } }
/** * Sends this user a new password by E-Mail * */ public function recover() { $user = User::findOne(array('email' => $this->email)); // Switch to users language - if specified if ($user->language !== "") { Yii::$app->language = $user->language; } $token = \humhub\libs\UUID::v4(); Yii::$app->getModule('user')->settings->contentContainer($user)->set('passwordRecoveryToken', $token . '.' . time()); $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword', 'text' => '@humhub/modules/user/views/mails/plaintext/RecoverPassword'], ['user' => $user, 'linkPasswordReset' => Url::to(["/user/password-recovery/reset", 'token' => $token, 'guid' => $user->guid], true)]); $mail->setFrom([Yii::$app->settings->get('mailer.systemEmailAddress') => Yii::$app->settings->get('mailer.systemEmailName')]); $mail->setTo($user->email); $mail->setSubject(Yii::t('UserModule.forms_AccountRecoverPasswordForm', 'Password Recovery')); $mail->send(); return true; }
/** * Sends this user a new password by E-Mail * */ public function recover() { $user = User::findOne(array('email' => $this->email)); // Switch to users language - if specified if ($user->language !== "") { Yii::$app->language = $user->language; } $token = \humhub\libs\UUID::v4(); $user->setSetting('passwordRecoveryToken', $token . '.' . time(), 'user'); $mail = Yii::$app->mailer->compose(['html' => '@humhub/modules/user/views/mails/RecoverPassword'], ['user' => $user, 'linkPasswordReset' => Url::to(["/user/auth/reset-password", 'token' => $token, 'guid' => $user->guid], true)]); $mail->setFrom([\humhub\models\Setting::Get('systemEmailAddress', 'mailing') => \humhub\models\Setting::Get('systemEmailName', 'mailing')]); $mail->setTo($user->email); $mail->setSubject(Yii::t('UserModule.forms_AccountRecoverPasswordForm', 'Password Recovery')); $mail->send(); return true; }
/** * 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)); }
/** * Sets an password and hash it * * @param string $password */ public function setPassword($newPassword) { $this->salt = \humhub\libs\UUID::v4(); $this->algorithm = $this->defaultAlgorithm; $this->password = $this->hashPassword($newPassword); }
public function actionFinish() { if (Yii::$app->settings->get('secret') == "") { Yii::$app->settings->set('secret', \humhub\libs\UUID::v4()); } \humhub\libs\DynamicConfig::rewrite(); return $this->redirect(['finished']); }
public function actionFinish() { if (Setting::Get('secret') == "") { Setting::Set('secret', \humhub\libs\UUID::v4()); } \humhub\libs\DynamicConfig::rewrite(); $this->redirect(['finished']); }