public function getLogin() { if (Session::exists(Config::get('session.name'))) { return Redirect::to('/'); } return view('auth.login'); }
/** * Redirect kembali ke halaman sebelumnya. * * @param array $data * @return response */ public static function back($data = []) { if (count($data) == 1) { Session::flash(key($data), current($data)); } header('Location: ' . $_SERVER['HTTP_REFERER']); }
public function getLogout() { if (Auth::check()) { Session::delete(Config::get('session.name')); } return Redirect::to('/'); }
/** * Mengecek apakah token yang dikirimkan sama dengan token yang disimpan di session. * * @return string $token * @return bool */ public static function match($token) { $token_name = Config::get('session.token_name'); if (Session::exists($token_name) && $token === Session::get($token_name)) { Session::delete($token_name); return true; } return false; }
public function index($id = null) { if ($id) { if ($idmedia = $this->Media->read($id)) { $currentMedia = Request::cleanInput($idmedia); $this->view->currentMedia = $currentMedia; } else { Session::setFlash("This Media doesn't exist", "warning"); } } $this->view->medias = $this->Media->read(); $this->view->render('medias/index'); }
<?php namespace App\Core\Controller; use App\Core\View\View; use App\Core\Session; // Initialisation de la session dans tous les controleurs Session::init(); /** * @Controlleur principal */ class Controller { protected $model = null; function __construct() { /* main controller */ $this->view = new View(); } public function loadModel($name) { /* recupere le chemin du model */ $n = ucfirst($name); $name .= "S"; $path = '../App/Model/' . $n . '.php'; /* vérifie si le model exixte et l' initialise */ if (file_exists($path)) { require '../App/Model/' . $n . '.php'; $this->{$n} = new $n($name); // modification, pour pourvoir faire par exemple $this->User->method // $this->model = new $name();
public static function user() { return self::check() ? Session::get(Config::get('session.name')) : false; }
public static function is_connected($user) { return Session::get($user); }
public function logout() { Session::destroy('user'); $this->setFlash("Log Out successfull !", 'success'); $this->view->redirect_to(''); }
/** * @return array|bool public function create(){ $sql= "INSERT INTO tmedias (title, url, type) VALUES ('".$this->title."', '".$this->url."', '".$this->type."')"; return $this->db->query($sql); }*/ public function upload($datas, $names) { $target_path = 'medias/'; $uploadOk = 1; for ($i = 0; $i < count($datas); $i++) { $name = $names[$i]; $temp_name = $datas[$i]; $target_path = $target_path . basename($name); if (file_exists($target_path)) { $uploadOk = 0; } if ($uploadOk == 0) { Session::setFlash('File already exist', 'warning'); } else { if (move_uploaded_file($temp_name, $target_path)) { Session::setFlash("The file " . basename($name) . " has been uploaded.", 'warning'); } else { Session::setFlash("Sorry, there was an error uploading your file", 'warning'); } } } }
<?php use App\Core\Session; use App\Core\Config; use App\Core\Redirect; use App\Core\Middleware; $middleware = new Middleware(); /** * Berhubung isu method next pada Middleware. * Sekarang hanya bisa menggunakan before middleware/filter. * Note: Dikarenakan fungsi exit() pada helper view(). */ $middleware->add('auth', function ($params) use($middleware) { // echo "auth <br>"; if (!Session::exists(Config::get('session.name'))) { if (is_ajax()) { http_response_code(401); exit; } else { Redirect::route('get-login'); } } $middleware->next($params); }); $middleware->add('admin', function ($params) use($middleware) { // do something $middleware->next($params); }); $middleware->add('something', function ($params) use($middleware) { // do something $middleware->next($params);
public function UpdateBrick($id) { $this->data = Request::all(); if ($this->Brick->UpdateBrick($id, $this->data)) { Session::setFlash('The brick has been updated', "success"); $this->view->redirect_to('/brick/edit'); } else { Session::setFlash("Problem occur while updating", "warning"); $this->view->redirect_to('/brick/edit'); } }