Advertisement
Serafim

Untitled

Mar 13th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.03 KB | None | 0 0
  1. <?php
  2. use Illuminate\Support\MessageBag;
  3.  
  4. /**
  5.  * Class AuthController
  6.  */
  7. class AuthController extends \BaseController
  8. {
  9.     /**
  10.      * @var string
  11.      */
  12.     protected $layout   = 'layout.main';
  13.  
  14.     /**
  15.      * @var string
  16.      */
  17.     protected $page     = 'Auth';
  18.  
  19.     /**
  20.      * New auth controller
  21.      */
  22.     public function __construct()
  23.     {
  24.         $this->page = Lang::get('auth.title.login');
  25.     }
  26.  
  27.     /**
  28.      * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
  29.      */
  30.     public function loginAction()
  31.     {
  32.         $data = [];
  33.  
  34.         $validator = Validator::make(Input::all(), [
  35.             'login'     => 'required|email',
  36.             'password'  => 'required|min:3'
  37.         ]);
  38.  
  39.  
  40.         if ($validator->passes()) {
  41.             if (Auth::attempt([
  42.                 'email'    => Input::get('login'),
  43.                 'password' => Input::get('password')
  44.             ])) {
  45.                 return Redirect::route('user.profile');
  46.             }
  47.         }
  48.  
  49.  
  50.         $data['errors'] = new MessageBag([
  51.             'auth' => [
  52.                 Lang::get('auth.login.failed') .
  53.                 link_to_route('auth.remind', Lang::get('auth.lost.password'))
  54.             ]
  55.         ]);
  56.  
  57.         return $this->index($data);
  58.     }
  59.  
  60.     /**
  61.      * @return \Illuminate\Http\RedirectResponse
  62.      */
  63.     public function logoutAction()
  64.     {
  65.         Auth::logout();
  66.         return Redirect::route('auth.login');
  67.     }
  68.  
  69.     /**
  70.      * @param array $data
  71.      * @return \Illuminate\View\View
  72.      */
  73.     public function index($data = [])
  74.     {
  75.         $this->page = Lang::get('auth.title.login');
  76.         return $this->content('auth.login', $data);
  77.     }
  78.  
  79.     /**
  80.      * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
  81.      */
  82.     public function registerAction()
  83.     {
  84.         $data = [];
  85.  
  86.         $validator = Validator::make(Input::all(), [
  87.             'login'     => 'required|email|unique:users,email',
  88.             'password'  => 'required|min:3|confirmed',
  89.             'password_confirmation' => 'required|min:3'
  90.         ]);
  91.  
  92.         if ($validator->passes()) {
  93.             $u              = new User();
  94.             $u->email       = Input::get('login');
  95.             $u->password    = Hash::make(Input::get('password'));
  96.             $u->confirmed   = false;
  97.             $u->save();
  98.  
  99.             if (Auth::attempt([
  100.                 'email'    => Input::get('login'),
  101.                 'password' => Input::get('password')
  102.             ])) {
  103.                 return Redirect::route('user.profile');
  104.             }
  105.         }
  106.  
  107.         $data['errors'] = new MessageBag([
  108.             'validate' => Lang::get('auth.' . $validator->errors()->first())
  109.         ]);
  110.  
  111.         return $this->register($data);
  112.     }
  113.  
  114.     /**
  115.      * @param array $data
  116.      * @return \Illuminate\View\View
  117.      */
  118.     public function register($data = [])
  119.     {
  120.         $this->page = Lang::get('auth.title.register');
  121.         return $this->content('auth.register', $data);
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement