Advertisement
Serafim

Untitled

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