/** * Get the resolved profile link for a given user * * @param UserModel $user * @return string */ public static function ResolveProfileLink(UserModel $user) { if ($user->get('username')) { return \Core\resolve_link('/userprofile/view/' . $user->get('username')); } else { return \Core\resolve_link('/userprofile/view/' . $user->get('id')); } }
protected function _formatArchive($archives) { $ret = array(); if ($archives) { $departmentList = $this->_departmentList(); if (isset($archives[0]) && is_array($archives[0])) { $authorIds = array(); foreach ($archives as $archive) { $authorIds[] = $archive['author']; } $authors = UserModel::getByUids($authorIds); foreach ($archives as $key => $archive) { $author = $authors[$archive['author']]; $archive['author'] = $author; $archive['department'] = $departmentList[$author['department_id']]; $archive['catalog'] = $this->catalogList[$archive['catalog_id']]; $ret[] = $archive; } } else { $author = UserModel::get($archives['author']); $archives['author'] = $author; $archives['department'] = $departmentList[$author['department_id']]; $archives['catalog'] = $this->catalogList[$archives['catalog_id']]; $ret = $archives; } } return $ret; }
public function getDisplayName() { if ($this->user_id) { $user = UserModel::get($this->user_id); return $user->getDisplayName(); } else { return $this->name; } }
public function listAction() { $param['page'] = $this->getLegalParam('page', 'int'); $model = new UserModel(); $result = $model->get(1); //var_dump($result); //var_dump($model); $this->assign('user_list', $result); //$this->render('user/list.phtml'); }
public function index($args) { //var_dump(func_get_args()); print_r($args); $user = new UserModel(); /*$user->insert('user', array( 'username' => 'chipolata', 'passwd' => 'shit happens', 'role' => 0 ));*/ $user->select('uid'); var_dump($user->get(1)); }
function createComponent($name) { switch ($name) { case 'userTabella': $model = new UserModel(); $grid = new Tabella($model->getFluent(false)->toDatasource(), array('sorting' => 'desc', 'order' => 'id_gui_user')); $grid->addColumn("Login/Email", "login", array("width" => 100)); $grid->addColumn("Meno", "name", array("width" => 100)); $grid->addColumn("Priezvisko", "surname", array("width" => 100)); $grid->addColumn("Naposledy prihlásený", "lastvisit", array("width" => 100)); $grid->addColumn("", "", array("width" => 30, 'filter' => NULL, "options" => '', "renderer" => function ($row) { $el = NHtml::el("td"); /* * link na zmazanie produktu */ $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('deleteUser!', array('id' => $row->id_gui_user)))->addClass('deleteIcon ajax')); /* * link na editaciu produktu */ $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('edit', array('id' => $row->id_gui_user)))->addClass('editIcon')); /* * ikona aktivan polozka, neaktivan polozka */ $span = NHtml::el('span'); if ($row->activate) { $span->addClass('activeIcon active'); } else { $span->addClass('unactiveIcon active '); } $el->add($span); return $el; })); $this->addComponent($grid, $name); break; case 'userForm': $form = UserModel::baseForm(false); $form->addGroup(''); $form->addText('discount', 'Zľava použivateľa'); $form->addHidden('id'); $form->addSubmit('btn_submit', 'Uložiť'); $form->onSuccess[] = array($this, 'saveUser'); $form->setDefaults(UserModel::get($this->getParam('id'))); return $form; break; default: return parent::createComponent($name); break; } }
function login() { $uname = request('uname'); $passwd = request('passwd'); if (false == ($uname && $passwd)) { $this->ajaxError('用户名或者密码没有填写'); } //echo mymd5($passwd); $user = UserModel::get('', $uname); if (!$user) { $this->ajaxError('用户不存在'); } if ($user['passwd'] != mymd5($passwd)) { $this->ajaxError('密码不正确'); } $_SESSION['user'] = $user; $this->ajaxSuccess($user); }
/** * Set the current session to be owned by the given user, * effectively logging the user in. * * Drop support for the User class in favour of UserModel after pre-2.8.x is no longer supported. * * @param \UserModel $u */ public static function SetUser($u) { $model = self::_GetModel(session_id()); $model->set('user_id', $u->get('id')); $model->save(); // If this user is currently SUDO, then set the SUDO'd user and NOT the actual user. if(isset($_SESSION['user_sudo'])){ Session::Set('user_sudo', $u); } else{ Session::Set('user', $u); } }
} catch (\Exception $e) { //测试插入冲突 echo "\r\n"; echo $e->getMessage(); } //测试忽略冲突 $user->save(YZE_SQL::INSERT_ON_DUPLICATE_KEY_IGNORE); echo "\r\n"; echo $user->get_key() ? "ignore false" : "ignore true"; //测试冲突是更新 $user->set("name", "aaaa"); $user->save(YZE_SQL::INSERT_ON_DUPLICATE_KEY_UPDATE); echo "\r\n"; echo $insert_key == $user->get_key() ? "UPDATE true" : "UPDATE false"; echo "\r\n"; echo $user->get("name") == "aaaa" ? "UPDATE true" : "UPDATE false"; //测试删除原来的,插入新的 $user->save(YZE_SQL::INSERT_ON_DUPLICATE_KEY_REPLACE); echo "\r\n"; echo $insert_key + 1 == $user->get_key() ? "REPLACE true" : "REPLACE false"; $insert_key += 1; //测试存在时添加 $user1 = new UserModel(); $user1->set("name", "aa"); $user1->set("register_time", "2015-12-17 17:50:30"); $sql = new \yangzie\YZE_SQL(); $sql->from("\\yangzie\\UserModel", "u")->where("u", "name", \yangzie\YZE_SQL::EQ, "aaaa"); $user1->set("email", "1234"); $user1->save(YZE_SQL::INSERT_EXIST, $sql); echo "\r\n"; echo $user1->get_key() && $user1->Get("email") == "1234" ? "INSERT_EXIST true" : "INSERT_EXIST false";
public function register(array $me) { $last_id = UserModel::insert(array('login' => $me['email'], 'fbuid' => $me['id'], 'name' => $me['first_name'], 'surname' => $me['last_name'], 'activate' => 1, 'password' => Tools::random(12), 'newsletter' => 0, 'iso' => 'SVK')); return UserModel::get($last_id); }
public function profile() { if (in_array(Auth::getCapability(), array(CAPABILITY_ADMINISTRATOR))) { Model::autoloadModel('User'); $model = new UserModel($this->db); $this->para = new stdClass(); $this->para->user_id = Session::get('user_id'); if (isset($this->para->user_id)) { $this->view->userBO = $model->get($this->para->user_id); $this->view->renderAdmin(RENDER_VIEW_USER_INFO); } else { header('location: ' . URL . CONTEXT_PATH_USER_EDIT); } } else { $this->login(); } }
public function getUserInfo($id) { return $this->userDao->get('*', ['id' => $id]); }
static function publicShow($uid) { return self::format(UserModel::get($uid), 'public'); }
/** * Send the commands to a user to verify they have access to the provided GPG key. * * @param \UserModel $user * @param string $fingerprint * @param boolean $cli Set to false to send non-CLI instructions. * * @return false|string */ public static function SendVerificationEmail(\UserModel $user, $fingerprint, $cli = true){ $sentence = trim(\BaconIpsumGenerator::Make_a_Sentence()); $nonce = \NonceModel::Generate( '30 minutes', null, [ 'sentence' => $sentence, 'key' => $fingerprint, 'user' => $user->get('id'), ] ); $key = $user->get('apikey'); $url = \Core\resolve_link('/gpgauth/rawverify'); if($cli){ $cmd = <<<EOD echo -n "{$sentence}" \\ | gpg -b -a --default-key $fingerprint \\ | curl --data-binary @- \\ --header "X-Core-Nonce-Key: $nonce" \\ $url EOD; } else{ $cmd = <<<EOD echo -n "{$sentence}" | gpg -b -a EOD; } $email = new \Email(); $email->templatename = 'emails/user/gpgauth_key_verification.tpl'; $email->setSubject('GPG Key Change Request'); $email->assign('key', $fingerprint); $email->assign('sentence', $sentence); $email->assign('user', $user); $email->assign('cmd', $cmd); $email->to($user->get('email')); $email->setEncryption($fingerprint); \SystemLogModel::LogSecurityEvent('/user/gpg/submit', 'Verification requested for key ' . $fingerprint, null, $user->get('id')); if(!$email->send()){ return false; } else{ return $nonce; } }
function saveProfil(NFORM $form) { $values = $form->getValues(); $data = $this->user->getIdentity()->data; // print_r($data);exit; $user = UserModel::getFluent(false)->where(' login = %s', $values['login'], "AND login != %s", $data['login'])->fetch(); try { if ($user and $user['login'] == $values['login']) { throw new InvalidStateException(_('Uživateľ pod týmto prihlasovacím meno už existuje.')); } // if($user AND $user['email'] == $values['email']) // throw new InvalidStateException( _('Emailová adresa sa už nachádza v databáze. ') ); // unset($values['passwordCheck']); unset($values['terms_and_conditions']); //ak nevyplni heslo, zostava stare if ($values['password'] == '') { unset($values['password']); } UserModel::update($data['id'], $values); $values = UserModel::get($data['id']); // $this->user->getIdentity()->updating(); foreach ($values as $key => $value) { // zmenime to i v aktualni identite, aby se nemusel prihlasovat znovu $this->user->getIdentity()->{$key} = $value; } $this->flashMessage("Váš profil bol aktualizovaný."); $this->redirect('this'); } catch (InvalidStateException $e) { $form->addError($e->getMessage()); // throw $e; } }
/** * Called from the /user/postsave hook with the one argument of the UserModel. * * @param \UserModel $user * @return bool */ public static function ForceSessionSync(\UserModel $user){ // BEFORE I do this, cleanup any old sessions! Session::CleanupExpired(); $me = (\Core\user() && \Core\user()->get('id') == $user->get('id')); foreach(\SessionModel::Find(['user_id = ' . $user->get('id')]) as $sess){ /** @var \SessionModel $sess */ if($me && $sess->get('session_id') == session_id()){ // It's this current session! // Reload this user object :) // Remember, the external data cannot be set from within the same session! Session::SetUser($user); continue; } $dat = $sess->getExternalData(); $dat['user_forcesync'] = true; $sess->setExternalData($dat); $sess->save(); } return true; }
public function edit($id = '') { if (!$id) { $id = request('id'); } if (isset($_POST['id'])) { $uname = request('uname'); $user = UserModel::get('', $uname); if ($user && $user['id'] != $id) { $this->error('用户名重复'); } $passwd = request('passwd'); if ($passwd) { if ($passwd != request('passwd2')) { $this->error('两次输入的密码不一致'); } $data['passwd'] = mymd5($passwd); } if ($GLOBALS['method'] != 'my') { $data['group_id'] = request('group_id'); $data['department_id'] = request('department_id'); } $data['alias'] = request('alias'); $data['uname'] = request('uname'); $data['phone'] = request('phone'); if (UserModel::update($id, $data)) { $this->success(request('reffer')); } else { $this->error('更新失败'); } } else { $user = UserModel::get($id); if (!$user) { $this->error('用户不存在'); } $this->assign('user', $user); $this->display('user_edit'); } }
/** * View to accept and process the FB login post. * * This will redirect to the registration page if the user doesn't exist, * will throw an error and display a link to enable FB if it's not enabled already, * or will simply log the user in via Facebook and sync his/her settings. */ public function login() { $view = $this->getView(); $request = $this->getPageRequest(); $view->ssl = true; $view->record = false; $auths = \Core\User\Helper::GetEnabledAuthDrivers(); if (!isset($auths['facebook'])) { // Facebook isn't enabled, simply redirect to the home page. \Core\redirect('/'); } if (!FACEBOOK_APP_ID) { \Core\redirect('/'); } if (!FACEBOOK_APP_SECRET) { \Core\redirect('/'); } if (!$request->isPost()) { return View::ERROR_BADREQUEST; } $facebook = new Facebook(['appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_SECRET]); // Did the user submit the facebook login request? if (isset($_POST['login-method']) && $_POST['login-method'] == 'facebook' && $_POST['access-token']) { try { $facebook->setAccessToken($_POST['access-token']); /** @var int $fbid The user ID from facebook */ $fbid = $facebook->getUser(); /** @var array $user_profile The array of user data from Facebook */ $user_profile = $facebook->api('/me'); } catch (Exception $e) { \Core\set_message($e->getMessage(), 'error'); \Core\go_back(); return null; } /** @var \UserModel|null $user */ $user = UserModel::Find(['email' => $user_profile['email']], 1); if (!$user) { if (ConfigHandler::Get('/user/register/allowpublic')) { // If public registration is enabled, then redirect the user to the registration page to complete their registration. $user = new UserModel(); $user->set('email', $user_profile['email']); $user->enableAuthDriver('facebook'); $user->disableAuthDriver('datastore'); /** @var \Facebook\UserAuth $auth */ $auth = $user->getAuthDriver('facebook'); $auth->syncUser($_POST['access-token']); // Otherwise, w00t! Record this user into a nonce and forward to step 2 of registration. $nonce = NonceModel::Generate('20 minutes', null, ['user' => $user, 'redirect' => $_POST['redirect']]); \Core\redirect('/user/register2/' . $nonce); } else { // Log this as a login attempt! $logmsg = 'Failed Login (Facebook). Email not registered' . "\n" . 'Email: ' . $user_profile['email'] . "\n"; \SystemLogModel::LogSecurityEvent('/user/login', $logmsg); \Core\set_message('Your Facebook email (' . $user_profile['email'] . ') does not appear to be registered on this site.', 'error'); \Core\go_back(); return null; } } elseif (!$user->get('active')) { // The model provides a quick cut-off for active/inactive users. // This is the control managed with in the admin. $logmsg = 'Failed Login. User tried to login before account activation' . "\n" . 'User: '******'email') . "\n"; \SystemLogModel::LogSecurityEvent('/user/login', $logmsg, null, $user->get('id')); \Core\set_message('Your account is not active yet.', 'error'); \Core\go_back(); return null; } try { /** @var \Facebook\UserAuth $auth */ $auth = $user->getAuthDriver('facebook'); } catch (Exception $e) { \Core\set_message('Your account does not have Facebook logins enabled! <a href="' . \Core\resolve_link('/facebook/enable') . '">Do you want to enable Facebook?</a>', 'error'); \Core\go_back(); return null; } if (!$user->isActive()) { \Core\set_message('Your account is not active!', 'error'); \Core\go_back(); return null; } // Well yay the user is available and authencation driver is ready! $auth->syncUser($_POST['access-token']); if ($_POST['redirect']) { // The page was set via client-side javascript on the login page. // This is the most reliable option. $url = $_POST['redirect']; } elseif (REL_REQUEST_PATH == '/facebook/login') { // If the user came from the registration page, get the page before that. $url = '/'; } else { // else the registration link is now on the same page as the 403 handler. $url = REL_REQUEST_PATH; } // Well, record this too! \SystemLogModel::LogSecurityEvent('/user/login', 'Login successful (via Facebook)', null, $user->get('id')); // yay... $user->set('last_login', \CoreDateTime::Now('U', \Time::TIMEZONE_GMT)); $user->save(); \Core\Session::SetUser($user); // Allow an external script to override the redirecting URL. $overrideurl = \HookHandler::DispatchHook('/user/postlogin/getredirecturl'); if ($overrideurl) { $url = $overrideurl; } \Core\redirect($url); } else { \Core\go_back(); } }
public function changeAdvSetting($para) { $action = NULL; if (isset($para->internalflights_per_page) && is_numeric($para->internalflights_per_page)) { $this->updateInternalflightsPerPages($para->internalflights_per_page); } $description_show = false; $slug_show = false; $tours_show = false; if (isset($para->description_show) && $para->description_show == "description") { $description_show = true; } if (isset($para->slug_show) && $para->slug_show == "slug") { $slug_show = true; } if (isset($para->tours_show) && $para->tours_show == "tours") { $tours_show = true; } $this->updateColumnsShow($description_show, $slug_show, $tours_show); Model::autoloadModel('user'); $userModel = new UserModel($this->db); $userBO = $userModel->get(Session::get("user_id")); $userModel->setNewSessionUser($userBO); }
/** * Import the given data into the destination Model. * * @param array $data Indexed array of records to import/merge from the external source. * @param array $options Any options required for the import, such as merge, key, etc. * @param boolean $output_realtime Set to true to output the log in real time as the import happens. * * @throws Exception * * @return \Core\ModelImportLogger */ public static function Import($data, $options, $output_realtime = false) { $log = new \Core\ModelImportLogger('User Importer', $output_realtime); $merge = isset($options['merge']) ? $options['merge'] : true; $pk = isset($options['key']) ? $options['key'] : null; if(!$pk) { throw new Exception( 'Import requires a "key" field on options containing the primary key to compare against locally.' ); } // Load in members from the group // Set the default group on new accounts, if a default is set. $defaultgroups = \UserGroupModel::Find(["default = 1"]); $groups = []; $gnames = []; foreach($defaultgroups as $g) { /** @var \UserGroupModel $g */ $groups[] = $g->get('id'); $gnames[] = $g->get('name'); } if(sizeof($groups)) { $log->log('Found ' . sizeof($groups) . ' default groups for new users: ' . implode(', ', $gnames)); } else { $log->log('No groups set as default, new users will not belong to any groups.'); } $log->log('Starting ' . ($merge ? '*MERGE*' : '*skipping*' ) . ' import of ' . sizeof($data) . ' users'); foreach($data as $dat) { if(isset($dat[$pk])){ // Only check the information if the primary key is set on this record. if($pk == 'email' || $pk == 'id') { // These are the only two fields on the User object itself. $user = UserModel::Find([$pk . ' = ' . $dat[ $pk ]], 1); } else { $uucm = UserUserConfigModel::Find(['key = ' . $pk, 'value = ' . $dat[ $pk ]], 1); if($uucm) { $user = $uucm->getLink('UserModel'); } else { // Try the lookup from the email address instead. // This will force accounts that exist to be synced up correctly. // The only caveat to this is that users will not be updated with the foreign key if merge is disabled. $user = UserModel::Find(['email = ' . $dat['email']], 1); } } } else{ $user = null; } $status_type = $user ? 'Updated' : 'Created'; if($user && !$merge) { $log->duplicate('Skipped user ' . $user->getLabel() . ', already exists and merge not requested'); // Skip to the next record. continue; } if(!$user) { // All incoming users must have an email address! if(!isset($dat['email'])) { $log->error('Unable to import user without an email address!'); // Skip to the next record. continue; } // Meta fields that may or may not be present, but should be for reporting purposes. if(!isset($dat['registration_ip'])) { $dat['registration_ip'] = REMOTE_IP; } if(!isset($dat['registration_source'])) { $dat['registration_source'] = \Core\user()->exists() ? 'admin' : 'self'; } if(!isset($dat['registration_invitee'])) { $dat['registration_invitee'] = \Core\user()->get('id'); } // New user! $user = new UserModel(); } // No else needed, else is there IS a valid $user object and it's setup ready to go. // Handle all the properties for this user! foreach($dat as $key => $val){ if($key == 'avatar' && strpos($val, '://') !== false){ // Sync the user avatar. $log->actionStart('Downloading ' . $dat['avatar']); $f = new \Core\Filestore\Backends\FileRemote($dat['avatar']); $dest = \Core\Filestore\Factory::File('public/user/avatar/' . $f->getBaseFilename()); if($dest->identicalTo($f)) { $log->actionSkipped(); } else { $f->copyTo($dest); $user->set('avatar', 'public/user/avatar/' . $dest->getBaseFilename()); $log->actionSuccess(); } } elseif($key == 'profiles' && is_array($val)) { $new_profiles = $val; // Pull the current profiles from the account $profiles = $user->get('external_profiles'); if($profiles && is_array($profiles)) { $current_flat = []; foreach($profiles as $current_profile) { $current_flat[] = $current_profile['url']; } // Merge in any *actual* new profile foreach($new_profiles as $new_profile) { if(!in_array($new_profile['url'], $current_flat)) { $profiles[] = $new_profile; } } unset($new_profile, $new_profiles, $current_flat, $current_profile); } else { $profiles = $new_profiles; unset($new_profiles); } $user->set('external_profiles', $profiles); } elseif($key == 'backend'){ // Was a backend requested? // This gets merged instead of replaced entirely. $user->enableAuthDriver($val); } elseif($key == 'groups'){ $user->setGroups($val); } else{ // Default Behaviour, // save the key into whatever field it was set to go to. $user->set($key, $val); } } try { // Set the default groups loaded from the system. if(!$user->exists()){ $user->setGroups($groups); } $status = $user->save(); } catch(Exception $e) { $log->error($e->getMessage()); // Skip to the next. continue; } if($status) { $log->success($status_type . ' user ' . $user->getLabel() . ' successfully!'); } else { $log->skip('Skipped user ' . $user->getLabel() . ', no changes detected.'); } } $log->finalize(); return $log; }