-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Remove Authenticates from AuthenticatesAndRegistersUsers to its own trait #7567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,115 +1,60 @@ | ||
| <?php namespace Illuminate\Foundation\Auth; | ||
|
|
||
| use Auth; | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't do that.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No extra new line.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, got it. If you find something else, let me know.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's multiple occurrences in this pull request. |
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Contracts\Auth\Guard; | ||
| use Illuminate\Contracts\Auth\Registrar; | ||
|
|
||
| trait AuthenticatesAndRegistersUsers { | ||
|
|
||
| /** | ||
| * Show the application registration form. | ||
| * | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function getRegister() | ||
| { | ||
| return view('auth.register'); | ||
| } | ||
|
|
||
| /** | ||
| * Handle a registration request for the application. | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function postRegister(Request $request) | ||
| { | ||
| $validator = $this->validator($request->all()); | ||
|
|
||
| if ($validator->fails()) | ||
| { | ||
| $this->throwValidationException( | ||
| $request, $validator | ||
| ); | ||
| } | ||
|
|
||
| Auth::login($this->create($request->all())); | ||
|
|
||
| return redirect($this->redirectPath()); | ||
| } | ||
|
|
||
| /** | ||
| * Show the application login form. | ||
| * | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function getLogin() | ||
| { | ||
| return view('auth.login'); | ||
| } | ||
|
|
||
| /** | ||
| * Handle a login request to the application. | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function postLogin(Request $request) | ||
| { | ||
| $this->validate($request, [ | ||
| 'email' => 'required|email', 'password' => 'required', | ||
| ]); | ||
|
|
||
| $credentials = $request->only('email', 'password'); | ||
|
|
||
| if (Auth::attempt($credentials, $request->has('remember'))) | ||
| { | ||
| return redirect()->intended($this->redirectPath()); | ||
| } | ||
|
|
||
| return redirect($this->loginPath()) | ||
| ->withInput($request->only('email', 'remember')) | ||
| ->withErrors([ | ||
| 'email' => 'These credentials do not match our records.', | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Log the user out of the application. | ||
| * | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function getLogout() | ||
| { | ||
| Auth::logout(); | ||
|
|
||
| return redirect('/'); | ||
| } | ||
|
|
||
| /** | ||
| * Get the post register / login redirect path. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function redirectPath() | ||
| { | ||
| if (property_exists($this, 'redirectPath')) | ||
| { | ||
| return $this->redirectPath; | ||
| } | ||
|
|
||
| return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home'; | ||
| } | ||
|
|
||
| /** | ||
| * Get the path to the login route. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function loginPath() | ||
| { | ||
| return property_exists($this, 'loginPath') ? $this->loginPath : '/auth/login'; | ||
| } | ||
|
|
||
| use AuthenticatesUsers; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must use tabs for indentation. |
||
|
|
||
| /** | ||
| * Show the application registration form. | ||
| * | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function getRegister() | ||
| { | ||
| return view('auth.register'); | ||
| } | ||
|
|
||
| /** | ||
| * Handle a registration request for the application. | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function postRegister(Request $request) | ||
| { | ||
| $validator = $this->validator($request->all()); | ||
|
|
||
| if ($validator->fails()) | ||
| { | ||
| $this->throwValidationException( | ||
| $request, $validator | ||
| ); | ||
| } | ||
|
|
||
| Auth::login($this->create($request->all())); | ||
|
|
||
| return redirect($this->redirectPath()); | ||
| } | ||
|
|
||
| /** | ||
| * Validates the submitted registration form | ||
| * | ||
| * @param array $data | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect cs. |
||
| * | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect cs. |
||
| * @return \Illuminate\Contracts\Validation\Validator | ||
| */ | ||
| abstract protected function validator(array $data); | ||
|
|
||
| /** | ||
| * Persist the registration form and returns it | ||
| * | ||
| * @param array $data | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect cs. |
||
| * | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect cs. |
||
| * @return \Illuminate\Contracts\Auth\Authenticatable | ||
| */ | ||
| abstract protected function create(array $data); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| <?php | ||
|
|
||
|
|
||
| namespace Illuminate\Foundation\Auth; | ||
|
|
||
| use Auth; | ||
|
|
||
| use Illuminate\Http\Request; | ||
|
|
||
| trait AuthenticatesUsers { | ||
|
|
||
| /** | ||
| * Show the application login form. | ||
| * | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function getLogin() | ||
| { | ||
| return view('auth.login'); | ||
| } | ||
|
|
||
| /** | ||
| * Handle a login request to the application. | ||
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function postLogin(Request $request) | ||
| { | ||
| $this->validate($request, [ | ||
| 'email' => 'required|email', 'password' => 'required', | ||
| ]); | ||
|
|
||
| $credentials = $request->only('email', 'password'); | ||
|
|
||
| if (Auth::attempt($credentials, $request->has('remember'))) | ||
| { | ||
| return redirect()->intended($this->redirectPath()); | ||
| } | ||
|
|
||
| return redirect($this->loginPath()) | ||
| ->withInput($request->only('email', 'remember')) | ||
| ->withErrors([ | ||
| 'email' => 'These credentials do not match our records.', | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Log the user out of the application. | ||
| * | ||
| * @return \Illuminate\Http\Response | ||
| */ | ||
| public function getLogout() | ||
| { | ||
| Auth::logout(); | ||
|
|
||
| return redirect('/'); | ||
| } | ||
|
|
||
| /** | ||
| * Get the post register / login redirect path. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function redirectPath() | ||
| { | ||
| if (property_exists($this, 'redirectPath')) | ||
| { | ||
| return $this->redirectPath; | ||
| } | ||
|
|
||
| return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home'; | ||
| } | ||
|
|
||
| /** | ||
| * Get the path to the login route. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function loginPath() | ||
| { | ||
| return property_exists($this, 'loginPath') ? $this->loginPath : '/auth/login'; | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need a new line before the closing brace. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nooo. You absolutely cannot do that. You MUST use the actual class name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you refer to the line above, I didn't touch it cause its not mine, its in the existing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's wrong and must be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do.