Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php namespace Controller;
- use Lang, Auth, Validator, Redirect, Input, User;
- use Illuminate\Support\MessageBag;
- /**
- * Class AuthController
- */
- class AuthController extends \BaseController
- {
- /**
- * @var string
- */
- protected $layout = 'layout.main';
- /**
- * @var string
- */
- protected $page = 'Auth';
- /**
- * New auth controller
- */
- public function __construct()
- {
- $this->page = Lang::get('auth.title.login');
- }
- /**
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
- */
- public function loginAction()
- {
- $data = [];
- $validator = Validator::make(Input::all(), [
- 'login' => 'required|email',
- 'password' => 'required|min:3'
- ]);
- if ($validator->passes()) {
- if (Auth::attempt([
- 'email' => Input::get('login'),
- 'password' => Input::get('password')
- ])) {
- return Redirect::route('user.profile');
- }
- }
- $data['errors'] = new MessageBag([
- 'auth' => [
- Lang::get('auth.login.failed') .
- link_to_route('auth.remind', Lang::get('auth.lost.password'))
- ]
- ]);
- return $this->index($data);
- }
- /**
- * @return \Illuminate\Http\RedirectResponse
- */
- public function logoutAction()
- {
- Auth::logout();
- return Redirect::route('auth.login');
- }
- /**
- * @param array $data
- * @return \Illuminate\View\View
- */
- public function index($data = [])
- {
- $this->page = Lang::get('auth.title.login');
- return $this->content('auth.login', $data);
- }
- /**
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
- */
- public function registerAction()
- {
- $data = [];
- $validator = Validator::make(Input::all(), [
- 'login' => 'required|email|unique:users,email',
- 'password' => 'required|min:3|confirmed',
- 'password_confirmation' => 'required|min:3'
- ]);
- if ($validator->passes()) {
- $u = new User();
- $u->email = Input::get('login');
- $u->password = Hash::make(Input::get('password'));
- $u->confirmed = false;
- $u->save();
- if (Auth::attempt([
- 'email' => Input::get('login'),
- 'password' => Input::get('password')
- ])) {
- return Redirect::route('user.profile');
- }
- }
- $data['errors'] = new MessageBag([
- 'validate' => Lang::get('auth.' . $validator->errors()->first())
- ]);
- return $this->register($data);
- }
- /**
- * @param array $data
- * @return \Illuminate\View\View
- */
- public function register($data = [])
- {
- $this->page = Lang::get('auth.title.register');
- return $this->content('auth.register', $data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement