Advertisement
Serafim

Untitled

Mar 13th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 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     = 'Авторизация';
  18.  
  19.     /**
  20.      * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
  21.      */
  22.     public function loginAction()
  23.     {
  24.         $data = [];
  25.  
  26.         $validator = Validator::make(Input::all(), [
  27.             'login'     => 'required|email',
  28.             'password'  => 'required|min:3'
  29.         ]);
  30.  
  31.  
  32.         if ($validator->passes()) {
  33.             if (Auth::attempt([
  34.                 'email'    => Input::get('login'),
  35.                 'password' => Input::get('password')
  36.             ])) {
  37.                 return Redirect::route('user.profile');
  38.             }
  39.         }
  40.  
  41.  
  42.         $data['errors'] = new MessageBag([
  43.             'auth' => [
  44.                 'Неверный email или пароль. ' .
  45.                 link_to_route('auth.remind', 'Забыли пароль?')
  46.             ]
  47.         ]);
  48.  
  49.         return $this->index($data);
  50.     }
  51.  
  52.     /**
  53.      * @return \Illuminate\Http\RedirectResponse
  54.      */
  55.     public function logoutAction()
  56.     {
  57.         Auth::logout();
  58.         return Redirect::route('auth.login');
  59.     }
  60.  
  61.     /**
  62.      * @param array $data
  63.      * @return \Illuminate\View\View
  64.      */
  65.     public function index($data = [])
  66.     {
  67.         $this->page = Lang::get('auth.title.login');
  68.         return $this->content('auth.login', $data);
  69.     }
  70.  
  71.     /**
  72.      * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
  73.      */
  74.     public function registerAction()
  75.     {
  76.         $data = [];
  77.  
  78.         $validator = Validator::make(Input::all(), [
  79.             'login'     => 'required|email|unique:users,email',
  80.             'password'  => 'required|min:3|confirmed',
  81.             'password_confirmation' => 'required|min:3'
  82.         ]);
  83.  
  84.         if ($validator->passes()) {
  85.             $u              = new User();
  86.             $u->email       = Input::get('login');
  87.             $u->password    = Hash::make(Input::get('password'));
  88.             $u->confirmed   = false;
  89.             $u->save();
  90.  
  91.             if (Auth::attempt([
  92.                 'email'    => Input::get('login'),
  93.                 'password' => Input::get('password')
  94.             ])) {
  95.                 return Redirect::route('user.profile');
  96.             }
  97.         }
  98.  
  99.         $data['errors'] = new MessageBag([
  100.             'validate' => Lang::get('auth.' . $validator->errors()->first())
  101.         ]);
  102.  
  103.         return $this->register($data);
  104.     }
  105.  
  106.     /**
  107.      * @param array $data
  108.      * @return \Illuminate\View\View
  109.      */
  110.     public function register($data = [])
  111.     {
  112.         $this->page = Lang::get('auth.title.register');
  113.         return $this->content('auth.register', $data);
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement