public function getMailUpdate(User $user, $interval) { $output = ""; foreach (Session::find()->where(['<', 'expire', time()])->all() as $session) { $session->delete(); } $receive_email_notifications = $user->getSetting("receive_email_notifications", 'core', Setting::Get('receive_email_notifications', 'mailing')); // Never receive notifications if ($receive_email_notifications == User::RECEIVE_EMAIL_NEVER) { return ""; } // We are in hourly mode and user wants daily if ($interval == CronController::EVENT_ON_HOURLY_RUN && $receive_email_notifications == User::RECEIVE_EMAIL_DAILY_SUMMARY) { return ""; } // We are in daily mode and user dont wants daily reports if ($interval == CronController::EVENT_ON_DAILY_RUN && $receive_email_notifications != User::RECEIVE_EMAIL_DAILY_SUMMARY) { return ""; } // User wants only when offline and is online if ($interval == CronController::EVENT_ON_HOURLY_RUN) { $isOnline = count($user->httpSessions) > 0; if ($receive_email_notifications == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) { return ""; } } $query = Notification::find()->where(['user_id' => $user->id])->andWhere(['!=', 'seen', 1])->andWhere(['!=', 'emailed', 1]); foreach ($query->all() as $notification) { $output .= $notification->getClass()->render(BaseNotification::OUTPUT_MAIL); $notification->emailed = 1; $notification->save(); } return $output; }
/** * @return type */ public function getHttpSessions() { return $this->hasMany(\humhub\modules\user\models\Session::className(), ['user_id' => 'id']); }
/** * 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(); }
/** * Allows third party applications to convert a valid sessionId * into a username. */ public function actionGetSessionUserJson() { Yii::$app->response->format = 'json'; $sessionId = Yii::$app->request->get('sessionId'); $output = array(); $output['valid'] = false; $httpSession = \humhub\modules\user\models\Session::findOne(['id' => $sessionId]); if ($httpSession != null && $httpSession->user != null) { $output['valid'] = true; $output['userName'] = $httpSession->user->username; $output['fullName'] = $httpSession->user->displayName; $output['email'] = $httpSession->user->email; $output['superadmin'] = $httpSession->user->super_admin; } return $output; }
/** * Tasks on hourly cron job * * @param \yii\base\Event $event */ public static function onHourlyCron($event) { $controller = $event->sender; foreach (Yii::$app->authClientCollection->getClients() as $authClient) { if ($authClient instanceof authclient\interfaces\AutoSyncUsers) { /** * @var authclient\interfaces\AutoSyncUsers $authClient */ $authClient->syncUsers(); } } // Delete expired session foreach (models\Session::find()->where(['<', 'expire', time()])->all() as $session) { $session->delete(); } }
public static function onHourlyCron($event) { $controller = $event->sender; if (Setting::Get('enabled', 'authentication_ldap') && Setting::Get('refreshUsers', 'authentication_ldap') && Ldap::isAvailable()) { $controller->stdout("Refresh ldap users... "); Ldap::getInstance()->refreshUsers(); $controller->stdout('done.' . PHP_EOL, \yii\helpers\Console::FG_GREEN); } // Delete expired session foreach (models\Session::find()->where(['<', 'expire', time()])->all() as $session) { $session->delete(); } }