initial commit
This commit is contained in:
		
							
								
								
									
										57
									
								
								app/Actions/Fortify/CreateNewUser.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								app/Actions/Fortify/CreateNewUser.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Actions\Fortify; | ||||
| 
 | ||||
| use App\Models\Team; | ||||
| use App\Models\User; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use Illuminate\Support\Facades\Hash; | ||||
| use Illuminate\Support\Facades\Validator; | ||||
| use Laravel\Fortify\Contracts\CreatesNewUsers; | ||||
| use Laravel\Jetstream\Jetstream; | ||||
| 
 | ||||
| class CreateNewUser implements CreatesNewUsers | ||||
| { | ||||
|     use PasswordValidationRules; | ||||
| 
 | ||||
|     /** | ||||
|      * Create a newly registered user. | ||||
|      * | ||||
|      * @param  array  $input | ||||
|      * @return \App\Models\User | ||||
|      */ | ||||
|     public function create(array $input) | ||||
|     { | ||||
|         Validator::make($input, [ | ||||
|             'name' => ['required', 'string', 'max:255'], | ||||
|             'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], | ||||
|             'password' => $this->passwordRules(), | ||||
|             'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '', | ||||
|         ])->validate(); | ||||
| 
 | ||||
|         return DB::transaction(function () use ($input) { | ||||
|             return tap(User::create([ | ||||
|                 'name' => $input['name'], | ||||
|                 'email' => $input['email'], | ||||
|                 'password' => Hash::make($input['password']), | ||||
|             ]), function (User $user) { | ||||
|                 $this->createTeam($user); | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Create a personal team for the user. | ||||
|      * | ||||
|      * @param  \App\Models\User  $user | ||||
|      * @return void | ||||
|      */ | ||||
|     protected function createTeam(User $user) | ||||
|     { | ||||
|         $user->ownedTeams()->save(Team::forceCreate([ | ||||
|             'user_id' => $user->id, | ||||
|             'name' => explode(' ', $user->name, 2)[0]."'s Team", | ||||
|             'personal_team' => true, | ||||
|         ])); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										18
									
								
								app/Actions/Fortify/PasswordValidationRules.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								app/Actions/Fortify/PasswordValidationRules.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Actions\Fortify; | ||||
| 
 | ||||
| use Laravel\Fortify\Rules\Password; | ||||
| 
 | ||||
| trait PasswordValidationRules | ||||
| { | ||||
|     /** | ||||
|      * Get the validation rules used to validate passwords. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function passwordRules() | ||||
|     { | ||||
|         return ['required', 'string', new Password, 'confirmed']; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										30
									
								
								app/Actions/Fortify/ResetUserPassword.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								app/Actions/Fortify/ResetUserPassword.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Actions\Fortify; | ||||
| 
 | ||||
| use Illuminate\Support\Facades\Hash; | ||||
| use Illuminate\Support\Facades\Validator; | ||||
| use Laravel\Fortify\Contracts\ResetsUserPasswords; | ||||
| 
 | ||||
| class ResetUserPassword implements ResetsUserPasswords | ||||
| { | ||||
|     use PasswordValidationRules; | ||||
| 
 | ||||
|     /** | ||||
|      * Validate and reset the user's forgotten password. | ||||
|      * | ||||
|      * @param  mixed  $user | ||||
|      * @param  array  $input | ||||
|      * @return void | ||||
|      */ | ||||
|     public function reset($user, array $input) | ||||
|     { | ||||
|         Validator::make($input, [ | ||||
|             'password' => $this->passwordRules(), | ||||
|         ])->validate(); | ||||
| 
 | ||||
|         $user->forceFill([ | ||||
|             'password' => Hash::make($input['password']), | ||||
|         ])->save(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										35
									
								
								app/Actions/Fortify/UpdateUserPassword.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								app/Actions/Fortify/UpdateUserPassword.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Actions\Fortify; | ||||
| 
 | ||||
| use Illuminate\Support\Facades\Hash; | ||||
| use Illuminate\Support\Facades\Validator; | ||||
| use Laravel\Fortify\Contracts\UpdatesUserPasswords; | ||||
| 
 | ||||
| class UpdateUserPassword implements UpdatesUserPasswords | ||||
| { | ||||
|     use PasswordValidationRules; | ||||
| 
 | ||||
|     /** | ||||
|      * Validate and update the user's password. | ||||
|      * | ||||
|      * @param  mixed  $user | ||||
|      * @param  array  $input | ||||
|      * @return void | ||||
|      */ | ||||
|     public function update($user, array $input) | ||||
|     { | ||||
|         Validator::make($input, [ | ||||
|             'current_password' => ['required', 'string'], | ||||
|             'password' => $this->passwordRules(), | ||||
|         ])->after(function ($validator) use ($user, $input) { | ||||
|             if (! isset($input['current_password']) || ! Hash::check($input['current_password'], $user->password)) { | ||||
|                 $validator->errors()->add('current_password', __('The provided password does not match your current password.')); | ||||
|             } | ||||
|         })->validateWithBag('updatePassword'); | ||||
| 
 | ||||
|         $user->forceFill([ | ||||
|             'password' => Hash::make($input['password']), | ||||
|         ])->save(); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										59
									
								
								app/Actions/Fortify/UpdateUserProfileInformation.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								app/Actions/Fortify/UpdateUserProfileInformation.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,59 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Actions\Fortify; | ||||
| 
 | ||||
| use Illuminate\Contracts\Auth\MustVerifyEmail; | ||||
| use Illuminate\Support\Facades\Validator; | ||||
| use Illuminate\Validation\Rule; | ||||
| use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; | ||||
| 
 | ||||
| class UpdateUserProfileInformation implements UpdatesUserProfileInformation | ||||
| { | ||||
|     /** | ||||
|      * Validate and update the given user's profile information. | ||||
|      * | ||||
|      * @param  mixed  $user | ||||
|      * @param  array  $input | ||||
|      * @return void | ||||
|      */ | ||||
|     public function update($user, array $input) | ||||
|     { | ||||
|         Validator::make($input, [ | ||||
|             'name' => ['required', 'string', 'max:255'], | ||||
|             'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)], | ||||
|             'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'], | ||||
|         ])->validateWithBag('updateProfileInformation'); | ||||
| 
 | ||||
|         if (isset($input['photo'])) { | ||||
|             $user->updateProfilePhoto($input['photo']); | ||||
|         } | ||||
| 
 | ||||
|         if ($input['email'] !== $user->email && | ||||
|             $user instanceof MustVerifyEmail) { | ||||
|             $this->updateVerifiedUser($user, $input); | ||||
|         } else { | ||||
|             $user->forceFill([ | ||||
|                 'name' => $input['name'], | ||||
|                 'email' => $input['email'], | ||||
|             ])->save(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Update the given verified user's profile information. | ||||
|      * | ||||
|      * @param  mixed  $user | ||||
|      * @param  array  $input | ||||
|      * @return void | ||||
|      */ | ||||
|     protected function updateVerifiedUser($user, array $input) | ||||
|     { | ||||
|         $user->forceFill([ | ||||
|             'name' => $input['name'], | ||||
|             'email' => $input['email'], | ||||
|             'email_verified_at' => null, | ||||
|         ])->save(); | ||||
| 
 | ||||
|         $user->sendEmailVerificationNotification(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user