FavorAction upgraded to extend FormAction

Includes some minor changes to other things as well, such as the session
token input element now having the same 'name' attribute as everyone else.
(it still retains a 'token-'+noticeid 'id' attribute for clientside JS)
This commit is contained in:
Mikael Nordfeldth
2013-09-23 11:34:15 +02:00
parent f711f9ee75
commit 5f1fea1488
7 changed files with 80 additions and 135 deletions

View File

@@ -27,9 +27,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET')) {
exit(1);
}
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Anonymous disfavor class
@@ -65,22 +63,14 @@ class AnonDisfavorAction extends RedirectingAction
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
$token = $this->trimmed('token-' . $notice->id);
if (!$token || $token != common_session_token()) {
// TRANS: Client error.
$this->clientError(_m('There was a problem with your session token. Try again, please.'));
return;
}
$token = $this->checkSessionToken();
$fave = new Fave();
$fave->user_id = $profile->id;
$fave->notice_id = $notice->id;
if (!$fave->find(true)) {
// TRANS: Client error.
$this->clientError(_m('This notice is not a favorite!'));
return;
throw new NoResultException($fave);
}
$result = $fave->delete();

View File

@@ -27,9 +27,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET')) {
exit(1);
}
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Anonymous favor class
@@ -64,14 +62,7 @@ class AnonFavorAction extends RedirectingAction
$id = $this->trimmed('notice');
$notice = Notice::getKV($id);
$token = $this->trimmed('token-' . $notice->id);
if (empty($token) || $token != common_session_token()) {
// TRANS: Client error.
$this->clientError(_m('There was a problem with your session token. Try again, please.'));
return;
}
$token = $this->checkSessionToken();
if ($profile->hasFave($notice)) {
// TRANS: Client error.

View File

@@ -301,7 +301,7 @@ RealtimeUpdate = {
ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
"<fieldset>"+
"<legend>Favor this notice</legend>"+
"<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
"<input name=\"token\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
"<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
"<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
"</fieldset>"+
@@ -348,7 +348,7 @@ RealtimeUpdate = {
rf = "<form id=\"repeat-"+id+"\" class=\"form_repeat\" method=\"post\" action=\""+RealtimeUpdate._repeaturl+"\">"+
"<fieldset>"+
"<legend>Repeat this notice?</legend>"+
"<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
"<input name=\"token\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
"<input name=\"notice\" type=\"hidden\" id=\"notice-"+id+"\" value=\""+id+"\"/>"+
"<input type=\"submit\" id=\"repeat-submit-"+id+"\" name=\"repeat-submit-"+id+"\" class=\"submit\" value=\"Yes\" title=\"Repeat this notice\"/>"+
"</fieldset>"+