1
0
mirror of https://github.com/glmdev/eecs448-lab10 synced 2024-10-27 19:14:00 +00:00
eecs448-lab10/CreateUser.php

30 lines
776 B
PHP
Raw Normal View History

2020-12-06 19:58:02 +00:00
<?php
require_once './configuration.php';
$request = common\Request::capture();
$page = new common\Page;
$users = new app\UserRepository;
$page->title('Exercise 2 - EECS 448 Lab 10')
->header('Create a New User');
if ( !$request->input('username') ) {
$page->fail_to('You must specify a username.', system_url('CreateUser.html'));
}
$existing_user = $users->find_one([ 'username' => $request->input('username') ]);
if ( $existing_user ) {
$page->fail_to('A user with that username already exists.', system_url('CreateUser.html'));
}
$new_user = $users->save([
'username' => $request->input('username'),
]);
$page->div(function() use($page, $new_user) {
$page->writes('User ' . $new_user['username'] . ' created successfully.');
});
$page->write();