/** * Get all data! * @param string $criteria * @return \PDOStatement : fetchAll query */ public static function all($criteria = 'from') { if ('to' === $criteria) { $criteria = 'WHERE A.to_account=' . Request::user()->id; } else { $criteria = 'WHERE A.from_account=' . Request::user()->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 %s", $criteria); return self::query($sql); }
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) { $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(''); }
/** * 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 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 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'); } }
<li class="user-body hidden-xs"> <div class="col-xs-4 text-center"> <a href="#">Followers</a> </div> <div class="col-xs-4 text-center"> <a href="#">Sales</a> </div> <div class="col-xs-4 text-center"> <a href="#">Friends</a> </div> </li> <!-- Menu Footer--> <li class="user-footer hidden-xs"> <div class="pull-left"> <?php echo Html::anchor('/profile/' . Request::get_user('username'), 'Profile', ['class' => ['btn', 'btn-default', 'btn-flat']]); ?> </div> <div class="pull-right"> <?php echo Html::anchor('/logout', 'Sign out', ['class' => ['btn', 'btn-default', 'btn-flat']]); ?> </div> </li> <li class="hidden-lg hidden-md hidden-sm"> <?php echo Html::anchor('/profile', 'Profile'); ?> </li> <li class="hidden-lg hidden-md hidden-sm">
<i class="fa fa-clock-o"></i> <?php echo date_format_en($post['created_at']) . " "; ?> </small> <?php echo $post['name']; ?> </a> <?php echo Html::anchor('post/read/' . $post['id'], $post['title']); ?> <? # menampilkan aksi edit dan hapus untuk artikel milik member login if (\Ngaji\Http\Request::is_authenticated() and $post['account_id'] == \Ngaji\Http\Request::user()->id ): ?> <?php echo Html::anchor("post/edit/" . $post['id'], '<i class="fa fa-edit"></i> Edit', ['class' => 'btn btn-sm btn-flat']); ?> <?php echo Html::anchor("#", '<i class="fa fa-trash-o"></i> Delete', ['class' => 'btn btn-sm btn-flat', 'data-post-id' => $post['id'], 'data-post-title' => $post['title'], 'data-href' => sprintf("%s/post/delete/%d", HOSTNAME, $post['id']), 'data-toggle' => "modal", 'data-target' => "#confirm-delete"]); ?> <? endif; ?> </p> <div class="attachment"> <article> <?php echo Post::limit($post['post']); ?> </article>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'> <!-- Bootstrap 3.3.2 --> <?php echo Html::load('css', 'bootstrap.min.css'); echo Html::load('css', 'font-awesome.min.css'); ?> <link href="http://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css" rel="stylesheet" type="text/css"/> <!-- Theme style --> <?php echo Html::load('css', 'dist/AdminLTE.min.css'); ?> <!-- AdminLTE Skins. Choose a skin from the css/skins folder instead of downloading all of them to reduce the load. --> <?php echo Html::load('css', 'dist/skins/skin-blue.min.css'); ?> <!--custom style--> <style> <? if (!\Ngaji\Http\Request::is_admin()) : ?> .content-wrapper { padding-top: 60px; } <? endif; ?> </style>
</div> </div> <!-- /.box --> </div> <!--/.col (right) --> <div class="col-md-4"> <!-- PROFILE --> <div class="box box-primary"> <div class="box-header with-border"> <h3 class="box-title text-center">Profile</h3> <div class="pull-right box-tools"> <? # menampilkan aksi edit dan hapus untuk artikel milik member login if (\Ngaji\Http\Request::is_authenticated() and $account['id'] == \Ngaji\Http\Request::user()->id ): ?> <?php echo Html::button('<i class="fa fa-edit"></i> Edit', ['class' => 'btn btn-info btn-sm btn-flat', 'id' => 'edit-profile']); ?> <? endif; ?> </div> </div> <!-- /.box-header --> <div class="box-body"> <div class="col-center-block"> <?php echo Html::loadIMG($account['photo'], ['alt' => 'account image', 'class' => 'img-responsive img-circle center-block', 'width' => '140', 'height' => '140']); ?> <?php
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; }