diff --git a/public_html/js/Presenters/UserPresenter.js b/public_html/js/Presenters/UserPresenter.js
index 8587ea12..4977d193 100644
--- a/public_html/js/Presenters/UserPresenter.js
+++ b/public_html/js/Presenters/UserPresenter.js
@@ -1,19 +1,50 @@
var App = App || {};
App.Presenters = App.Presenters || {};
-App.Presenters.UserPresenter = function(jQuery, topNavigationPresenter, appState) {
+App.Presenters.UserPresenter = function(
+ jQuery,
+ util,
+ promise,
+ api,
+ appState,
+ topNavigationPresenter,
+ messagePresenter) {
var $el = jQuery('#content');
+ var $messages = $el;
+ var template;
+ var accountSettingsTemplate;
+ var browsingSettingsTemplate;
+ var user;
var userName;
function init(args) {
userName = args.userName;
topNavigationPresenter.select(appState.get('loggedIn') && appState.get('loggedInUser').name == userName ? 'my-account' : 'users');
- render();
+
+ promise.waitAll(
+ util.promiseTemplate('user'),
+ util.promiseTemplate('account-settings'),
+ util.promiseTemplate('browsing-settings'),
+ api.get('/users/' + userName))
+ .then(function(userHtml, accountSettingsHtml, browsingSettingsHtml, response) {
+ template = _.template(userHtml);
+ accountSettingsTemplate = _.template(accountSettingsHtml);
+ browsingSettingsTemplate = _.template(browsingSettingsHtml);
+
+ user = response.json;
+ render();
+ }).fail(function(response) {
+ $el.empty();
+ messagePresenter.showError($messages, response.json && response.json.error || response);
+ });
}
function render() {
- $el.html('Viewing user: ' + userName);
+ $el.html(template({user: user}));
+ $el.find('.browsing-settings').html(browsingSettingsTemplate({user: user}));
+ $el.find('.account-settings').html(accountSettingsTemplate({user: user}));
+ $messages = $el.find('.messages');
};
return {
diff --git a/public_html/templates/account-settings.tpl b/public_html/templates/account-settings.tpl
new file mode 100644
index 00000000..8c94ebd4
--- /dev/null
+++ b/public_html/templates/account-settings.tpl
@@ -0,0 +1,74 @@
+
diff --git a/public_html/templates/browsing-settings.tpl b/public_html/templates/browsing-settings.tpl
new file mode 100644
index 00000000..cbe54b24
--- /dev/null
+++ b/public_html/templates/browsing-settings.tpl
@@ -0,0 +1,55 @@
+
+
+
diff --git a/public_html/templates/user.tpl b/public_html/templates/user.tpl
new file mode 100644
index 00000000..9b4e18fa
--- /dev/null
+++ b/public_html/templates/user.tpl
@@ -0,0 +1,13 @@
+
+
+ <%= user.name %>
+
+
Browsing settings
+
+
+
+
Account settings
+
+
+
+
diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php
index 33ba118d..528c81ca 100644
--- a/src/Controllers/UserController.php
+++ b/src/Controllers/UserController.php
@@ -18,13 +18,14 @@ final class UserController extends AbstractController
{
$router->post('/api/users', [$this, 'register']);
$router->get('/api/users', [$this, 'getFiltered']);
- $router->get('/api/users/:id', [$this, 'getById']);
- $router->put('/api/users/:id', [$this, 'update']);
- $router->delete('/api/users/:id', [$this, 'delete']);
+ $router->get('/api/users/:name', [$this, 'getByName']);
+ $router->put('/api/users/:name', [$this, 'update']);
+ $router->delete('/api/users/:name', [$this, 'delete']);
}
public function getFiltered()
{
+ //todo: privilege checking
//todo: move this to form data constructor
$searchFormData = new \Szurubooru\FormData\SearchFormData;
$searchFormData->query = $this->inputReader->query;
@@ -38,30 +39,33 @@ final class UserController extends AbstractController
'totalRecords' => $searchResult->totalRecords];
}
- public function getById($id)
+ public function getByName($name)
{
- throw new \BadMethodCallException('Not implemented');
+ //todo: privilege checking
+ $user = $this->userService->getByName($name);
+ if (!$user)
+ throw new \DomainException('User with name "' . $name . '" was not found.');
+ return new \Szurubooru\ViewProxies\User($user);
}
public function register()
{
+ //todo: privilege checking
$input = new \Szurubooru\FormData\RegistrationFormData;
//todo: move this to form data constructor
$input->name = $this->inputReader->userName;
$input->password = $this->inputReader->password;
$input->email = $this->inputReader->email;
-
$user = $this->userService->register($input);
-
return new \Szurubooru\ViewProxies\User($user);
}
- public function update($id)
+ public function update($name)
{
throw new \BadMethodCallException('Not implemented');
}
- public function delete($id)
+ public function delete($name)
{
throw new \BadMethodCallException('Not implemented');
}
diff --git a/src/Services/UserService.php b/src/Services/UserService.php
index 18f187aa..bffdc1e3 100644
--- a/src/Services/UserService.php
+++ b/src/Services/UserService.php
@@ -29,6 +29,11 @@ class UserService
$this->timeService = $timeService;
}
+ public function getByName($name)
+ {
+ return $this->userDao->getByName($name);
+ }
+
public function getFiltered(\Szurubooru\FormData\SearchFormData $formData)
{
$pageSize = intval($this->config->users->usersPerPage);
@@ -46,8 +51,6 @@ class UserService
if ($this->userDao->getByName($formData->name))
throw new \DomainException('User with this name already exists.');
- //todo: privilege checking
-
$user = new \Szurubooru\Entities\User();
$user->name = $formData->name;
$user->email = $formData->email;