/** * Gets the coach for this client request. * * @return \TableRecords\User|null */ public function getCoach() { if (!$this->coach_id) { return; } $table = new \Tables\Users(); return $table->get($this->coach_id); }
$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']); } $users_table->get(getUser()->id)->save($form_input); $Javascript->setSuccessMessage(__('Settings updated.'))->output();
<?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');
return $Javascript->setErrors($errors)->output(); } $form_input = $form->getInput(); $user_id = !empty($form_input['id']) ? $form_input['id'] : null; $users_table = new Tables\Users(); // Email not already in use? if ($user_id) { $email_in_use = !!$users_table->by('email', $form_input['email'])->where('id != ' . $user_id)->getFirst(); if ($email_in_use) { return $Javascript->setError(__('Email address already in use.'))->output(); } } // Set password. if (!empty($form_input['password'])) { // Encrypt new 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']); } if ($user_id) { $user = $users_table->get((int) $form_input['id']); $user->save($form_input); } else { $user_id = $users_table->create($form_input); } $Javascript->setSuccessMessage(__('User saved.'))->output();
<?php $page_title = __('Settings'); $Crumbs->setRoot($page_title); $Template->output('header', ['title' => $page_title]); $table = new Tables\Users(); $user = $table->get(getUser()->id); $settings = []; foreach (get_object_vars($user) as $key => $value) { if (in_array($key, ['password'])) { continue; } $settings[$key] = $value; } $form = new Odf\Form('settings/settings', $settings); $form->output(); $Template->output('footer');
<?php $page_title = __('Admin'); $Crumbs->setRoot($page_title); $Template->output('header', ['title' => $page_title]); $users_table = new Tables\Users(); $users = $users_table->get(); $Template->output('page_controls', [['text' => __('New user'), 'url' => 'admin/user']]); $Template->output('validator/status'); ?> <table class="overview"> <thead> <tr> <th><?php echo __('Name'); ?> </th> <th><?php echo __('Email'); ?> </th> <th><?php echo __('Rank'); ?> </th> </tr> </thead> <tbody> <?php foreach ($users as $i => $user) {