Advertisement
lamhottt

Router-Register-Login

Aug 11th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1.  
  2. use System\GF_Router as GF;
  3. // Namespace untuk Post Form Input
  4. use System\GF_Post as Form;
  5.  
  6.  
  7. GF::Route("",function(){
  8.     /**
  9.      * Controller Check Login
  10.      */
  11.     $o = GF::Controller("User_Controller");
  12.     $o->checkLogin();
  13.  
  14.     GF::directTo("login-user");
  15. });
  16.  
  17.  
  18. GF::Route("login-user",function(){
  19.  
  20.     /**
  21.      * Controller Check Login
  22.      */
  23.     $o = GF::Controller("User_Controller");
  24.     $o->checkLogin();
  25.     /* ============================== */
  26.  
  27.     /*
  28.     * Untuk mengambil dari Form Input
  29.     */
  30.     Form::post("txt_username # txt_password");
  31.    
  32.     $data['login']   = "null";
  33.    
  34.     // Jika form input terpenuhi, maka
  35.     if (Form::check())
  36.     {
  37.         $o = new User();
  38.         $txt  = Form::getAll();
  39.  
  40.         $o->setUsername($txt['txt_username']);
  41.         $o->setPassword($txt['txt_password']);
  42.        
  43.         // check login, apakah benar ?
  44.         if ($o->login())
  45.         {
  46.             // masukkan nilai login menjadi TRUE
  47.             $data['login'] = 'true';
  48.             // buat session baru
  49.             _createSession("username",$txt['txt_username']);
  50.             // refresh halaman
  51.             GF::directTo('');
  52.         }
  53.         else
  54.         {
  55.             $data['login'] = 'false';
  56.         }
  57.     }
  58.  
  59.     GF::setView("login",$data);
  60. });
  61.  
  62. GF::Route("daftar-user",function(){
  63.  
  64.     /**
  65.      * Controller Check Login
  66.      */
  67.     $o = GF::Controller("User_Controller");
  68.     $o->checkLogin();
  69.     /* ============================== */
  70.  
  71.     /*
  72.     * Untuk mengambil dari Form Input
  73.     */
  74.     Form::post("txt_username # txt_password");
  75.    
  76.     $data['register']   = "null";
  77.    
  78.     // Jika form input terpenuhi, maka
  79.     if (Form::check())
  80.     {
  81.         $o    = new User();
  82.         $txt  = Form::getAll();
  83.  
  84.         $o->setUsername($txt['txt_username']);
  85.         $o->setPassword($txt['txt_password']);
  86.  
  87.         if ($o->register())
  88.         {
  89.             $data['register'] = 'true';
  90.         }
  91.         else
  92.         {
  93.             $data['register'] = 'false';
  94.         }
  95.     }
  96.     GF::setView("register",$data);
  97. });
  98.  
  99.  
  100. GF::Route("logout-user",function(){
  101.     if (_checkSession('username'))
  102.     {
  103.         _destroySession('username');
  104.         GF::directTo('');
  105.     }
  106.     else
  107.     {
  108.         echo "Upzz Kamu Belum Login !";
  109.     }
  110. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement