public static function compose() { self::login_required(); if ("POST" == Request::method()) { $from = Request::user()->id; $to = Request::POST()->to_account; $subject = isset(Request::POST()->subject) ? Request::POST()->subject : ''; $text = Request::POST()->text; Messages::create($from, $to, $subject, $text); Response::redirect('mail/sent'); } else { $inboxes_count = Messages::countMsg('to'); $outboxes_count = Messages::countMsg('from'); $users = Accounts::all(); View::render('mails/compose', ['inboxes_count' => $inboxes_count, 'outboxes_count' => $outboxes_count, 'users' => $users]); } }
public static function edit($id) { if (!Request::is_admin()) { Response::redirect(''); } if ("POST" == Request::method()) { $id = Request::POST()->id; $word = Request::POST()->word; Badwords::update($id, $word); # push a flash message Session::push('flash-message', 'That badwords sensor has changed successfully!'); Response::redirect('badwords'); } else { $badword = Badwords::findByPK($id); $categories = Categories::all()->fetchAll(\PDO::FETCH_CLASS); View::render('badwords/add', ['badword' => $badword, 'categories' => $categories]); } }
public static function edit($id) { if (!Request::is_admin()) { Response::redirect(''); } if ("POST" == Request::method()) { $id = Request::POST()->id; $name = Request::POST()->name; $decsription = Request::POST()->description; Categories::update($id, $name, $decsription); # push flash-message Session::push('flash-message', 'That category has changed successfuly!'); Response::redirect('categories'); } else { $category = Categories::findByPK($id); $categories = Categories::all()->fetchAll(\PDO::FETCH_CLASS); View::render('categories/add', ['category' => $category, 'categories' => $categories]); } }
public static function addMember() { if ("POST" == Request::method()) { $username = Request::POST()->username; $email = Request::POST()->email; $pass = Request::POST()->password; $name = Request::POST()->name; $type = Request::POST()->type; $photo = File::upload('img', 'photo'); # if username has used by another member if (Accounts::find(['username' => $username])) { Session::push('flash-message', 'That username has used by other member, please use another!'); Response::redirect('accounts/add'); } Accounts::create($username, $pass, $name, $email, $photo, $type); # push flash-message Session::push('flash-message', 'That members has successfuly added!'); Response::redirect('accounts'); } else { $categories = Categories::all()->fetchAll(\PDO::FETCH_CLASS); View::render('admin/account-add', ['categories' => $categories]); } }
/** * @param $id */ public static function edit($id) { $post = Posts::findByPK($id); if (!Request::is_authenticated()) { Session::push('flash-message', 'You must login before!'); Response::redirect('login?next=post/edit/' . $id); } else { if (Request::user()->id !== $post['id_account']) { Session::push('flash-message', 'You does not have permission to edit the other Member\'s post!'); Response::redirect(''); } } if ("POST" == Request::method()) { $id_member = Request::user()->id; $data = Request::POST()->post; $title = Request::POST()->title; $cat = Request::POST()->category; Posts::edit($id, $id_member, $title, $data, $cat); } else { $users = Accounts::find(['type' => 2]); $categories = Categories::all(); View::render('member/edit-post', ['post' => $post, 'users' => $users, 'categories' => $categories]); } }
/** * Action Login * */ public static function login() { # if user was login before if (Request::is_authenticated()) { # redirect to main page Response::redirect(''); } # if request path contain ?next=page if (Request::GET()->next) { if (Session::flash()->has('next')) { Session::pop('next'); } # push next request page in the session Session::push('next', Request::GET()->next); } if ("POST" == Request::method()) { $username = Request::POST()->username; # $_POST['username'] $password = Request::POST()->password; # auth by base controller $auth = self::auth($username, $password); if ($auth) { # if session path contain next request page if (Session::flash()->has('next')) { # redirect to that request page Response::redirect(Session::pop('next')); } else { # Response::redirect(''); } } else { # if authenticated failure # pust a flash message Session::push('flash-message', 'Authenticated failure!'); View::render('login'); } } else { View::render('login'); } }
public static function register() { # if user was login before if (Request::is_authenticated()) { # redirect to main page Response::redirect(''); } if ("POST" == Request::method()) { $username = Request::POST()->username; $email = Request::POST()->email; $pass = Request::POST()->password; $name = Request::POST()->name; $photo = File::upload('img', 'photo'); # if username has used by another member if (Accounts::find(['username' => $username])) { Session::push('flash-message', 'That username has used by other member, please use another!'); Response::redirect('register'); } Accounts::create($username, $pass, $name, $email, $photo); # set a session self::auth($username, $pass); Session::push('flash-message-info', "Welcome to iniForum, <strong>{$name}</strong>!"); Response::redirect(''); } else { View::render('member/register'); } }