Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2. use TinyURL\Repository\User\DbUserRepository;
  3. class AuthController extends BaseController
  4. {
  5.     protected $userRepo;
  6.     public function __construct(DbUserRepository $userRepository)
  7.     {
  8.         $this->userRepo = $userRepository;
  9.  
  10.     }
  11.  
  12.     public function getLogin()
  13.     {
  14.         return View::make('auth.login');
  15.     }
  16.  
  17.     public function postLogin()
  18.     {
  19.         $email = Input::get('email');
  20.         $password = Input::get('password');
  21.         $validator = Validator::make(
  22.             ['email' => $email, 'password' => $password],
  23.             ['email' => 'required|email|exists:users', 'password' => 'required|min:5|exists:users']
  24.         );
  25.         if ($validator->fails())
  26.         {
  27.             return Redirect::to('auth/login')->withErrors($validator);
  28.         }
  29.         $data = array(
  30.             'email' => $email,
  31.             'password' => $password
  32.             );
  33.             if (Auth::attempt($data))
  34.             {
  35.                 return Redirect::intended('/');
  36.             }
  37.             return Redirect::to('auth/login');
  38.     }
  39.  
  40.     public function getLogout()
  41.     {
  42.         Auth::logout();
  43.         return Redirect::to('/');
  44.     }
  45.  
  46.     public function getRegister()
  47.     {
  48.         return View::make('auth.register');
  49.     }
  50.  
  51.     public function postRegister()
  52.     {
  53.         echo $name = Input::get('name');
  54.         echo $email = Input::get('email');
  55.         echo $password = Input::get('password');
  56.         echo $password2 = Input::get('password2');
  57.         $validator = Validator::make(
  58.             ['name' => $name, 'email' => $email, 'password' => $password, 'password2' => $password2],
  59.             ['name' => 'required|min:3', 'email' => 'required|email|unique:users', 'password' => 'required|min:5', 'password2' => 'same:password']
  60.         );
  61.         if ($validator->fails())
  62.         {
  63.             return Redirect::to('auth/register')->withErrors($validator);
  64.         }
  65.         $userName =  $this->userRepo->create($name, $email, $password);
  66.  
  67.         return View::make('index.index');
  68.     }
  69.  
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement