93 lines
3 KiB
PHP
93 lines
3 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Controller\ControllerBase,
|
|
App\Form\UserSettings as UserSettingsForm,
|
|
App\Model\Data\ActivityLog;
|
|
|
|
class UserController extends ControllerBase
|
|
{
|
|
public function settingsAction()
|
|
{
|
|
$user = $this->_getAuth()->getUser();
|
|
|
|
$form = new UserSettingsForm($user);
|
|
|
|
if ($this->request->isPost()) {
|
|
$data = $this->request->getPost();
|
|
|
|
if ($form->isValid($data)) {
|
|
|
|
$new_pw = $form->getValue('passwordNew');
|
|
if (strlen($new_pw) > 0) {
|
|
$hash = password_hash($new_pw, PASSWORD_BCRYPT);
|
|
$user->setPassword($hash);
|
|
}
|
|
$user->save();
|
|
$form->initialize();
|
|
|
|
$this->flash->message('success', 'Settings saved!');
|
|
} else {
|
|
$this->flash->message('error', 'Could not save settings');
|
|
}
|
|
}
|
|
|
|
$this->view->user = $user;
|
|
$this->view->form = $form;
|
|
}
|
|
|
|
public function activityAction($page = 1)
|
|
{
|
|
$user = $this->_getAuth()->getUser();
|
|
|
|
$paginator = ActivityLog::getPaginationList($user->getId(), $page);
|
|
|
|
$this->view->page = $paginator->getPaginate();
|
|
$this->view->pagination_url = '/user/activity/';
|
|
}
|
|
|
|
public function oauthDisconnectAction($provider, $last_unlink_confirmed = false)
|
|
{
|
|
$user = $this->_getAuth()->getUser();
|
|
|
|
// Check if we are unlinking the last provider
|
|
if (count($user->getSocialLinks()) <= 1) {
|
|
|
|
// If user does not have a password, we wont allow it.
|
|
if (strlen($user->getPassword()) < 1) {
|
|
$msg = 'Unlinking your last OAuth provider cannot be done '
|
|
. 'if you don\'t have a password as it would be impossible for you to log in.';
|
|
|
|
$this->flash->message('error', $msg);
|
|
$this->response->redirect('/settings');
|
|
return;
|
|
}
|
|
|
|
// Give a warning to the user about password as the only login option.
|
|
if ($last_unlink_confirmed == false) {
|
|
|
|
$url = $this->url->get([
|
|
'for' => 'oauth-disconnect-confirm',
|
|
'provider' => $provider,
|
|
'confirm' => 'confirm',
|
|
]);
|
|
|
|
$msg = '<p>You are about to unlink the last OAuth provider.'
|
|
. ' Your <strong>only</strong> login option will be <strong>password</strong> if you do this.</p>'
|
|
. '<p>Are you sure? <a class="alert-link" href="' . $url .'">Yes</a></p>';
|
|
|
|
$this->flash->message('warning', $msg);
|
|
$this->response->redirect('/settings');
|
|
return;
|
|
}
|
|
}
|
|
|
|
$user->{'set' . $provider . 'Id'}(null);
|
|
$user->save();
|
|
|
|
$this->flash->message('success', "<p><strong>{$provider}</strong> was disconnected</p>");
|
|
|
|
$this->response->redirect('/settings');
|
|
}
|
|
}
|