/** * Check If The Current Session Is Legit * * @param none * @return bool * @access public */ public function getSessionValidity() { if (!empty($this->username)) { $credentials = $this->decryptSessionCredentials(); // Level 1 if ($credentials['username'] == $this->username && $credentials['key'] == $this->auth_key && $credentials['token'] == session_id()) { // Level 2 $dbh = Core_DBH::getDBH(); // Fetch information from the database $sth = $dbh->prepare("\n\t\t\t\t\tSELECT username, last_ip, token\n\t\t\t\t\tFROM " . DB_PREFIX . "user\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tuser_id = :user_id\n\t\t\t\t\t;"); $sth->bindParam(':user_id', $this->session['INFORMATION']['id']); $sth->execute(); $userResult = $sth->fetchAll(PDO::FETCH_ASSOC); // Verify if ($userResult[0]['username'] == $this->username && $userResult[0]['last_ip'] == $_SERVER['REMOTE_ADDR'] && $userResult[0]['token'] == session_id()) { // Update User Activity on page request $last_activity = date('Y-m-d H:i:s'); $sth = $dbh->prepare("\n\t\t\t\t\t\tUPDATE " . DB_PREFIX . "user\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tlast_activity\t= :last_activity\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tuser_id\t\t\t= :user_id\n\t\t\t\t\t\t;"); $uid = Core_AuthService::getSessionInfo('ID'); $sth->bindParam(':last_activity', $last_activity); $sth->bindParam(':user_id', $uid); $sth->execute(); return TRUE; } else { return FALSE; } } } return FALSE; }
<!-- SCRIPT --> <?php /** * Generate AngularJS Code * * @param String $task * @param String $schema * @param String $form * @param String $model * @param String $redirect */ // Schema Definition $schema = "\n{\n\ttype: 'object',\n\tproperties: {\n\t\tusername: {\n\t\t\ttitle: '" . T_('Login') . "',\n\t\t\ttype: 'string'\n\t\t},\n\t\tpassword0: {\n\t\t\ttitle: '" . T_('Password') . "',\n\t\t\ttype: 'string'\n\t\t},\n\t\tpassword1: {\n\t\t\ttitle: '" . T_('Confirm Password') . "',\n\t\t\ttype: 'string'\n\t\t},\n\t\tfirstname: {\n\t\t\ttitle: '" . T_('First Name') . "',\n\t\t\ttype: 'string'\n\t\t},\n\t\tlastname: {\n\t\t\ttitle: '" . T_('Last Name') . "',\n\t\t\ttype: 'string'\n\t\t},\n\t\temail: {\n\t\t\ttitle: '" . T_('Email') . "',\n\t\t\ttype: 'string'\n\t\t},\n\t\tlanguage: {\n\t\t\ttitle: '" . T_('Language') . "',\n\t\t\ttype: 'string'\n\t\t},\n\t\ttemplate: {\n\t\t\ttitle: '" . T_('Template') . "',\n\t\t\ttype: 'string'\n\t\t}\n\t},\n\t'required': [\n\t\t'username',\n\t\t'password0',\n\t\t'password1',\n\t\t'email',\n\t\t'language'\n\t]\n}"; // Form Definition $form = "\n[\n\t{\n\t\t'key': 'username',\n\t\t'type': 'text',\n\t\tfieldAddonLeft: '<span class=\"glyphicon glyphicon-user\"></span>',\n\t\tplaceholder: '" . T_('Login') . "'\n\t},\n\t{\n\t\t'key': 'password0',\n\t\t'type': 'password',\n\t\tfieldAddonLeft: '<span class=\"glyphicon glyphicon-lock\"></span>',\n\t\tplaceholder: '" . T_('Password') . "'\n\t},\n\t{\n\t\t'key': 'password1',\n\t\t'type': 'password',\n\t\tfieldAddonLeft: '<span class=\"glyphicon glyphicon-lock\"></span>',\n\t\tplaceholder: '" . T_('Password') . "'\n\t},\n\t{\n\t\t'key': 'firstname',\n\t\t'type': 'text',\n\t\tfieldAddonLeft: 'Optional'\n\t},\n\t{\n\t\t'key': 'lastname',\n\t\t'type': 'text',\n\t\tfieldAddonLeft: 'Optional'\n\t},\n\t{\n\t\t'key': 'email',\n\t\t'type': 'email',\n\t\tfieldAddonLeft: '<span class=\"glyphicon glyphicon-envelope\"></span>',\n\t\tplaceholder: '" . T_('Email') . "'\n\t},\n\t{\n\t\t'key': 'language',\n\t\t'type': 'select',\n\t\ttitleMap: " . $langMap . "\n\t},\n\t{\n\t\t'key': 'template',\n\t\t'type': 'select',\n\t\ttitleMap: " . $templateMap . "\n\t}\n]"; // Model Init $model = json_encode(array('username' => htmlspecialchars($profile['username'], ENT_QUOTES), 'password0', 'password1', 'firstname' => htmlspecialchars($profile['firstname'], ENT_QUOTES), 'lastname' => htmlspecialchars($profile['lastname'], ENT_QUOTES), 'email' => htmlspecialchars($profile['email'], ENT_QUOTES), 'language' => htmlspecialchars(Core_AuthService::getSessionInfo('LANG'), ENT_QUOTES), 'template' => htmlspecialchars($profile['template'], ENT_QUOTES)), JSON_FORCE_OBJECT); $js->getAngularCode('updateUserConfig', $schema, $form, $model); ?> <!-- END: SCRIPT --> <?php //------------------------------------------------------------------------------------------------------------+ /** * END: PAGE BODY */ /** * Build Page Footer */ $gui->getFooter();
/** * Update User Configuration * * @param string $username * @param string $password0 * @param string $password1 * @param string $email * @param string $language * @param optional string $firstname * @param optional string $lastname * @param optional string $template * * @author Nikita Rousseau */ public function updateUserConfig($username, $password0, $password1, $email, $language, $firstname = '', $lastname = '', $template = 'bootstrap.min.css') { $form = array('username' => $username, 'password0' => $password0, 'password1' => $password1, 'email' => $email, 'language' => $language, 'template' => $template); $errors = array(); // array to hold validation errors $data = array(); // array to pass back data $dbh = Core_DBH::getDBH(); // Get Database Handle // Get languages $languages = parse_ini_file(CONF_LANG_INI); $languages = array_flip(array_values($languages)); // Get templates $templates = parse_ini_file(CONF_TEMPLATES_INI); $templates = array_flip(array_values($templates)); // validate the variables ====================================================== $v = new Valitron\Validator($form); $rules = ['required' => [['username'], ['password0'], ['password1'], ['email'], ['language']], 'alphaNum' => [['username']], 'lengthMin' => [['username', 4], ['password0', 8]], 'equals' => [['password0', 'password1']], 'email' => [['email']], 'in' => [['language', $languages], ['template', $templates]]]; $labels = array('username' => T_('Username'), 'password0' => T_('Password'), 'password1' => T_('Confirmation Password'), 'email' => T_('Email'), 'language' => T_('Language'), 'template' => T_('Template')); $v->rules($rules); $v->labels($labels); $v->validate(); $errors = $v->errors(); // Apply ======================================================================= if (empty($errors)) { // Database update $db_data['username'] = $form['username']; $db_data['password'] = Core_AuthService::getHash($form['password0']); $db_data['email'] = $form['email']; $db_data['lang'] = $form['language']; if (!empty($firstname)) { $db_data['firstname'] = $firstname; } if (!empty($lastname)) { $db_data['lastname'] = $lastname; } if ($template != 'bootstrap.min.css') { $db_data['template'] = $template; } $authService = Core_AuthService::getAuthService(); $uid = Core_AuthService::getSessionInfo('ID'); foreach ($db_data as $key => $value) { try { $sth = $dbh->prepare("\tUPDATE " . DB_PREFIX . "user\n\t\t\t\t\t\t\t\t\t\t\tSET " . $key . " = :" . $key . "\n\t\t\t\t\t\t\t\t\t\t\tWHERE user_id = '" . $uid . "';"); $sth->bindParam(':' . $key, $value); $sth->execute(); } catch (PDOException $e) { echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine(); die; } } // Reload Session $authService->rmSessionInfo(); $authService->setSessionInfo($uid, $db_data['username'], $db_data['firstname'], $db_data['lastname'], $db_data['lang'], $db_data['template']); $authService->setSessionPerms(); $this->rmCookie('LANG'); } // return a response and log =================================================== $logger = self::getLogger(); // response if there are errors if (!empty($errors)) { // if there are items in our errors array, return those errors $data['success'] = false; $data['errors'] = $errors; $data['msgType'] = 'warning'; $data['msg'] = T_('Bad Settings!'); $logger->info('Failed to update user configuration.'); } else { $data['success'] = true; $logger->info('Updated user configuration.'); } // return all our data to an AJAX call return $data; }
</form> </div> </div> </div> </div> <!-- END: CONTENTS --> <!-- SCRIPT --> <?php /** * Generate AngularJS Code * @arg $task * @arg $inputs * @arg $redirect */ $fields = array('username' => htmlspecialchars($profile['username'], ENT_QUOTES), 'password0', 'password1', 'firstname' => htmlspecialchars($profile['firstname'], ENT_QUOTES), 'lastname' => htmlspecialchars($profile['lastname'], ENT_QUOTES), 'email' => htmlspecialchars($profile['email'], ENT_QUOTES), 'language' => htmlspecialchars(Core_AuthService::getSessionInfo('LANG'), ENT_QUOTES)); $js->getAngularController('updateUserConfig', $fields, './'); ?> <!-- END: SCRIPT --> <?php //------------------------------------------------------------------------------------------------------------+ /** * END: PAGE BODY */ /** * Build Page Footer */ $gui->getFooter(); // Clean Up unset($module, $gui, $js);