| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App;
- use Exception;
- use ParagonIE\AntiCSRF\AntiCSRF;
- use RuntimeException;
- $users = User::getAll();
- if($users) {
- Http::redirect("/home");
- }
- $request = Request::fromPost();
- $email = $request->string("email");
- $password = $request->raw("password");
- $confirm_password = $request->raw("confirm_password");
- if($email) {
- $csrf = new AntiCSRF();
- try {
- if(!$csrf->validateRequest()) {
- throw new RuntimeException(__("CSRF validation failed."));
- }
- if($password !== $confirm_password) {
- throw new RuntimeException(__("Passwords do not match."));
- }
- $user = new User();
- $user->title = $request->string("title");
- $user->first_name = $request->string("first_name");
- $user->last_name = $request->string("last_name");
- $user->email = $request->email("email");
- $user->password = password_hash($password, PASSWORD_DEFAULT);
- $user->admin = 1;
- $user->dts_created = Database::dts();
- $user->commit();
- Session::addAlert("success", __("User created successfully."));
- Http::redirect("/home");
- }
- catch(Exception $e) {
- Session::addAlert("danger", $e->getMessage());
- }
- }
- View::include("header");
- View::include("setup");
- View::include("footer");
|