Browse Source

Extend SettingsAction instead of just Action

This way a lot of things (login, etc.) are handled for us.
master
Chimo 4 years ago
parent
commit
9af4584b90
1 changed files with 9 additions and 37 deletions
  1. +9
    -37
      actions/browsernotificationssettings.php

+ 9
- 37
actions/browsernotificationssettings.php View File

@@ -3,46 +3,20 @@ if (!defined('GNUSOCIAL')) {
exit(1);
}

class BrowserNotificationsSettingsAction extends Action
class BrowserNotificationsSettingsAction extends SettingsAction
{
function prepare($args)
protected function doPost()
{
parent::prepare($args);
$this->user = common_current_user();

if (!common_logged_in()) { // Make sure we're logged in
$this->clientError(_('Not logged in.'));
return;
} else if (!common_is_real_login()) { // Make _really_ sure we're logged in...
common_set_returnto($this->selfUrl());
$user = common_current_user();
if (Event::handle('RedirectToLogin', array($this, $user))) {
common_redirect(common_local_url('login'), 303);
}
} else { // k, I think by now we're logged in. For realz.
$this->user = common_current_user();
}
$settings = array(
'enabled' => $this->boolean('enabled', false),
'mentions_only' => $this->boolean('mentions_only', false)
);

if ($this->isPost()) {
$this->checkSessionToken();
}
BrowserNotificationSettings::save($this->user, $settings);

return true;
}

function handle($args)
{
parent::handle($args);

if ($this->isPost()) {
$settings = array(
'enabled' => $this->boolean('enabled', false),
'mentions_only' => $this->boolean('mentions_only', false)
);

BrowserNotificationSettings::save($this->user, $settings);
}

$this->showPage();
return _('Settings saved.');
}

function title()
@@ -52,8 +26,6 @@ class BrowserNotificationsSettingsAction extends Action

function showContent()
{
// TODO: Show 'success'/'error' msg after a form submit

$form = new BrowserNotificationsSettingsForm($this);
$form->show();
}


Loading…
Cancel
Save