/** * Use this function for authenticated member and ustadz * if the authenticated is failure, the user will be redirect to * warning page that they can input username and pass again * * @param $username : username user * @param $password : password user * @return bool */ public static function auth($username, $password) { $data = Accounts::find(['username' => $username, 'password' => md5($password)]); if ($data) { # validate was successed # Set a session ID $account = array($data['id'], $data['username'], $data['name'], $data['type']); $session = new Session(); $session->set('id_account', implode('|', $account)); return TRUE; } # validate was failure return FALSE; }
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) { $comment = Comments::findByPK($id); if (!Request::is_authenticated()) { Response::redirect(''); } else { if (Request::user()->id !== $comment['id_account'] and !Request::is_admin()) { Session::push('flash-message', 'You does not have permission to delete the other Member\'s post!'); Response::redirect(''); } } # perform the post deletion Comments::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'); } }
public static function user() { if (!Request::is_authenticated()) { die("There are no auth account!"); } $session = new Session(); $data = explode('|', $session->get('id_account')); $request = new Request(); $request->data['id'] = $data[0]; $request->data['username'] = $data[1]; $request->data['name'] = $data[2]; $request->data['type'] = $data[3]; return $request; }