/** * Edit user details * * @access 1 * @json * * @param Context $ctx * @return array */ public function edit(Context $ctx) { // get post data $changed = false; list($email, $password, $id, $rank, $username) = $ctx->post('email', 'password', 'id', 'rank', 'username'); // get user $user = $ctx->user; if ($user->isAdmin()) { $user = $id ? User::one(['id' => $id]) : new User(); if ($username != $user->username) { $changed = true; $username = strip_tags($username); $user->username = $username; } if ($rank != $user->rank) { $changed = true; $user->rank = $rank; } } // edit email if ($email != $user->email) { if (!filter_var($email, FILTER_SANITIZE_EMAIL)) { return ['state' => false, 'message' => text('logic.user.email.invalid')]; } $changed = true; $user->email = $email; } // edit password if ($password) { if (strlen($password) < User::PWD_MINLENGTH) { return ['state' => false, 'message' => text('logic.user.password.invalid')]; } $changed = true; $user->password = sha1(PWD_SALT . $password); } // save user $user->save(); // send confirmation mail if ($changed) { $email = new Mail(APP_NAME . ' - ' . text('email.profile.title')); $email->content = $ctx->templater->render('emails/profile', ['user' => $user, 'password' => $password]); $email->send($user->email); $ctx->logger->info($user->username . ' profile is updated', $_POST); } return ['state' => true]; }
<?php require 'instance.php'; /** * File permissions */ chmod(__ROOT__ . '/instance', 0777); chmod(__ROOT__ . '/instance/albums', 0777); chmod(CACHE_DIR, 0777); echo (string) is_writable(__ROOT__ . '/instance'); echo (string) is_writable(__ROOT__ . '/instance/albums'); echo (string) is_writable(CACHE_DIR); /** * Database reset */ use Pictobox\Model\User; User::builder()->wipe(); User::builder()->create(); $admin = new User(ADMIN_NAME, sha1(PWD_SALT . ADMIN_PWD), ADMIN_EMAIL, User::ADMIN); $admin->save();
<?php /** * PHP Settings */ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL & ~E_NOTICE); require 'instance.php'; /** * Authentication setup */ use Colorium\Stateful\Auth; use Pictobox\Model\User; Auth::factory(function ($id) { return User::one(['id' => $id]); }); /** * Debug mode */ use Colorium\Http; $request = Http\Request::globals(); $request->local[] = '10.0.2.2'; if ($request->local()) { $app->catch = false; $handler = new Whoops\Handler\PrettyPageHandler(); $handler->addDataTableCallback('App Request', function () use($request) { return (array) $request; }); $whoops = new Whoops\Run(); $whoops->pushHandler($handler)->register();