Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use TinyURL\Repository\User\DbUserRepository;
- class AuthController extends BaseController
- {
- protected $userRepo;
- public function __construct(DbUserRepository $userRepository)
- {
- $this->userRepo = $userRepository;
- }
- public function getLogin()
- {
- return View::make('auth.login');
- }
- public function postLogin()
- {
- $email = Input::get('email');
- $password = Input::get('password');
- $validator = Validator::make(
- ['email' => $email, 'password' => $password],
- ['email' => 'required|email|exists:users', 'password' => 'required|min:5|exists:users']
- );
- if ($validator->fails())
- {
- return Redirect::to('auth/login')->withErrors($validator);
- }
- $data = array(
- 'email' => $email,
- 'password' => $password
- );
- if (Auth::attempt($data))
- {
- return Redirect::intended('/');
- }
- return Redirect::to('auth/login');
- }
- public function getLogout()
- {
- Auth::logout();
- return Redirect::to('/');
- }
- public function getRegister()
- {
- return View::make('auth.register');
- }
- public function postRegister()
- {
- echo $name = Input::get('name');
- echo $email = Input::get('email');
- echo $password = Input::get('password');
- echo $password2 = Input::get('password2');
- $validator = Validator::make(
- ['name' => $name, 'email' => $email, 'password' => $password, 'password2' => $password2],
- ['name' => 'required|min:3', 'email' => 'required|email|unique:users', 'password' => 'required|min:5', 'password2' => 'same:password']
- );
- if ($validator->fails())
- {
- return Redirect::to('auth/register')->withErrors($validator);
- }
- $userName = $this->userRepo->create($name, $email, $password);
- return View::make('index.index');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement