Commit 10e32f5c authored by Taddeus Kroes's avatar Taddeus Kroes

Bugfix + made account editing actions responsive

parent 105ca2d9
...@@ -5,14 +5,9 @@ use Instante\Bootstrap3Renderer\BootstrapRenderer; ...@@ -5,14 +5,9 @@ use Instante\Bootstrap3Renderer\BootstrapRenderer;
use Nette\Security\Passwords; use Nette\Security\Passwords;
function find_user($id) { function find_user($id) {
global $app, $db, $user; global $app, $db;
if (!$user->isLoggedIn())
$app->redirect(ROOT_URL . '/login');
if ($user->getId() != $id && !in_array('admin', $user->getRoles()))
$app->halt(403, _('No access to this user'));
require_user_access($id);
$dbuser = $db->table('user')->get($id); $dbuser = $db->table('user')->get($id);
if (!$dbuser) if (!$dbuser)
...@@ -51,8 +46,9 @@ $app->get('/user/:id', function ($id) use ($app, $db) { ...@@ -51,8 +46,9 @@ $app->get('/user/:id', function ($id) use ($app, $db) {
}); });
$app->get('/user/:id/edit', function ($id) use ($app) { $app->get('/user/:id/edit', function ($id) use ($app) {
$form = edit_user_form(find_user($id)); $dbuser = find_user($id);
$app->render('user/edit', compact('form')); $form = edit_user_form($dbuser);
$app->render('user/edit', compact('dbuser', 'form'));
}); });
$app->put('/user/:id', function ($id) use ($app) { $app->put('/user/:id', function ($id) use ($app) {
$dbuser = find_user($id); $dbuser = find_user($id);
......
...@@ -2,5 +2,22 @@ ...@@ -2,5 +2,22 @@
{block content} {block content}
<h2 class="page-header">{_'Edit account'}</h2> <h2 class="page-header">{_'Edit account'}</h2>
{$form} {form $form}
{form errors}
{form controls}
<div class="form-group">
<div class="form-actions col-sm-offset-2 col-sm-10">
<div class="btn-group actions actions-responsive">
<a href="user/{$dbuser->id}" class="btn btn-default" title="{_'Cancel'}">
<span class="glyphicon glyphicon-remove"></span>
<span class="text">{_'Cancel'}</span>
</a>
<button type="submit" name="send" class="btn btn-primary" title="{_'Save'}">
<span class="glyphicon glyphicon-ok"></span>
<span class="text">{_'Save'}</span>
</button>
</div>
</div>
</div>
{/form}
{/block} {/block}
...@@ -45,6 +45,16 @@ function set_accept_locale($supported_languages=null) { ...@@ -45,6 +45,16 @@ function set_accept_locale($supported_languages=null) {
return null; return null;
} }
function require_user_access($user_id) {
global $user, $app;
if (!$user->isLoggedIn())
$app->redirect(ROOT_URL . '/login');
if ($user->getId() != $user_id && !in_array('admin', $user->getRoles()))
$app->halt(403, _('No access to this user'));
}
function find_match($id) { function find_match($id) {
global $app, $db, $user; global $app, $db, $user;
$match = $db->table('match')->get($id); $match = $db->table('match')->get($id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment