Browse Source

Organize requests differently.

Taylor Otwell 10 years ago
parent
commit
d306965007

+ 5 - 15
app/Http/Controllers/Auth/AuthController.php

@@ -1,7 +1,7 @@
 <?php namespace App\Http\Controllers\Auth;
 <?php namespace App\Http\Controllers\Auth;
 
 
 use App\User;
 use App\User;
-use Illuminate\Http\Request;
+use App\Http\Requests;
 use App\Http\Controllers\Controller;
 use App\Http\Controllers\Controller;
 use Illuminate\Contracts\Auth\Guard;
 use Illuminate\Contracts\Auth\Guard;
 
 
@@ -40,17 +40,11 @@ class AuthController extends Controller {
 	/**
 	/**
 	 * Handle a registration request for the application.
 	 * Handle a registration request for the application.
 	 *
 	 *
-	 * @param  Request  $request
+	 * @param  RegisterRequest  $request
 	 * @return Response
 	 * @return Response
 	 */
 	 */
-	public function postRegister(Request $request)
+	public function postRegister(Requests\Auth\RegisterRequest $request)
 	{
 	{
-		$this->validate($request, [
-			'name' => 'required|max:255',
-			'email' => 'required|email|max:255|unique:users',
-			'password' => 'required|min:6|confirmed',
-		]);
-
 		$user = User::forceCreate([
 		$user = User::forceCreate([
 			'name' => $request->name,
 			'name' => $request->name,
 			'email' => $request->email,
 			'email' => $request->email,
@@ -75,15 +69,11 @@ class AuthController extends Controller {
 	/**
 	/**
 	 * Handle a login request to the application.
 	 * Handle a login request to the application.
 	 *
 	 *
-	 * @param  Request  $request
+	 * @param  LoginRequest  $request
 	 * @return Response
 	 * @return Response
 	 */
 	 */
-	public function postLogin(Request $request)
+	public function postLogin(Requests\Auth\LoginRequest $request)
 	{
 	{
-		$this->validate($request, [
-			'email' => 'required', 'password' => 'required'
-		]);
-
 		$credentials = $request->only('email', 'password');
 		$credentials = $request->only('email', 'password');
 
 
 		if ($this->auth->attempt($credentials, $request->has('remember')))
 		if ($this->auth->attempt($credentials, $request->has('remember')))

+ 5 - 7
app/Http/Controllers/Auth/PasswordController.php

@@ -1,7 +1,7 @@
 <?php namespace App\Http\Controllers\Auth;
 <?php namespace App\Http\Controllers\Auth;
 
 
 use App\User;
 use App\User;
-use Illuminate\Http\Request;
+use App\Http\Requests;
 use App\Http\Controllers\Controller;
 use App\Http\Controllers\Controller;
 use Illuminate\Contracts\Auth\Guard;
 use Illuminate\Contracts\Auth\Guard;
 use Illuminate\Contracts\Auth\PasswordBroker;
 use Illuminate\Contracts\Auth\PasswordBroker;
@@ -50,13 +50,11 @@ class PasswordController extends Controller {
 	/**
 	/**
 	 * Send a reset link to the given user.
 	 * Send a reset link to the given user.
 	 *
 	 *
-	 * @param  Request  $request
+	 * @param  EmailPasswordLinkRequest  $request
 	 * @return Response
 	 * @return Response
 	 */
 	 */
-	public function postEmail(Request $request)
+	public function postEmail(Requests\Auth\EmailPasswordLinkRequest $request)
 	{
 	{
-		$this->validate($request, ['email' => 'required']);
-
 		switch ($response = $this->passwords->sendResetLink($request->only('email')))
 		switch ($response = $this->passwords->sendResetLink($request->only('email')))
 		{
 		{
 			case PasswordBroker::INVALID_USER:
 			case PasswordBroker::INVALID_USER:
@@ -86,10 +84,10 @@ class PasswordController extends Controller {
 	/**
 	/**
 	 * Reset the given user's password.
 	 * Reset the given user's password.
 	 *
 	 *
-	 * @param  Request  $request
+	 * @param  ResetPasswordRequest  $request
 	 * @return Response
 	 * @return Response
 	 */
 	 */
-	public function postReset(Request $request)
+	public function postReset(Requests\Auth\ResetPasswordRequest $request)
 	{
 	{
 		$credentials = $request->only(
 		$credentials = $request->only(
 			'email', 'password', 'password_confirmation', 'token'
 			'email', 'password', 'password_confirmation', 'token'

+ 29 - 0
app/Http/Requests/Auth/EmailPasswordLinkRequest.php

@@ -0,0 +1,29 @@
+<?php namespace App\Http\Requests\Auth;
+
+use App\Http\Requests\Request;
+
+class EmailPasswordLinkRequest extends Request {
+
+	/**
+	 * Get the validation rules that apply to the request.
+	 *
+	 * @return array
+	 */
+	public function rules()
+	{
+		return [
+			'email' => 'required',
+		];
+	}
+
+	/**
+	 * Determine if the user is authorized to make this request.
+	 *
+	 * @return bool
+	 */
+	public function authorize()
+	{
+		return true;
+	}
+
+}

+ 29 - 0
app/Http/Requests/Auth/LoginRequest.php

@@ -0,0 +1,29 @@
+<?php namespace App\Http\Requests\Auth;
+
+use App\Http\Requests\Request;
+
+class LoginRequest extends Request {
+
+	/**
+	 * Get the validation rules that apply to the request.
+	 *
+	 * @return array
+	 */
+	public function rules()
+	{
+		return [
+			'email' => 'required', 'password' => 'required',
+		];
+	}
+
+	/**
+	 * Determine if the user is authorized to make this request.
+	 *
+	 * @return bool
+	 */
+	public function authorize()
+	{
+		return true;
+	}
+
+}

+ 31 - 0
app/Http/Requests/Auth/RegisterRequest.php

@@ -0,0 +1,31 @@
+<?php namespace App\Http\Requests\Auth;
+
+use App\Http\Requests\Request;
+
+class RegisterRequest extends Request {
+
+	/**
+	 * Get the validation rules that apply to the request.
+	 *
+	 * @return array
+	 */
+	public function rules()
+	{
+		return [
+			'name' => 'required|max:255',
+			'email' => 'required|email|max:255|unique:users',
+			'password' => 'required|min:6|confirmed',
+		];
+	}
+
+	/**
+	 * Determine if the user is authorized to make this request.
+	 *
+	 * @return bool
+	 */
+	public function authorize()
+	{
+		return true;
+	}
+
+}

+ 31 - 0
app/Http/Requests/Auth/ResetPasswordRequest.php

@@ -0,0 +1,31 @@
+<?php namespace App\Http\Requests\Auth;
+
+use App\Http\Requests\Request;
+
+class ResetPasswordRequest extends Request {
+
+	/**
+	 * Get the validation rules that apply to the request.
+	 *
+	 * @return array
+	 */
+	public function rules()
+	{
+		return [
+			'token' => 'required',
+			'email' => 'required',
+			'password' => 'required|confirmed',
+		];
+	}
+
+	/**
+	 * Determine if the user is authorized to make this request.
+	 *
+	 * @return bool
+	 */
+	public function authorize()
+	{
+		return false;
+	}
+
+}