Example #1
0
<?php

$form = new Odf\Form('settings/settings');
$form->validate();
if ($errors = $form->getErrors()) {
    return $Javascript->setErrors($errors)->output();
}
$form_input = $form->getInput();
// Check if passwords match.
if ($form_input['password'] !== $form_input['repeat_password']) {
    return $Javascript->setError(__('Passwords do not match.'), 'password');
}
unset($form_input['repeat_password']);
// We don't want to pass the "repeat_password" field to the db.
// Email not already in use?
$users_table = new Tables\Users();
$email_in_use = !!$users_table->by('email', $form_input['email'])->where('id != ' . getUser()->id)->getFirst();
if ($email_in_use) {
    return $Javascript->setError(__('Email address already in use.'))->output();
}
// Update password if new password is given.
if (!empty($form_input['password'])) {
    $salt_1 = $Login->generateSalt();
    $salt_2 = $Login->generateSalt();
    $password = $Login->hash($form_input['password'], $salt_1, $salt_2);
    $form_input['salt_1'] = $salt_1;
    $form_input['salt_2'] = $salt_2;
    $form_input['password'] = $password;
} else {
    unset($form_input['password']);
}
Example #2
0
<?php

$page_title = __('New user');
$user_id = !empty($_GET['id']) ? (int) $_GET['id'] : null;
$scheme_part_foods = [];
$Crumbs->addCrumb($page_title);
$page_controls = [['text' => __('Back'), 'url' => $Crumbs->getPreviousPageUrl()]];
$form = new Odf\Form('admin/user');
// Handle edit instead of new:
if ($user_id) {
    $users_table = new Tables\Users();
    $user = $users_table->get($user_id);
    if (!$user) {
        return $Template->output('error', 404);
    }
    $page_title = __('Edit user');
    $page_controls[] = ['text' => __('Delete'), 'url' => 'action/admin/delete_user?id=' . $user_id, 'confirm_message' => true];
    $user->password = null;
    // Don't display password in form.
    $form->setFieldValues($user);
}
$Template->output('header', ['title' => $page_title, 'nav_active' => 'admin']);
$Template->output('page_controls', $page_controls);
$Template->output('validator/status');
$form->output();
$Template->output('footer');
Example #3
0
<?php

$form = new Odf\Form('food/new');
$form->validate();
if ($errors = $form->getErrors()) {
    return $Javascript->setErrors($errors)->output();
}
$table = new \Tables\Foods();
$data = $form->getInput();
$data['user_id'] = getUser()->id;
$id = $table->create($data);
$Validator->useSession()->setSuccessMessage(__('Food saved.'));
$Crumbs->removeLastCrumb();
// Replace last crumb by page we'll redirect to.
$Ase->happen('update_cache', ['food']);
$Javascript->setRedirect('food/edit?id=' . $id)->output();
Example #4
0
<?php

$Template->output('header_not_logged_in', ['title' => __('Register')]);
?>

<a href="login"><?php 
echo __('Back');
?>
</a>
<p><?php 
echo __('registration_intro_text');
?>
</p>

<?php 
$form = new Odf\Form('register/register');
$form->output();
$Template->output('footer_not_logged_in');
Example #5
0
<?php

$form = new Odf\Form('food/edit');
$form->validate();
if ($errors = $form->getErrors()) {
    return $Javascript->setErrors($errors)->output();
}
$food_id = (int) $_POST['id'];
$table = new \Tables\Foods();
// May the current user edit this food?
$food = $table->get($food_id);
if (!$food || $food->user_id != getUser()->id) {
    return $Javascript->setError(__('You are not authorized to edit this food.'))->output();
}
$table->update($form->getInput(), $food_id);
$Ase->happen('update_cache', ['food']);
$Javascript->setSuccessMessage(__('Food saved.'))->output();