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; }
/** * Resets users password based on given token */ public function actionReset() { $user = User::findOne(array('guid' => Yii::$app->request->get('guid'))); if ($user === null || !$this->checkPasswordResetToken($user, Yii::$app->request->get('token'))) { throw new HttpException('500', 'It looks like you clicked on an invalid password reset link. Please try again.'); } $model = new Password(); $model->scenario = 'registration'; if ($model->load(Yii::$app->request->post()) && $model->validate()) { Yii::$app->getModule('user')->settings->contentContainer($user)->delete('passwordRecoveryToken'); $model->user_id = $user->id; $model->setPassword($model->newPassword); $model->save(); return $this->render('reset_success'); } return $this->render('reset', array('model' => $model)); }
/** * Before Delete of a User * */ public function beforeDelete() { // We don't allow deletion of users who owns a space - validate that foreach (\humhub\modules\space\models\Membership::GetUserSpaces($this->id) as $space) { if ($space->isSpaceOwner($this->id)) { throw new Exception("Tried to delete a user which is owner of a space!"); } } // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } // Delete profile image $this->getProfileImage()->delete(); // Remove from search index Yii::$app->search->delete($this); // Cleanup related tables Invite::deleteAll(['user_originator_id' => $this->id]); Follow::deleteAll(['user_id' => $this->id]); Follow::deleteAll(['object_model' => $this->className(), 'object_id' => $this->id]); Password::deleteAll(['user_id' => $this->id]); Profile::deleteAll(['user_id' => $this->id]); GroupUser::deleteAll(['user_id' => $this->id]); Session::deleteAll(['user_id' => $this->id]); return parent::beforeDelete(); }
/** * Callback to validate module database records. * * @param \yii\base\Event $event */ public static function onIntegrityCheck($event) { $integrityController = $event->sender; $integrityController->showTestHeadline("User Module - Users (" . User::find()->count() . " entries)"); foreach (User::find()->joinWith(['profile'])->all() as $user) { if ($user->profile == null) { $integrityController->showWarning("User with id " . $user->id . " has no profile record!"); } } foreach (GroupUser::find()->joinWith(['user'])->all() as $groupUser) { if ($groupUser->user == null) { if ($integrityController->showFix("Deleting group admin " . $groupUser->id . " without existing user!")) { $groupUser->delete(); } } } $integrityController->showTestHeadline("User Module - Password (" . Password::find()->count() . " entries)"); foreach (Password::find()->joinWith(['user'])->all() as $password) { if ($password->user == null) { if ($integrityController->showFix("Deleting password " . $password->id . " without existing user!")) { $password->delete(); } } } $integrityController->showTestHeadline("User Module - Profile (" . Profile::find()->count() . " entries)"); foreach (Profile::find()->joinWith(['user'])->all() as $profile) { if ($profile->user == null) { if ($integrityController->showFix("Deleting profile " . $profile->user_id . " without existing user!")) { $profile->delete(); } } } $integrityController->showTestHeadline("User Module - Mentioning (" . Mentioning::find()->count() . " entries)"); foreach (Mentioning::find()->joinWith(['user'])->all() as $mentioning) { if ($mentioning->user == null) { if ($integrityController->showFix("Deleting mentioning " . $mentioning->id . " of non existing user!")) { $mentioning->delete(); } } if ($mentioning->getPolymorphicRelation() == null) { if ($integrityController->showFix("Deleting mentioning " . $mentioning->id . " of non target!")) { $mentioning->delete(); } } } $integrityController->showTestHeadline("User Module - Follow (" . Follow::find()->count() . " entries)"); foreach (Follow::find()->joinWith(['user'])->all() as $follow) { if ($follow->user == null) { if ($integrityController->showFix("Deleting follow " . $follow->id . " of non existing user!")) { $follow->delete(); } } if ($follow->getTarget() == null) { if ($integrityController->showFix("Deleting follow " . $follow->id . " of non target!")) { $follow->delete(); } } } $integrityController->showTestHeadline("User Module - Modules (" . models\Module::find()->count() . " entries)"); foreach (models\Module::find()->joinWith(['user'])->all() as $module) { if ($module->user == null) { if ($integrityController->showFix("Deleting user-module " . $module->id . " of non existing user!")) { $module->delete(); } } } }
public function actionSetDefaultPass() { if (isset($_GET['user_ids'])) { $user_ids = explode(",", $_GET['user_ids']); foreach ($user_ids as $user_id) { $userPasswordModel = new Password(); $userPasswordModel->user_id = $user_id; $userPasswordModel->setPassword("password"); if ($userPasswordModel->save()) { echo "Saved... <br />"; } } } else { echo "<p>?user_ids=user_id,user_id to reset the password of users to 'password'</p>"; } }