PHP Classes

File: app/controllers/Admin/AdminController.php

Recommend this page to a friend!
  Classes of ikhsan   Slim Starter   app/controllers/Admin/AdminController.php   Download  
File: app/controllers/Admin/AdminController.php
Role: Application script
Content type: text/plain
Description: Admin authentication Controller
Class: Slim Starter
Build MVC Web applications based on Slim framework
Author: By
Last change: Update of app/controllers/Admin/AdminController.php
Date: 5 months ago
Size: 1,855 bytes
 

Contents

Class file image Download
<?php

namespace Admin;

use \
App;
use \
View;
use \
Input;
use \
Sentry;
use \
Response;

class
AdminController extends BaseController
{

   
/**
     * display the admin dashboard
     */
   
public function index()
    {
       
View::display('admin/index.twig', $this->data);
    }

   
/**
     * display the login form
     */
   
public function login()
    {
        if(
Sentry::check()){
           
Response::redirect($this->siteUrl('admin'));
        }else{
           
$this->data['redirect'] = (Input::get('redirect')) ? base64_decode(Input::get('redirect')) : '';
           
View::display('admin/login.twig', $this->data);
        }
    }

   
/**
     * Process the login
     */
   
public function doLogin()
    {
       
$remember = Input::post('remember', false);
       
$email = Input::post('email');
       
$redirect = Input::post('redirect');
       
$redirect = ($redirect) ? $redirect : 'admin';

        try{
           
$credential = array(
               
'email' => $email,
               
'password' => Input::post('password')
            );

           
// Try to authenticate the user
           
$user = Sentry::authenticate($credential, false);

            if(
$remember){
               
Sentry::loginAndRemember($user);
            }else{
               
Sentry::login($user, false);
            }

           
Response::redirect($this->siteUrl($redirect));
        }catch(\
Exception $e){
           
App::flash('message', $e->getMessage());
           
App::flash('email', $email);
           
App::flash('redirect', $redirect);
           
App::flash('remember', $remember);

           
Response::redirect($this->siteUrl('login'));
        }
    }

   
/**
     * Logout the user
     */
   
public function logout()
    {
       
Sentry::logout();

       
Response::redirect($this->siteUrl('login'));
    }

}