public function actionDelete(array $ids) { foreach ($ids as $id) { $model = SettingParam::model()->findByPk($id); /** * TODO: Check related data if this User is deletable * This can be done in onBeforeDelete or here or in extensions * * if (Related::model()->count("UserId = {$id}") > 0) * $this->result->fail(ERROR_VIOLATING_BUSINESS_RULES, Yii::t('XUser.User',"Cannot delete User ID={$id} as it has related class data.")); * else */ try { $module = $model->module; if ($model->delete()) { //remove user custom setting if (!$model->customizable) { UserSetting::model()->deleteAllByAttributes(array('param_name' => $model->name)); } //rebuild cache Constant Settings class Yii::app()->XService->run('Xpress.Settings.db2php', array('module' => $module)); } } catch (CException $ex) { errorHandler()->log(new XException($ex->getMessage(), $ex->getCode())); } } }
/** * Looks up user supplied email address / alias and sends a mail * * @param $email email address or username */ function sendMail($in) { $in = trim($in); if (is_email($in)) { $user_id = UserFinder::byEmail($in); } else { $user_id = UserFinder::byUsername($in); } $error = ErrorHandler::getInstance(); if (!$user_id) { $error->add('Invalid email address or username'); return false; } $email = UserSetting::getEmail($user_id); if (!$email) { throw new \Exception('entered email not found'); } $code = Token::generate($user_id, 'activation_code'); $pattern = array('/@USERNAME@/', '/@IP@/', '/@URL@/', '/@EXPIRETIME@/'); $user = User::get($user_id); $page = XmlDocumentHandler::getInstance(); $url = $page->getUrl() . 'u/reset_pwd/' . $code; $replacement = array($user->getName(), client_ip(), $url, shortTimePeriod($this->expire_time_email)); $msg = preg_replace($pattern, $replacement, $this->password_msg); //d($msg); $mail = SendMail::getInstance(); $mail->addRecipient($email); $mail->setSubject('Forgot password'); $mail->send($msg); return true; }
/** @return user id */ static function byEmail($email) { $email = trim($email); if (!is_email($email)) { throw new \Exception('XXX not an email address: ' . $email); } $res = UserSetting::getList('email', $email); if (count($res) == 1) { return $res[0]; } if (count($res) > 1) { throw new \Exception('XXX multiple users with same email address'); } return false; }
public static function userConfig($uid, $type = '') { $dataProvider = UserSetting::model()->findAllByAttributes(array('uid' => $uid)); $settings = CHtml::listData($dataProvider, 'stype', 'svalue'); if (!empty($type)) { if (!isset($settings[$type]) or empty($settings[$type])) { return 1; } else { if ($settings[$type] == '0') { return false; } else { return true; } } } else { return $settings; } }
function handleEdit($p) { $session = SessionHandler::getInstance(); foreach (UserDataField::getAll() as $f) { if (!empty($p['remove_' . $f->id])) { UserSetting::set($session->id, $f->name, 0); continue; } switch ($f->type) { case UserDataField::IMAGE: if ($p[$f->name]['error'] == UPLOAD_ERR_NO_FILE) { continue; } $album = PhotoAlbum::getProfileAlbumId(); $fileId = File::importImage(USER, $p[$f->name], $album); UserSetting::set($session->id, $f->name, $fileId); break; default: UserSetting::set($session->id, $f->name, $p[$f->name]); } } js_redirect('u/profile'); }
public static function render($id) { $u = User::get($id); if (!$u) { return 'no such user'; } $res = ''; switch ($u->type) { case SESSION_REGULAR: //$res .= '(reg)'; break; case SESSION_FACEBOOK: // '<fb:name uid="'.$u->name.'" useyou="false"></fb:name>'; //$pic = UserSetting::get($u->id, 'fb_picture'); $name = UserSetting::get($u->id, 'fb_name'); $res .= $name . ' (facebook)'; break; default: throw new \Exception('hm'); } // $res .= '<span class="yui3-hastooltip" id="tt_usr_'.$u->id.'">'.$u->name.'</span>'; $res .= ahref('u/profile/' . $u->id, $u->name); return $res; }
function handleFacebookLogin() { if ($this->facebook_id) { throw new \Exception('wiee! already handled'); } // Get User ID $fbuser = $this->fb_handle->getUser(); if (!$fbuser) { return false; } try { $user_profile = $this->fb_handle->api('/me'); } catch (FacebookApiException $e) { // d( $e ); error_log($e); return false; } $this->type = SESSION_FACEBOOK; $this->username = $this->fb_handle->getUser(); $this->facebook_id = $this->fb_handle->getUser(); if (!$this->login($this->facebook_id, '', $this->type)) { return false; } // store email from this result UserSetting::set($this->id, 'email', $user_profile['email']); // store fb_name setting with "name" value UserSetting::set($this->id, 'fb_name', $user_profile['name']); // fetch picture $x = 'https://graph.facebook.com/' . $this->fb_handle->getUser() . '?fields=email,name,picture&access_token=' . $this->fb_handle->getAccessToken(); $res = file_get_contents($x); $res = json_decode($res); //d($res); // store fb_picture setting with "picture" value UserSetting::set($this->id, 'fb_picture', $res->picture); return true; }
$statistics->close(); } $setting = new SkinSetting(); if ($setting->load()) { $writer->write('<skin>' . '<name>' . $setting->skin . '</name>' . '<entriesOnRecent>' . $setting->entriesOnRecent . '</entriesOnRecent>' . '<commentsOnRecent>' . $setting->commentsOnRecent . '</commentsOnRecent>' . '<trackbacksOnRecent>' . $setting->trackbacksOnRecent . '</trackbacksOnRecent>' . '<commentsOnGuestbook>' . $setting->commentsOnGuestbook . '</commentsOnGuestbook>' . '<tagsOnTagbox>' . $setting->tagsOnTagbox . '</tagsOnTagbox>' . '<alignOnTagbox>' . $setting->alignOnTagbox . '</alignOnTagbox>' . '<expandComment>' . $setting->expandComment . '</expandComment>' . '<expandTrackback>' . $setting->expandTrackback . '</expandTrackback>' . '<recentNoticeLength>' . $setting->recentNoticeLength . '</recentNoticeLength>' . '<recentEntryLength>' . $setting->recentEntryLength . '</recentEntryLength>' . '<recentTrackbackLength>' . $setting->recentTrackbackLength . '</recentTrackbackLength>' . '<linkLength>' . $setting->linkLength . '</linkLength>' . '<showListOnCategory>' . $setting->showListOnCategory . '</showListOnCategory>' . '<showListOnArchive>' . $setting->showListOnArchive . '</showListOnArchive>' . '<tree>' . '<name>' . $setting->tree . '</name>' . '<color>' . $setting->colorOnTree . '</color>' . '<bgColor>' . $setting->bgcolorOnTree . '</bgColor>' . '<activeColor>' . $setting->activecolorOnTree . '</activeColor>' . '<activeBgColor>' . $setting->activebgcolorOnTree . '</activeBgColor>' . '<labelLength>' . $setting->labelLengthOnTree . '</labelLength>' . '<showValue>' . $setting->showValueOnTree . '</showValue>' . '</tree>' . '</skin>'); $writer->write(CRLF); } $setting = new PluginSetting(); if ($setting->open()) { do { $writer->write('<plugin>' . '<name>' . $setting->name . '</name>' . '<setting>' . htmlspecialchars($setting->setting) . '</setting>' . '</plugin>'); $writer->write(CRLF); } while ($setting->shift()); $setting->close(); } $setting = new UserSetting(); if ($setting->open()) { do { $writer->write('<userSetting>' . '<name>' . $setting->name . '</name>' . '<value>' . htmlspecialchars($setting->value) . '</value>' . '</userSetting>'); $writer->write(CRLF); } while ($setting->shift()); $setting->close(); } $comment = new GuestComment(); if ($comment->open('parent IS NULL')) { $writer->write('<guestbook>'); do { if ($comment->isfiltered == 0) { $writer->write('<comment>' . '<commenter' . ' id="' . $comment->commenter . '">' . '<name>' . htmlspecialchars(Utils_Unicode::correct($comment->name)) . '</name>' . '<homepage>' . htmlspecialchars(Utils_Unicode::correct($comment->homepage)) . '</homepage>' . '<ip>' . $comment->ip . '</ip>' . '<openid>' . $comment->openid . '</openid>' . '</commenter>' . '<content>' . htmlspecialchars(Utils_Unicode::correct($comment->content)) . '</content>' . '<password>' . htmlspecialchars($comment->password) . '</password>' . '<secret>' . htmlspecialchars($comment->secret) . '</secret>' . '<written>' . $comment->written . '</written>'); $writer->write(CRLF); if ($childComment = $comment->getChildren()) {
/** * Before Delete of a User * */ public function beforeDelete() { // We don't allow deletion of users who owns a space - validate that foreach (SpaceMembership::GetUserSpaces($this->id) as $workspace) { if ($workspace->isSpaceOwner($this->id)) { throw new Exception("Tried to delete a user which is owner of a space!"); } } UserSetting::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } HSearch::getInstance()->deleteModel($this); // Delete Profile Image $this->getProfileImage()->delete(); // Delete all pending invites UserInvite::model()->deleteAllByAttributes(array('user_originator_id' => $this->id)); Follow::model()->deleteAllByAttributes(array('user_id' => $this->id)); Follow::model()->deleteAllByAttributes(array('object_model' => 'User', 'object_id' => $this->id)); // Delete all group admin assignments GroupAdmin::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Delete wall entries WallEntry::model()->deleteAllByAttributes(array('wall_id' => $this->wall_id)); // Deletes all content created by this user foreach (Content::model()->findAllByAttributes(array('user_id' => $this->id)) as $content) { $content->delete(); } foreach (Content::model()->findAllByAttributes(array('created_by' => $this->id)) as $content) { $content->delete(); } // Delete all passwords foreach (UserPassword::model()->findAllByAttributes(array('user_id' => $this->id)) as $password) { $password->delete(); } return parent::beforeDelete(); }
public function saveSettings() { $user = Auth::user(); foreach (UserSettingDefinition::all() as $definition) { $value = Input::get("user-settings-" . $definition->id); if ($definition->type == "checkbox") { $value = $value == "on" ? 1 : 0; } if (isset($value)) { $setting = UserSetting::firstOrNew(['user_id' => $user->id, 'definition_id' => $definition->id]); $setting->value = $value; $setting->save(); } } $user->email = Input::get("user-email"); $user->save(); return Redirect::to('/dashboard/settings'); }
echo '<br/>'; echo xhtmlForm('grp'); $x = new XhtmlComponentDropdown(); $x->name = 'grp_id'; $x->setOptions(UserGroup::getIndexedList()); echo $x->render() . ' '; echo xhtmlSubmit('Add'); echo xhtmlFormClose() . '<br/><br/>'; echo '<h2>Password</h2>'; $form = new XhtmlForm('pwd'); $form->disableAutocomplete(); $form->addPassword('change_pwd', 'Change password'); $form->addSubmit('Change'); echo $form->render() . '<br/><br/>'; echo '<h2>User settings</h2>'; $settings = UserSetting::getAll($user->id); echo xhtmlForm('edit_setting'); echo '<table>'; echo '<tr><th>Name</th><th>Value</th><th>Delete</th></tr>'; //XXX use editable YuiDataTable foreach ($settings as $set) { echo '<tr>'; echo '<td>' . xhtmlInput('setting_name_' . $set['id'], $set['name']) . '</td>'; echo '<td>' . xhtmlInput('setting_val_' . $set['id'], $set['value']) . '</td>'; echo '<td><a href="' . relurl_add(array('remove_setting' => $set['name'])) . '">Remove</a></td>'; echo '</tr>'; } echo '</table>'; echo xhtmlSubmit('Save changes'); echo xhtmlFormClose() . '<br/><br/>'; echo '<h3>Add new user setting</h3>';
public function testSet() { UserSetting::Set(1, 'globalSetting', 'abc2'); $this->assertEquals(UserSetting::Get(1, 'globalSetting', 'core'), 'abc2'); }
/** * Returns a settings record by Name and Module Id * The result is cached. * * @param type $userId * @param type $name * @param type $moduleId * @return \HSetting */ private static function GetRecord($userId, $name, $moduleId = "core") { if ($moduleId == "") { $moduleId = "core"; } $cacheId = 'UserSetting_' . $userId . '_' . $name . '_' . $moduleId; // Check if stored in Runtime Cache if (RuntimeCache::Get($cacheId) !== false) { return RuntimeCache::Get($cacheId); } // Check if stored in Cache $cacheValue = Yii::app()->cache->get($cacheId); if ($cacheValue !== false) { return $cacheValue; } $condition = ""; $params = array('name' => $name, 'user_id' => $userId); if ($moduleId != "") { $params['module_id'] = $moduleId; } else { $condition = "module_id IS NULL"; } $record = UserSetting::model()->findByAttributes($params, $condition); if ($record == null) { $record = new UserSetting(); $record->user_id = $userId; $record->module_id = $moduleId; $record->name = $name; } else { $expireTime = 3600; if ($record->name != 'expireTime' && $record->module_id != "cache") { $expireTime = HSetting::Get('expireTime', 'cache'); } Yii::app()->cache->set($cacheId, $record, $expireTime); RuntimeCache::Set($cacheId, $record); } return $record; }
$session->requireSuperAdmin(); // process updates if (!empty($_POST)) { if (!empty($_POST['u_name']) && !empty($_POST['u_pwd'])) { $username = trim($_POST['u_name']); $pwd = trim($_POST['u_pwd']); $user_id = UserHandler::create($username, $pwd); if (!$user_id) { $error->add('Failed to create user'); } if ($error->getErrorCount()) { echo $error->render(true); return; } UserSetting::setEmail($user_id, $_POST['u_email']); if (!empty($_POST['u_grp'])) { UserGroupHandler::addToGroup($user_id, $_POST['u_grp']); } echo '<div class="good">New user created. ' . ahref('a/user/' . $user_id, $username) . '</div>'; } } echo xhtmlForm('add_user'); echo '<h1>Create new user</h1>'; echo 'Username: '******'u_name') . '<br/>'; echo 'Password: '******'u_pwd') . '<br/>'; echo 'E-mail: ' . xhtmlInput('u_email') . '<br/>'; echo '<br/>'; echo 'User group: '; $x = new XhtmlComponentDropdown(); $x->name = 'u_grp';
echo 'User level: ' . UserHandler::getUserLevel($user_id) . '<br/>'; $gender_id = UserSetting::get($user_id, 'gender'); $gender = Setting::getById(USERDATA_OPTION, $gender_id); echo 'Gender: ' . $gender . '<br/>'; $pres = UserSetting::get($user_id, 'presentation'); if ($pres) { echo 'Presentation: ' . $pres . '<br/>'; } $pic_id = UserSetting::get($user_id, 'picture'); if ($pic_id) { echo 'Profile picture:<br/>'; $a = new XhtmlComponentA(); $a->href = getThumbUrl($pic_id, 0, 0); $a->content = showThumb($pic_id, 'Profilbild', 150, 150); echo $a->render(); } else { $avatar_opt = UserSetting::get($user_id, 'avatar'); // get pic id from avatar_id $avatar_id = UserDataFieldOption::getById($avatar_opt); if ($avatar_id) { echo 'Avatar:<br/>'; $a = new XhtmlComponentA(); $a->href = getThumbUrl($avatar_id, 0, 0); $a->content = showThumb($avatar_id, 'Avatar', 150, 150); echo $a->render(); } } break; default: echo 'No handler for view ' . $this->owner; }
public function addUserSetting(UserSetting $l) { $this->collUserSettings[] = $l; $l->setsfGuardUser($this); }
public function getSettingValue($name) { $setting = UserSetting::where('user_id', $this->id)->whereHas('definition', function ($q) use($name) { $q->where('name', $name); })->first(); return $setting ? $setting->value : null; }
public function actionSettings() { array_pop($_POST); $arr = $_POST; if (Yii::app()->user->isGuest) { $this->message(0, Yii::t('default', 'loginfirst'), Yii::app()->createUrl('site/login'), 1); } $uid = zmf::uid(); foreach ($arr as $key => $val) { $_k = zmf::filterInput($key, 't', 1); $_v = zmf::filterInput($val, 't', 1); $sinfo = UserSetting::model()->findByAttributes(array('stype' => $_k), "uid='{$uid}'"); $model = new UserSetting(); if (!$sinfo) { $_input = array('uid' => $uid, 'stype' => $_k, 'svalue' => $_v); $model->attributes = $_input; if ($model->validate()) { $model->save(); } } elseif ($sinfo->svalue != $_v) { $model->updateByPk($sinfo->id, array('svalue' => $_v)); } } zmf::setFCache("userSettings{$uid}", $arr); $this->redirect(array('users/config')); }
/** * Sets an UserSetting * * @param String $name * @param String $value * @param String $moduleId */ public function setSetting($name, $value, $moduleId = "") { UserSetting::Set($this->getOwner()->id, $name, $value, $moduleId); }
/** * Create new user * * @param array $data, POST data * @return int $id, current id of created user */ public function saveLoginDataTab(array $data){ $userObj = new UserLogin(); $userObj->setUsername($data['userFirstTab_username']); $userObj->setEmail($data['userFirstTab_email']); $userObj->setRoleId($data['userFirstTab_userrole']); $userObj->setPassword($data['userFirstTab_password']); $userObj->save(); $id = $userObj->getId(); $userData = new UserData(); $userData->setUserId($id); $userData->setFirstname($data['userFirstTab_firstname']); $userData->setLastname($data['userFirstTab_lastname']); $userData->save(); $userSetting= new UserSetting(); $userSetting->setUserId($id); $userSetting->setEmailformat($data['userFirstTab_emailformat']); $userSetting->setEmailtype($data['userFirstTab_emailtype']); $userSetting->setLanguage($data['userFirstTab_language']); $userSetting->setFirstlogin(1); $userSetting->save(); return $id; }
/** * Lists all models. */ public function actionIndex() { $url = parse_url(app()->request->getHostInfo(), PHP_URL_HOST); $currentWorkflow = $this->api('Cms.Workflow.getByUrl', array('url' => $url)); $workflowId = 0; $workflows = array(); $workflow = $this->getWorkflow(); if (is_object($workflow)) { $workflowId = $workflow->id; } else { $workflow = $currentWorkflow; //get workflow by url if (is_object($currentWorkflow)) { $workflowId = $currentWorkflow->id; } } //find all workflows if (is_object($workflow)) { //init setting params for current workflow $this->api('Xpress.Settings.sync', array('workflowId' => $workflow->id)); $workflows = Workflow::model()->findAll('site_id=:site_id', array(':site_id' => $workflow->site_id)); if (count($workflows)) { $workflows = CHtml::listData($workflows, 'id', 'name'); } } $model = new SettingParam('search'); $model->unsetAttributes(); // clear any default values if (isset($_POST['SettingParam'])) { $model->attributes = $_POST['SettingParam']; } elseif (isset($_GET['module'])) { $model->module = $_GET['module']; if (in_array($model->module, array('Xpress', 'Admin'))) { $model->module = 'System'; } } else { $model->module = 'System'; } $model->visible = 1; $model->workflow_id = $workflowId; $dataProvider = $model->search(); $dataProvider->pagination = false; $modules = $model->getModules(); $data = $dataProvider->getData(); //override setting use user_setting $customizable = array(); if (count($data)) { foreach ($data as $i => $row) { /** var CActiveRecord $row */ if ($row->customizable) { //load data from user_setting $custom = UserSetting::model()->findByAttributes(array('param_name' => $row->name, 'user_id' => Yii::app()->user->id)); if (is_object($custom)) { $data[$i]->value = $custom->value; } else { $custom = new UserSetting(); $custom->user_id = Yii::app()->user->id; $custom->param_name = $row->name; } $customizable[] = $custom; } } } $paramForm = $this->createWidget('Admin.components.ParamForm', array('params' => $data, 'config' => null)); //TODO: load module param definitions into $config // save new values if (Yii::app()->request->IsPostRequest) { //save User Settings to user_setting if (is_array($customizable) && count($customizable)) { foreach ($customizable as $custom) { if ($custom instanceof UserSetting && isset($_POST[$custom->param_name])) { $custom->value = $_POST[$custom->param_name]; if (!$custom->save()) { Yii::log(CVarDumper::dumpAsString($custom->getErrors()), CLogger::LEVEL_ERROR, 'Admin.Setting'); } //force not save global setting unset($_POST[$custom->param_name]); } } } $paramForm->saveParams($_POST, ParamForm::TO_SETTING_TABLE); //update Settings Class if ($currentWorkflow->id == $workflowId && isset($_POST['SettingParam'], $_POST['SettingParam']['module'])) { $module = $_POST['SettingParam']['module']; if ($module == 'module_system') { $module = ''; } $this->api('Xpress.Settings.db2php', array('module' => $module)); } //update parameters to global and other workflows foreach ($paramForm->params as $param) { if (isset($_POST['sync_global'])) { $this->api('Xpress.SettingParam.syncValue', array('attrs' => $param->attributes)); //update cache file global $this->api('Xpress.Settings.db2php', array('module' => $param->module, 'path' => cachePath(true))); } if (isset($_POST['sync_other'])) { $this->api('Xpress.SettingParam.syncValueToOther', array('attrs' => $param->attributes)); } } //TODO: need fix validate in ParamForm //errorHandler()->getErrorMessages(); } $this->render('index', array('modules' => $modules, 'module' => $model->module, 'form' => $paramForm, 'workflowId' => $workflowId, 'workflows' => $workflows)); }
/** * Disables a module * * Which means delete all (user-) data created by the module. * */ public function disable() { if (!$this->isEnabled() || $this->isCoreModule) { return false; } // Check this module is a SpaceModule if ($this->isSpaceModule()) { foreach ($this->getSpaceModuleSpaces() as $space) { $space->disableModule($this->getId()); } } // Check this module is a UserModule if ($this->isUserModule()) { foreach ($this->getUserModuleUsers() as $user) { $user->disableModule($this->getId()); } } // Disable module in database $moduleEnabled = ModuleEnabled::model()->findByPk($this->getId()); if ($moduleEnabled != null) { $moduleEnabled->delete(); } HSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); SpaceSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); UserSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); // Delete also records with disabled state from SpaceApplicationModule Table foreach (SpaceApplicationModule::model()->findAllByAttributes(array('module_id' => $this->getId())) as $sam) { $sam->delete(); } // Delete also records with disabled state from UserApplicationModule Table foreach (UserApplicationModule::model()->findAllByAttributes(array('module_id' => $this->getId())) as $uam) { $uam->delete(); } ModuleManager::flushCache(); return true; }
/** * * @param string $key Key of the setting * @return \UserSetting Users setting for the specified key */ public function getSettingByKey($key) { return UserSetting::getByUserID($this->id, $key); }