示例#1
0
 /**
  * Remove new users that didn't validate the email for more than x days(read from config)
  * Removed deleted accounts if x days passed (read from config)
  */
 public function actionUsers()
 {
     $newUsers = User::findAll("status = :new AND register_date < DATE_SUB(NOW(), INTERVAL :days DAY)", array(':new' => User::STATUS_NEW, ':days' => GlobalConfig::value('USERS_REMOVE_NEW_AFTER_DAYS')));
     foreach ($newUsers as $user) {
         $this->debug($user->name . '<' . $user->email . '> deleted! [new]');
         $user->delete();
     }
     $deletedUsers = User::findAll("status = :deleted AND deleteblock_date < DATE_SUB(NOW(), INTERVAL :days DAY)", array(':deleted' => User::STATUS_DELETED, ':days' => GlobalConfig::value('USERS_REMOVE_DELETED_AFTER_X_DAYS')));
     foreach ($deletedUsers as $user) {
         $this->debug($user->name . '<' . $user->email . '> deleted! [delete request on ' . $user->deleteblock_date . ']');
         $user->delete();
     }
 }
示例#2
0
 public static function value($key)
 {
     if (self::get()->useGlobalConfig) {
         $value = GlobalConfig::value($key) ?: self::get()->{$key};
     } else {
         $value = self::get()->{$key};
     }
     $value = str_replace(['{APP_ROOT}', '{DIRECTORY_SEPARATOR}'], [APP_ROOT, DIRECTORY_SEPARATOR], $value);
     if (is_a(App::get(), WebApp::className())) {
         return str_replace(['{WEB_ROOT}', '{MODULE_FOLDER}'], [WebApp::get()->request()->getWebRoot(), WebApp::get()->request()->getModulePath()], $value);
     }
     return $value;
 }
示例#3
0
 public function actionEditConfig($id = null)
 {
     if (!$id) {
         $id = isset($_POST['save']) ? array_keys($_POST['GlobalConfig']) : $_POST['GlobalConfig'];
     }
     $ms = GlobalConfig::findAllByPk($id);
     $models = array();
     foreach ($ms as $model) {
         $models[$model->id] = $model;
     }
     if (isset($_POST['save'])) {
         $ok = true;
         foreach ($_POST['GlobalConfig'] as $k => $details) {
             $models[$k]->setAttributes($details);
             $models[$k]->lastupdate_date = date('Y-m-d H:i:s');
             $models[$k]->lastupdate_user = WebApp::get()->user()->id;
             $ok = $ok && $models[$k]->save();
         }
         if ($ok) {
             Messages::get()->info('Changes saved!');
             $this->getRequest()->goToPage('admin', 'config');
         }
     }
     $this->assign('models', $models);
 }
示例#4
0
 /**
  * On google developers console you should add the following redirect uris: [replace www.website.com with your own website]
  * http://www.website.com/
  * http://www.website.com/user/profile
  * http://www.website.com/admin/
  * http://www.website.com/admin/user/profile
  * @param bool $force
  * @return null|\Google_Client
  */
 public function getGoogleClient($force = false)
 {
     if ($this->isConnected() && !$force) {
         return null;
     }
     if (!$this->googleClient) {
         if (!GlobalConfig::value('GOOGLE_CLIENTID') || !GlobalConfig::value('GOOGLE_CLIENTSECRET') || !GlobalConfig::value('GOOGLE_DEVELOPERKEY')) {
             return null;
         }
         $this->googleClient = new \Google_Client();
         $this->googleClient->setClientId(GlobalConfig::value('GOOGLE_CLIENTID'));
         $this->googleClient->setClientSecret(GlobalConfig::value('GOOGLE_CLIENTSECRET'));
         $this->googleClient->setRedirectUri($force ? WebApp::get()->request()->createURL('user', 'profile') : WebApp::get()->request()->getLinkRoot());
         $this->googleClient->setDeveloperKey(GlobalConfig::value('GOOGLE_DEVELOPERKEY'));
         $this->googleClient->setScopes(array('https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'));
         $this->googleOauth = new \Google_Service_Oauth2($this->googleClient);
     }
     return $this->googleClient;
 }
示例#5
0
 /**
  * Register current user; to be called after validation
  */
 public function register()
 {
     $this->password = self::hashPassword($this->newPassword);
     $this->register_date = date('Y-m-d H:i:s');
     $this->status = self::STATUS_NEW;
     $this->title_id = GlobalConfig::value('USERS_DEFAULT_TITLE_ID');
     $this->lastconfirmationmail_date = date('Y-m-d H:i:s');
     $groups = explode(",", GlobalConfig::value('USERS_DEFAULT_GROUP_IDS'));
     if ($this->save(false)) {
         if (!Emails::get()->sendToNewAccount($this)) {
             Messages::get()->error('There was an error when trying to send confirmation email! Please try again!');
             $this->delete();
             // delete user from DB so that it can be inserted again with a second try.
             return false;
         }
         $connectionTable = WebApp::get()->sql()->table('users2groups');
         foreach ($groups as $id) {
             $connectionTable->insert(array('user_id' => $this->id, 'group_id' => trim($id)));
         }
         $this->logAction(UserHistory::ACTION_CREATED);
         return true;
     }
     return false;
 }