Added enable feature and removed ajax call in profile.php

This commit is contained in:
Mark Pemberton 2011-02-27 00:37:14 -05:00
parent 7109719b5c
commit 2a4e91f8f3
7 changed files with 79 additions and 35 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
dist/
build.properties
package.xml
.project
html.properties
.buildpath
.settings

View File

@ -31,8 +31,8 @@ $this->includeTemplate($GLOBALS['top_include']);
<td>&larr; <?php echo T_('Required'); ?></td>
</tr>
<tr>
<th align="left"><?php echo T_('Private Key (for RSS)'); ?></th>
<td><input type="text" id="pPrivateKey" name="pPrivateKey" size="40" value="<?php echo filter($objectUser->getPrivateKey(), 'xml'); ?>" readonly /><input type="button" value="Generate New Key" onClick="getNewPrivateKey(this,null)" /></td>
<th align="left"><?php echo T_('Private RSS Feed'); ?></th>
<td><input type="checkbox" id="pEnablePrivateKey" name="pEnablePrivateKey" value="1" <?php if ($objectUser->getEnablePrivateKey()==1) echo 'checked="checked"'; ?>><?php echo T_('Enable'); ?>&nbsp;&nbsp;&nbsp;<input type="text" id="pPrivateKey" name="pPrivateKey" size="40" value="<?php echo $privateKey;?>" readonly /><input type="submit" name="submittedPK" value="<?php echo T_('Generate New Key'); ?>" /></td>
</tr>
</table>

View File

@ -36,12 +36,13 @@ class SemanticScuttle_Model_User
var $datetime;
var $isAdmin;
var $privateKey;
var $enablePrivateKey;
/**
* Create a new user object
*
* @param integer $id User ID
* @param string $username Username
* @param integer $id User ID
* @param string $username Username
*/
public function __construct($id, $username)
{
@ -85,6 +86,22 @@ class SemanticScuttle_Model_User
return $this->privateKey;
}
/**
* Returns private key flag
*
* @return integer private key 1=enabled, 0=disabled
*/
public function getEnablePrivateKey()
{
// Look for value only if not already set
if (!isset($this->enablePrivateKey)) {
$us = SemanticScuttle_Service_Factory::get('User');
$user = $us->getUser($this->id);
$this->enablePrivateKey = $user['enablePrivateKey'];
}
return $this->enablePrivateKey;
}
/**
* Returns full user name as specified in the profile.
*

View File

@ -789,21 +789,23 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* No checks are done in here - you ought to have checked
* everything before calling this method!
*
* @param string $username Username to use
* @param string $password Password to use
* @param string $email Email to use
* @param string $privateKey Key for RSS auth
* @param string $username Username to use
* @param string $password Password to use
* @param string $email Email to use
* @param string $privateKey Key for RSS auth
* @param integer $enablePrivateKey Flag to enable Private RSS
*
* @return mixed Integer user ID if all is well,
* boolean false if an error occured
*/
public function addUser($username, $password, $email, $privateKey = null)
{
public function addUser(
$username, $password, $email, $privateKey=null, $enablePrivateKey=0
) {
// Set up the SQL UPDATE statement.
$datetime = gmdate('Y-m-d H:i:s', time());
$password = $this->sanitisePassword($password);
// set new private key if null
if ($privateKey == null) {
// set new private key if enabled but user forgot to generate
if ($enablePrivateKey == 1) {
$privateKey = $this->getNewPrivateKey();
}
$values = array(
@ -812,7 +814,8 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
'email' => $email,
'uDatetime' => $datetime,
'uModified' => $datetime,
'privateKey' => $privateKey
'privateKey' => $privateKey,
'enablePrivateKey' => $enablePrivateKey
);
$sql = 'INSERT INTO '. $this->getTableName()
. ' '. $this->db->sql_build_array('INSERT', $values);
@ -836,18 +839,20 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
/**
* Update User Record
*
* @param string $uId User ID
* @param string $password User Password
* @param string $name User Name
* @param string $email Email Address
* @param string $homepage Homepage URL
* @param string $uContent Content
* @param string $privateKey RSS Private Key
* @param string $uId User ID
* @param string $password User Password
* @param string $name User Name
* @param string $email Email Address
* @param string $homepage Homepage URL
* @param string $uContent Content
* @param string $privateKey RSS Private Key
* @param integer $enablePrivateKey Flag to enable RSS Private Key
*
* @return boolean true if it successful, false if not
*/
function updateUser(
$uId, $password, $name, $email, $homepage, $uContent, $privateKey = null
$uId, $password, $name, $email, $homepage, $uContent,
$privateKey=null, $enablePrivateKey=0
) {
if (!is_numeric($uId)) {
return false;
@ -859,12 +864,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$updates = array (
'uModified' => $moddatetime, 'name' => $name,
'email' => $email, 'homepage' => $homepage,
'uContent' => $uContent, 'privateKey' => $privateKey);
'uContent' => $uContent, 'privateKey' => $privateKey,
'enablePrivateKey' => $enablePrivateKey);
} else {
$updates = array ('uModified' => $moddatetime,
'password' => $this->sanitisePassword($password),
'name' => $name, 'email' => $email, 'homepage' => $homepage,
'uContent' => $uContent, 'privateKey' => $privateKey);
'uContent' => $uContent, 'privateKey' => $privateKey,
'enablePrivateKey' => $enablePrivateKey);
}
$sql = 'UPDATE '. $this->getTableName() .' SET '
. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '

View File

@ -258,14 +258,16 @@ if ($templatename == 'editbookmark.tpl') {
createURL('rss', filter($user, 'url') . $rssCat.'?sort='.getSortOrder())
)
);
if ($currentUser->getPrivateKey() <> null) {
array_push(
$tplVars['rsschannels'],
array(
filter($sitename . sprintf(T_(': (private) ')) . $pagetitle),
createURL('rss', filter($user, 'url') . $rssCat.'?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
)
);
if ($userservice->isLoggedOn()) {
if ($currentUser->getPrivateKey() <> null && $currentUser->getEnablePrivateKey() == 1) {
array_push(
$tplVars['rsschannels'],
array(
filter($sitename . sprintf(T_(': (private) ')) . $pagetitle),
createURL('rss', filter($user, 'url') . $rssCat.'?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
)
);
}
}
$tplVars['page'] = $page;

View File

@ -43,12 +43,13 @@ $tplVars['rsschannels'] = array(
array(sprintf(T_('%s: Recent bookmarks'), $sitename), createURL('rss').'?sort='.getSortOrder())
);
if ($userservice->isLoggedOn()) {
if ($currentUser->getPrivateKey() <> null) {
$currentUsername = $currentUser->getUsername();
if ($currentUser->getPrivateKey() <> null && $currentUser->getEnablePrivateKey() == 1) {
array_push(
$tplVars['rsschannels'],
array(
filter($sitename . sprintf(T_(': (private) ')) . $pagetitle),
createURL('rss', filter($user, 'url') . $rssCat.'?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
filter($sitename . sprintf(T_(': (private) ')) . $sitename),
createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&privatekey='.$currentUser->getPrivateKey())
)
);
}

View File

@ -25,11 +25,13 @@ require_once 'www-header.php';
// No specific services
/* Managing all possible inputs */
isset($_POST['submittedPK']) ? define('POST_SUBMITTEDPK', $_POST['submittedPK']): define('POST_SUBMITTEDPK', '');
isset($_POST['submitted']) ? define('POST_SUBMITTED', $_POST['submitted']): define('POST_SUBMITTED', '');
isset($_POST['pPass']) ? define('POST_PASS', $_POST['pPass']): define('POST_PASS', '');
isset($_POST['pPassConf']) ? define('POST_PASSCONF', $_POST['pPassConf']): define('POST_PASSCONF', '');
isset($_POST['pName']) ? define('POST_NAME', $_POST['pName']): define('POST_NAME', '');
isset($_POST['pPrivateKey']) ? define('POST_PRIVATEKEY', $_POST['pPrivateKey']): define('POST_PRIVATEKEY', '');
isset($_POST['pEnablePrivateKey']) ? define('POST_ENABLEPRIVATEKEY', $_POST['pEnablePrivateKey']): define('POST_ENABLEPRIVATEKEY', '');
isset($_POST['pMail']) ? define('POST_MAIL', $_POST['pMail']): define('POST_MAIL', '');
isset($_POST['pPage']) ? define('POST_PAGE', $_POST['pPage']): define('POST_PAGE', '');
isset($_POST['pDesc']) ? define('POST_DESC', $_POST['pDesc']): define('POST_DESC', '');
@ -63,8 +65,11 @@ if ($user) {
if ($userservice->isLoggedOn() && $user == $currentUser->getUsername()) {
$title = T_('My Profile');
$tplVars['privateKey'] = $currentUser->getPrivateKey();
$tplVars['enablePrivateKey'] = $currentUser->getPrivateKey();
} else {
$title = T_('Profile') .': '. $user;
$tplVars['privateKey'] = '';
}
$tplVars['pagetitle'] = $title;
$tplVars['subtitle'] = $title;
@ -72,12 +77,19 @@ $tplVars['subtitle'] = $title;
$tplVars['user'] = $user;
$tplVars['userid'] = $userid;
/* Update Private Key */
if (POST_SUBMITTEDPK!='' && $currentUser->getId() == $userid) {
$userinfo = $userservice->getObjectUserByUsername($user);
$tplVars['privateKey'] = $userservice->getNewPrivateKey();
}
if (POST_SUBMITTED!='' && $currentUser->getId() == $userid) {
$error = false;
$detPass = trim(POST_PASS);
$detPassConf = trim(POST_PASSCONF);
$detName = trim(POST_NAME);
$detPrivateKey = trim(POST_PRIVATEKEY);
$detEnablePrivateKey = trim(POST_ENABLEPRIVATEKEY);
$detMail = trim(POST_MAIL);
$detPage = trim(POST_PAGE);
$detDesc = filter(POST_DESC);
@ -102,13 +114,14 @@ if (POST_SUBMITTED!='' && $currentUser->getId() == $userid) {
$tplVars['error'] = T_('E-mail address is not valid.');
}
if (!$error) {
if (!$userservice->updateUser($userid, $detPass, $detName, $detMail, $detPage, $detDesc, $detPrivateKey)) {
if (!$userservice->updateUser($userid, $detPass, $detName, $detMail, $detPage, $detDesc, $detPrivateKey, $detEnablePrivateKey)) {
$tplvars['error'] = T_('An error occurred while saving your changes.');
} else {
$tplVars['msg'] = T_('Changes saved.');
}
}
$userinfo = $userservice->getObjectUserByUsername($user);
$tplVars['privateKey'] = $userinfo->getPrivateKey();
}
if (!$userservice->isLoggedOn() || $currentUser->getId() != $userid) {