mirror of
https://github.com/glmdev/eecs448-lab10
synced 2026-03-02 03:39:24 +00:00
Initial commit
This commit is contained in:
35
CreatePosts.php
Normal file
35
CreatePosts.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
require_once './configuration.php';
|
||||
|
||||
$request = common\Request::capture();
|
||||
$page = new common\Page;
|
||||
$users = new app\UserRepository;
|
||||
$posts = new app\PostRepository;
|
||||
|
||||
$page->title('Exercise 3 - EECS 448 Lab 10')
|
||||
->header('Create a New Post');
|
||||
|
||||
if ( !$request->input('username') ) {
|
||||
$page->fail_to('You must specify the username.', system_url('CreatePosts.html'));
|
||||
}
|
||||
|
||||
if ( !$request->input('content') ) {
|
||||
$page->fail_to('You must specify post content.', system_url('CreatePosts.html'));
|
||||
}
|
||||
|
||||
$user = $users->find_one([ 'username' => $request->input('username') ]);
|
||||
if ( !$user ) {
|
||||
$page->fail_to('Sorry, a user with that username does not exist.', system_url('CreatePosts.html'));
|
||||
}
|
||||
|
||||
$post = $posts->save([
|
||||
'user_id' => $user['user_id'],
|
||||
'content' => $request->input('content'),
|
||||
]);
|
||||
|
||||
$page->div(function() use($page) {
|
||||
$page->writes('Post created successfully.');
|
||||
});
|
||||
|
||||
$page->write();
|
||||
Reference in New Issue
Block a user