-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure Jetstream classes in providers and separate panels into Adm…
…in and App
- Loading branch information
1 parent
38e67cb
commit 7fd4713
Showing
38 changed files
with
912 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?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<string, string> $input | ||
*/ | ||
public function create(array $input): User | ||
{ | ||
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. | ||
*/ | ||
protected function createTeam(User $user): void | ||
{ | ||
$user->ownedTeams()->save(Team::forceCreate([ | ||
'user_id' => $user->id, | ||
'name' => explode(' ', $user->name, 2)[0]."'s Team", | ||
'personal_team' => true, | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Actions\Jetstream; | ||
|
||
use App\Models\Team; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\DB; | ||
use Laravel\Jetstream\Contracts\DeletesTeams; | ||
use Laravel\Jetstream\Contracts\DeletesUsers; | ||
|
||
class DeleteUser implements DeletesUsers | ||
{ | ||
/** | ||
* Create a new action instance. | ||
*/ | ||
public function __construct(protected DeletesTeams $deletesTeams) | ||
{ | ||
} | ||
|
||
/** | ||
* Delete the given user. | ||
*/ | ||
public function delete(User $user): void | ||
{ | ||
DB::transaction(function () use ($user) { | ||
$this->deleteTeams($user); | ||
$user->deleteProfilePhoto(); | ||
$user->tokens->each->delete(); | ||
$user->delete(); | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the teams and team associations attached to the user. | ||
*/ | ||
protected function deleteTeams(User $user): void | ||
{ | ||
$user->teams()->detach(); | ||
|
||
$user->ownedTeams->each(function (Team $team) { | ||
$this->deletesTeams->delete($team); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/Actions/Socialstream/CreateUserWithTeamsFromProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Actions\Socialstream; | ||
|
||
use App\Models\Team; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\DB; | ||
use JoelButcher\Socialstream\Contracts\CreatesConnectedAccounts; | ||
use JoelButcher\Socialstream\Contracts\CreatesUserFromProvider; | ||
use JoelButcher\Socialstream\Socialstream; | ||
use Laravel\Socialite\Contracts\User as ProviderUserContract; | ||
|
||
class CreateUserFromProvider implements CreatesUserFromProvider | ||
{ | ||
/** | ||
* The creates connected accounts instance. | ||
*/ | ||
public CreatesConnectedAccounts $createsConnectedAccounts; | ||
|
||
/** | ||
* Create a new action instance. | ||
*/ | ||
public function __construct(CreatesConnectedAccounts $createsConnectedAccounts) | ||
{ | ||
$this->createsConnectedAccounts = $createsConnectedAccounts; | ||
} | ||
|
||
/** | ||
* Create a new user from a social provider user. | ||
*/ | ||
public function create(string $provider, ProviderUserContract $providerUser): User | ||
{ | ||
return DB::transaction(function () use ($provider, $providerUser) { | ||
return tap(User::create([ | ||
'name' => $providerUser->getName(), | ||
'email' => $providerUser->getEmail(), | ||
]), function (User $user) use ($provider, $providerUser) { | ||
$user->markEmailAsVerified(); | ||
|
||
if (Socialstream::hasProviderAvatarsFeature() && $providerUser->getAvatar()) { | ||
$user->setProfilePhotoFromUrl($providerUser->getAvatar()); | ||
} | ||
|
||
$this->createsConnectedAccounts->create($user, $provider, $providerUser); | ||
|
||
$this->createTeam($user); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Create a personal team for the user. | ||
*/ | ||
protected function createTeam(User $user): void | ||
{ | ||
$user->ownedTeams()->save(Team::forceCreate([ | ||
'user_id' => $user->id, | ||
'name' => explode(' ', $user->name, 2)[0]."'s Team", | ||
'personal_team' => true, | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Password; | ||
use Laravel\Jetstream\Http\Controllers\AuthenticatedSessionController; | ||
|
||
class AdminForgotPasswordController extends AuthenticatedSessionController | ||
{ | ||
public function showLinkRequestForm() | ||
{ | ||
return view('admin.auth.forgot-password'); | ||
} | ||
|
||
public function sendResetLinkEmail(Request $request) | ||
{ | ||
$request->validate(['email' => 'required|email']); | ||
|
||
$status = Password::broker('admins')->sendResetLink( | ||
$request->only('email') | ||
); | ||
|
||
return $status === Password::RESET_LINK_SENT | ||
? back()->with(['status' => __($status)]) | ||
: back()->withErrors(['email' => __($status)]); | ||
} | ||
} |
Oops, something went wrong.