knowndiaspora/Pages/Account.php

53 lines
2.0 KiB
PHP
Raw Normal View History

2015-01-17 23:12:58 +01:00
<?php
/**
2015-01-17 23:21:25 +01:00
* Diaspora pages
2015-01-17 23:12:58 +01:00
*/
2015-01-18 00:20:22 +01:00
namespace IdnoPlugins\KnownDiaspora\Pages {
2015-01-17 23:12:58 +01:00
/**
2015-01-17 23:21:25 +01:00
* Default class to serve Diaspora-related account settings
2015-01-17 23:12:58 +01:00
*/
class Account extends \Idno\Common\Page
{
function getContent()
{
2015-01-18 00:20:22 +01:00
if(isset($_GET['remove'])) {
unset(\Idno\Core\site()->session()->currentUser()->diaspora);
2015-01-18 00:20:22 +01:00
\Idno\Core\site()->config()->save();
\Idno\Core\site()->session()->addMessage('Your Diaspora credentials were removed.');
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/diaspora/');
2015-01-17 23:12:58 +01:00
}
2015-01-18 00:20:22 +01:00
$this->gatekeeper(); // Logged-in users only
2015-01-17 23:12:58 +01:00
$t = \Idno\Core\site()->template();
2015-01-18 00:20:22 +01:00
$body = $t->__(array())->draw('account/diaspora');
2015-01-17 23:21:25 +01:00
$t->__(array('title' => 'Diaspora', 'body' => $body))->drawPage();
2015-01-17 23:12:58 +01:00
}
function postContent() {
$this->gatekeeper(); // Logged-in users only
2015-01-18 00:20:22 +01:00
$pod = $this->getInput('pod');
$username = $this->getInput('user');
$password = $this->getInput('pass');
$user = \Idno\Core\site()->session()->currentUser();
$user->diaspora = [
2015-01-18 00:20:22 +01:00
'diaspora_username' => $username,
'diaspora_pod' => $pod
];
if (empty($user->diaspora['diaspora_password']) || !empty($password) ) {
$user->diaspora['diaspora_password'] = $password;
2015-01-17 23:12:58 +01:00
}
else {
$user->diaspora['diaspora_password'] = $user->diaspora['diaspora_password'];
}
$user->save();
2015-01-18 00:20:22 +01:00
\Idno\Core\site()->session()->addMessage('Your Diaspora credentials were saved.');
2015-01-17 23:21:25 +01:00
$this->forward(\Idno\Core\site()->config()->getDisplayURL() . 'account/diaspora/');
2015-01-17 23:12:58 +01:00
}
}
2015-01-17 23:21:25 +01:00
}