Commit a8208d23 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Added profile and account pages

parent e359370b
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# elem.checkValidity() # elem.checkValidity()
$ -> $ ->
$('form:not(.nofocus) input:first', document.forms[0]).focus() if document.forms.length $('form:not(.nofocus):first input:first').focus()
create_addon = (input) -> create_addon = (input) ->
group = $('<div class="input-group">').insertBefore(input) group = $('<div class="input-group">').insertBefore(input)
......
...@@ -7,11 +7,11 @@ msgstr "" ...@@ -7,11 +7,11 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: routes/common.php:15 routes/register.php:18 #: routes/common.php:15 routes/register.php:18 routes/register.php:20
msgid "Username" msgid "Username"
msgstr "Gebruikersnaam" msgstr "Gebruikersnaam"
#: routes/common.php:17 routes/register.php:24 #: routes/common.php:17 routes/register.php:24 routes/register.php:26
msgid "Password" msgid "Password"
msgstr "Wachtwoord" msgstr "Wachtwoord"
...@@ -19,7 +19,7 @@ msgstr "Wachtwoord" ...@@ -19,7 +19,7 @@ msgstr "Wachtwoord"
msgid "Login" msgid "Login"
msgstr "Inloggen" msgstr "Inloggen"
#: routes/match.php:34 util.php:59 #: routes/match.php:34 util.php:59 util.php:61
msgid "Match does not exist" msgid "Match does not exist"
msgstr "Score bestaat niet" msgstr "Score bestaat niet"
...@@ -29,12 +29,14 @@ msgstr "Onvoldoende permissies" ...@@ -29,12 +29,14 @@ msgstr "Onvoldoende permissies"
#: routes/match.php:77 routes/match.php:105 routes/match.php:64 #: routes/match.php:77 routes/match.php:105 routes/match.php:64
#: routes/match.php:92 routes/match.php:32 routes/match.php:60 #: routes/match.php:92 routes/match.php:32 routes/match.php:60
#: routes/user.php:60 #: routes/user.php:60 routes/user.php:109 routes/user.php:114
#: routes/user.php:106
msgid "Distance" msgid "Distance"
msgstr "Afstand" msgstr "Afstand"
#: routes/match.php:78 routes/match.php:65 routes/match.php:33 #: routes/match.php:78 routes/match.php:65 routes/match.php:33
#: routes/user.php:61 #: routes/user.php:61 routes/user.php:110 routes/user.php:115
#: routes/user.php:107
msgid "Select a distance" msgid "Select a distance"
msgstr "Selecteer een afstand" msgstr "Selecteer een afstand"
...@@ -52,7 +54,8 @@ msgid "Name" ...@@ -52,7 +54,8 @@ msgid "Name"
msgstr "Naam" msgstr "Naam"
#: routes/match.php:82 routes/match.php:69 routes/user.php:52 #: routes/match.php:82 routes/match.php:69 routes/user.php:52
#: routes/match.php:37 routes/user.php:65 #: routes/match.php:37 routes/user.php:65 routes/user.php:114
#: routes/user.php:119 routes/user.php:111
msgid "Filter" msgid "Filter"
msgstr "Filteren" msgstr "Filteren"
...@@ -73,7 +76,8 @@ msgid "Distance in meters" ...@@ -73,7 +76,8 @@ msgid "Distance in meters"
msgstr "Afstand in meters" msgstr "Afstand in meters"
#: routes/match.php:109 routes/match.php:96 routes/match.php:64 #: routes/match.php:109 routes/match.php:96 routes/match.php:64
#: routes/user.php:62 #: routes/user.php:62 routes/user.php:111 routes/user.php:116
#: routes/user.php:108
msgid "Discipline" msgid "Discipline"
msgstr "Discipline" msgstr "Discipline"
...@@ -93,23 +97,25 @@ msgstr "Opmerkingen" ...@@ -93,23 +97,25 @@ msgstr "Opmerkingen"
msgid "Create" msgid "Create"
msgstr "Opslaan" msgstr "Opslaan"
#: routes/register.php:22 #: routes/register.php:22 routes/register.php:24
msgid "Username may not contain whitespace or special characters" msgid "Username may not contain whitespace or special characters"
msgstr "Gebruikersnaam mag geen spaties of speciale tekens bevatten" msgstr "Gebruikersnaam mag geen spaties of speciale tekens bevatten"
#: routes/register.php:23 #: routes/register.php:23 routes/register.php:25
msgid "This username has already been taken" msgid "This username has already been taken"
msgstr "Deze gebruikersnaam is al in gebruik" msgstr "Deze gebruikersnaam is al in gebruik"
#: routes/register.php:26 #: routes/register.php:26 routes/register.php:30
msgid "Confirm password" msgid "Confirm password"
msgstr "Bevestig wachtwoord" msgstr "Bevestig wachtwoord"
#: routes/register.php:29 #: routes/register.php:29 routes/user.php:30 routes/register.php:33
#: routes/user.php:32
msgid "Passwords must match" msgid "Passwords must match"
msgstr "Wachtwoorden moeten gelijk zijn" msgstr "Wachtwoorden moeten gelijk zijn"
#: routes/register.php:30 templates/layout.latte:4 templates/login.latte:13 #: routes/register.php:30 templates/layout.latte:4 templates/login.latte:13
#: routes/register.php:34
msgid "Register" msgid "Register"
msgstr "Registreren" msgstr "Registreren"
...@@ -130,6 +136,7 @@ msgid "Add new match" ...@@ -130,6 +136,7 @@ msgid "Add new match"
msgstr "Nieuwe score" msgstr "Nieuwe score"
#: templates/match/create.latte:9 routes/user.php:51 routes/user.php:59 #: templates/match/create.latte:9 routes/user.php:51 routes/user.php:59
#: routes/user.php:108 routes/user.php:113 routes/user.php:105
msgid "Tags" msgid "Tags"
msgstr "Tags" msgstr "Tags"
...@@ -176,27 +183,33 @@ msgstr "Verwijderen" ...@@ -176,27 +183,33 @@ msgstr "Verwijderen"
msgid "Scores" msgid "Scores"
msgstr "Punten" msgstr "Punten"
#: routes/user.php:31 routes/user.php:33
msgid "Save" msgid "Save"
msgstr "Opslaan" msgstr "Opslaan"
#: util.php:53 #: util.php:53 util.php:55
msgid "No access to this user" msgid "No access to this user"
msgstr "Geen toegang tot deze gebruiker" msgstr "Geen toegang tot deze gebruiker"
#: routes/user.php:47 routes/user.php:52 #: routes/user.php:47 routes/user.php:52 routes/user.php:101
#: routes/user.php:106 routes/user.php:98
msgid "From" msgid "From"
msgstr "Vanaf" msgstr "Vanaf"
#: routes/user.php:49 routes/user.php:55 #: routes/user.php:49 routes/user.php:55 routes/user.php:104
#: routes/user.php:109 routes/user.php:101
msgid "Until" msgid "Until"
msgstr "Tot" msgstr "Tot"
#: routes/match.php:25 routes/user.php:45 #: routes/match.php:25 routes/user.php:45 routes/user.php:94
#: routes/user.php:99 routes/user.php:91
#, php-format #, php-format
msgid "%d meters" msgid "%d meters"
msgstr "%d meter" msgstr "%d meter"
#: routes/user.php:54 routes/user.php:57 #: routes/user.php:54 routes/user.php:57 routes/user.php:103
#: routes/user.php:106 routes/user.php:108 routes/user.php:111
#: routes/user.php:100
msgid "YYYY-MM-DD" msgid "YYYY-MM-DD"
msgstr "JJJJ-MM-DD" msgstr "JJJJ-MM-DD"
...@@ -205,3 +218,39 @@ msgstr "Gemiddelde score over tijd" ...@@ -205,3 +218,39 @@ msgstr "Gemiddelde score over tijd"
msgid "Progress graph" msgid "Progress graph"
msgstr "Voortgangsgrafiek" msgstr "Voortgangsgrafiek"
msgid "Profile"
msgstr "Profiel"
#: routes/user.php:23
msgid "Current password"
msgstr "Huidig wachtwoord"
#: routes/user.php:25
msgid "Password incorrect"
msgstr "Ongeldig wachtwoord"
#: routes/user.php:26
msgid "New password"
msgstr "Nieuw wachtwoord"
#: routes/user.php:27 routes/user.php:30
msgid "Confirm new password"
msgstr "Bevestig nieuw wachtwoord"
msgid "Edit account"
msgstr "Account bewerken"
msgid "Statistics"
msgstr "Statistieken"
msgid "Average match score"
msgstr "Gemiddelde wedstrijdscore"
msgid "Average arrow score"
msgstr "Gemiddelde pijlscore"
#: routes/register.php:28 routes/user.php:28
#, php-format
msgid "Password must be at least %d charachers"
msgstr "Uw wachtwoord moet minimaal %d karakters lang zijn"
...@@ -4,6 +4,8 @@ use Nette\Forms\Form; ...@@ -4,6 +4,8 @@ use Nette\Forms\Form;
use Instante\Bootstrap3Renderer\BootstrapRenderer; use Instante\Bootstrap3Renderer\BootstrapRenderer;
use Nette\Security\Passwords; use Nette\Security\Passwords;
define('MIN_PASSWORD_CHARS', 6);
function validate_unique_user($field) { function validate_unique_user($field) {
global $db; global $db;
$username = $field->getValue(); $username = $field->getValue();
...@@ -22,7 +24,9 @@ function registration_form() { ...@@ -22,7 +24,9 @@ function registration_form() {
->addRule(Form::PATTERN, _('Username may not contain whitespace or special characters'), '([a-zA-Z0-9-_])+') ->addRule(Form::PATTERN, _('Username may not contain whitespace or special characters'), '([a-zA-Z0-9-_])+')
->addRule('validate_unique_user', _('This username has already been taken')); ->addRule('validate_unique_user', _('This username has already been taken'));
$form->addPassword('password', _('Password')) $form->addPassword('password', _('Password'))
->setRequired(); ->setRequired()
->addRule(Form::MIN_LENGTH, sprintf(_('Password must be at least %d charachers'),
MIN_PASSWORD_CHARS), MIN_PASSWORD_CHARS);
$form->addPassword('password_repeat', _('Confirm password')) $form->addPassword('password_repeat', _('Confirm password'))
->setRequired() ->setRequired()
->addConditionOn($form['password'], Form::FILLED) ->addConditionOn($form['password'], Form::FILLED)
......
...@@ -2,21 +2,67 @@ ...@@ -2,21 +2,67 @@
use Nette\Forms\Form; use Nette\Forms\Form;
use Instante\Bootstrap3Renderer\BootstrapRenderer; use Instante\Bootstrap3Renderer\BootstrapRenderer;
use Nette\Security\Passwords;
$app->get('/user', function () { function find_user($id) {
echo "create user form"; global $db;
}); require_user_access($id);
return $db->table('user')->get($id);
}
function edit_user_form($dbuser) {
$form = new Form;
$form->setRenderer(new BootstrapRenderer);
$form->setAction("user/$dbuser->id");
$form->addHidden('_METHOD', 'PUT');
$check_current_password = function ($password) use ($dbuser) {
return Passwords::verify($password->getValue(), $dbuser->password);
};
$form->addPassword('current_password', _('Current password'))
->setRequired()
->addRule($check_current_password, _('Password incorrect'));
$form->addPassword('password', _('New password'))
->addCondition(Form::FILLED)
->addRule(Form::MIN_LENGTH, sprintf(_('Password must be at least %d charachers'),
MIN_PASSWORD_CHARS), MIN_PASSWORD_CHARS);
$form->addPassword('password_repeat', _('Confirm new password'))
->addConditionOn($form['password'], Form::FILLED)
->addRule(Form::EQUAL, _('Passwords must match'), $form['password']);
$form->addSubmit('send', _('Save'))->setAttribute('class', 'btn-primary');
$app->post('/user', function () { return $form;
echo "insert user"; }
$app->get('/user/:id', function ($id) use ($app, $db) {
$app->render('user/view', array('dbuser' => find_user($id)));
}); });
$app->get('/user/:id', function ($id) { $app->get('/user/:id/edit', function ($id) use ($app) {
echo "view user $id"; $form = edit_user_form(find_user($id));
$app->render('user/edit', compact('form'));
}); });
$app->put('/user/:id', function ($id) use ($app) {
$dbuser = find_user($id);
$form = edit_user_form($dbuser);
$form->validate();
if (!$form->hasErrors()) {
$values = $form->getValues();
if ($values->password) {
$dbuser->update(array(
'password' => Passwords::hash($values->password)
));
//$user->logout();
//$user->login($dbuser->username, $values->password);
}
$app->redirect(ROOT_URL . "/user/$id");
}
$app->get('/user/:id/edit', function ($id) { $app->render('user/edit', compact('form'));
echo "edit user $id form";
}); });
$app->put('/user/:id', function ($id) { $app->put('/user/:id', function ($id) {
......
$portrait-width: 640px $portrait-width: 640px
$xs-width: 768px $sm-width: 768px
$md-width: 992px
$lg-width: 1200px
.visible-xs-pt .visible-xs-pt
display: none display: none
...@@ -73,7 +75,7 @@ $xs-width: 768px ...@@ -73,7 +75,7 @@ $xs-width: 768px
.text .text
display: inline-block display: inline-block
@media (max-width: $xs-width - 1) @media (max-width: $sm-width - 1)
.actions .actions
float: right float: right
.btn .btn
...@@ -98,3 +100,15 @@ a.tag ...@@ -98,3 +100,15 @@ a.tag
.jqplot-highlighter-tooltip, .jqplot-canvasOverlay-tooltip, .jqplot-axis .jqplot-highlighter-tooltip, .jqplot-canvasOverlay-tooltip, .jqplot-axis
font-size: 1em !important font-size: 1em !important
td
&.header
white-space: nowrap
&.stretch
width: 100%
@media (min-width: $sm-width)
td.sm-stretch
width: 100%
{var $menu = $user->isLoggedIn() ? [ {var $menu = $user->isLoggedIn() ? [
['matches', _('Matches')], ['matches', _('Matches')],
["user/{$user->getId()}", _('Profile')],
["user/{$user->getId()}/plot", _('Progress graph')], ["user/{$user->getId()}/plot", _('Progress graph')],
['logout', _('Logout')], ['logout', _('Logout')],
] : [ ] : [
......
{extends '../layout.latte'}
{block content}
<h2 class="page-header">{_'Edit account'}</h2>
{$form}
{/block}
{extends '../layout.latte'}
{var $helper = new UserHelper($dbuser)}
{block content}
<h2 class="page-header">
{_'Account'}
<a href="user/{$dbuser->id}/edit" class="btn btn-sm btn-default"
title="{_'Edit'}">
<span class="glyphicon glyphicon-pencil"></span>
</a>
</h2>
<table class="table">
<tbody>
<tr>
<th>{_'Username'}</th>
<td class="sm-stretch">{$dbuser->username}</td>
</tr>
<tr>
<th>{_'Password'}</th>
<td class="sm-stretch">
********
</td>
</tr>
</tbody>
</table>
<h2 class="page-header">{_'Statistics'}</h2>
<table class="table">
{foreach ['barebow', 'recurve', 'compound'] as $discipline}
{if $helper->numberOfMatches($discipline) > 0}
<thead>
<tr>
<th colspan="3">{$discipline|capitalize}</th>
</tr>
</thead>
<tbody>
<tr>
<td class="header">{_'Matches'}</td>
<td>:</td>
<td class="sm-stretch">{$helper->numberOfMatches($discipline)}</td>
</tr>
<tr>
<td class="header">{_'Average match score'}</td>
<td>:</td>
<td class="stretch">{$helper->averageMatchScore($discipline)}</td>
</tr>
<tr>
<td class="header">{_'Average arrow score'}</td>
<td>:</td>
<td class="stretch">{$helper->averageArrowScore($discipline)|number:4}</td>
</tr>
</tbody>
{/if}
{/foreach}
</table>
{/block}
<?php <?php
use Nette\Database\IRow;
function load_config($filename, $optional=false) { function load_config($filename, $optional=false) {
if (!file_exists(__DIR__ . '/' . $filename)) { if (!file_exists(__DIR__ . '/' . $filename)) {
if ($optional) if ($optional)
...@@ -92,3 +94,43 @@ function match_score($row) { ...@@ -92,3 +94,43 @@ function match_score($row) {
function match_avg_score($row) { function match_avg_score($row) {
return match_score($row) / ($row->turns * $row->arrows); return match_score($row) / ($row->turns * $row->arrows);
} }
class UserHelper {
private $user;
public function __construct(IRow $dbuser) {
global $db;
$this->db = $db;
$this->user = $dbuser;
}
public function numberOfMatches($discipline) {
return $this->user->related('match')
->where('discipline', $discipline)
->count();
}
public function averageMatchScore($discipline) {
$matches = $this->user->related('match')
->select('scores')
->where('discipline', $discipline);
$score = 0;
foreach ($matches as $match)
$score += match_score($match);
return $score / $matches->count();
}
public function averageArrowScore($discipline) {
$matches = $this->user->related('match')
->select('arrows, turns, scores')
->where('discipline', $discipline);
$score = 0;
foreach ($matches as $match)
$score += match_avg_score($match);
return $score / $matches->count();
}
}
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