public static function getOrFail($id) { $sql = sprintf("SELECT A.*, (\n SELECT name FROM accounts WHERE id=A.from_account\n ) as from_account_display, B.name as to_account_display, B.id as account_id, B.photo as account_photo\n FROM messages A LEFT JOIN accounts B\n ON A.to_account = B.id WHERE A.id=%d", $id); $data = self::query($sql)->fetch(); # if no data are return if (empty($data)) { Response::render('app/views/404.php'); } return $data; }
public static function login_required($role = null) { if (!Request::is_authenticated()) { Response::redirect(''); } $type = strtolower(Request::get_user('type-display')); if ($role and !($role === $type)) { Response::redirect(''); } return new static(); }
public static function delete($id) { if (!Request::is_admin()) { Response::redirect(''); } # perform the categories deletion Badwords::delete($id); # push a flash message Session::push('flash-message', 'That badwords sensor has deleted successfully!'); # redirect to main page Response::redirect('badwords'); }
public static function delete($id) { if (!Request::is_admin()) { Response::redirect(''); } # perform the categories deletion Categories::delete($id); # push flash-message Session::push('flash-message', 'That category has deleted successfuly!'); # redirect to main page Response::redirect('categories'); }
/** * @param $id */ public static function delete($id) { $post = Posts::findByPK($id); if (!Request::is_authenticated()) { Response::redirect(''); } else { if (Request::user()->id !== $post['id_account']) { Session::push('flash-message', 'You does not have permission to delete the other Member\'s post!'); Response::redirect(''); } } # perform the post deletion Posts::delete($id); # redirect to main page Response::redirect(''); }
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]); } }
public static function logout() { $session = new Session(); if ($session->has('id_account')) { $session->delete('id_account'); } $session->destroy(); Response::redirect(''); }
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'); } }
/** * @param $param * @param $page * @return mixed */ public static function get_object_or_redirect($param, $page) { $data = self::find($param); if (empty($data)) { Response::redirect("/{$page}"); } return $data; }