Skip to content

Commit

Permalink
feat: configure provider names and labels
Browse files Browse the repository at this point in the history
  • Loading branch information
joelbutcher committed Oct 12, 2023
1 parent a737057 commit 24a99bb
Show file tree
Hide file tree
Showing 71 changed files with 804 additions and 601 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"require": {
"php": "^8.1",
"laravel/prompts": "^0.1.10",
"laravel/socialite": "^5.9"
"laravel/socialite": "^5.9",
"webmozart/assert": "^1.11"
},
"require-dev": {
"laravel/jetstream": "^4.0",
Expand Down
1 change: 1 addition & 0 deletions config/socialstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

return [
'middleware' => ['web'],
'prompt' => 'Or Login Via',
'providers' => [
// Providers::github(),
],
Expand Down
17 changes: 9 additions & 8 deletions src/Actions/Auth/Breeze/Blade/AuthenticateOauthCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use JoelButcher\Socialstream\Contracts\CreatesUserFromProvider;
use JoelButcher\Socialstream\Contracts\UpdatesConnectedAccounts;
use JoelButcher\Socialstream\Features;
use JoelButcher\Socialstream\Providers;
use JoelButcher\Socialstream\Socialstream;
use Laravel\Socialite\Contracts\User as ProviderUser;

Expand Down Expand Up @@ -59,7 +60,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => $provider])
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => Providers::name($provider)])
);

return redirect()->route('login')->withErrors(
Expand All @@ -72,7 +73,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => $provider])
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('login')->withErrors(
Expand Down Expand Up @@ -102,19 +103,19 @@ protected function alreadyAuthenticated(Authenticatable $user, ?ConnectedAccount
$this->createsConnectedAccounts->create($user, $provider, $providerAccount);

return redirect()->route('profile.edit')->with(
'status', __('You have successfully connected :Provider to your account.', ['provider' => $provider])
'status', __('You have successfully connected :Provider to your account.', ['provider' => Providers::name($provider)])
);
}

if ($account->user_id !== $user->id) {
return redirect()->route('profile.edit')->withErrors(
['callback' => __('This :Provider sign in account is already associated with another user. Please log in with that user or connect a different :Provider account.', ['provider' => $provider])]
['callback' => __('This :Provider sign in account is already associated with another user. Please log in with that user or connect a different :Provider account.', ['provider' => Providers::name($provider)])]
);
}

// Account already connected
return redirect()->route('profile.edit')->withErrors(
['callback' => __('This :Provider sign in account is already associated with your user.', ['provider' => $provider])]
['callback' => __('This :Provider sign in account is already associated with your user.', ['provider' => Providers::name($provider)])]
);
}

Expand All @@ -133,7 +134,7 @@ protected function alreadyRegistered(Authenticatable $user, ?ConnectedAccount $a
}

$messageBag = new MessageBag;
$messageBag->add('socialstream', __('An account with that :Provider sign in already exists, please login.', ['provider' => $provider]));
$messageBag->add('socialstream', __('An account with that :Provider sign in already exists, please login.', ['provider' => Providers::name($provider)]));

return redirect()->route('login')->withErrors($messageBag);
}
Expand All @@ -147,7 +148,7 @@ protected function register(string $provider, ProviderUser $providerAccount): Re
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('No email address is associated with this :Provider account. Please try a different account.', ['provider' => $provider])
__('No email address is associated with this :Provider account. Please try a different account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('register')->withErrors($messageBag);
Expand All @@ -157,7 +158,7 @@ protected function register(string $provider, ProviderUser $providerAccount): Re
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => $provider])
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('register')->withErrors($messageBag);
Expand Down
21 changes: 11 additions & 10 deletions src/Actions/Auth/Breeze/Livewire/AuthenticateOauthCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use JoelButcher\Socialstream\Contracts\CreatesUserFromProvider;
use JoelButcher\Socialstream\Contracts\UpdatesConnectedAccounts;
use JoelButcher\Socialstream\Features;
use JoelButcher\Socialstream\Providers;
use JoelButcher\Socialstream\Socialstream;
use Laravel\Socialite\Contracts\User as ProviderUser;

Expand Down Expand Up @@ -59,7 +60,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => $provider])
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => Providers::name($provider)])
);

return redirect()->route('login')->withErrors(
Expand All @@ -72,7 +73,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => $provider])
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('login')->withErrors(
Expand All @@ -89,7 +90,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => $provider])
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => Providers::name($provider)])
);

return redirect()->route('login')->withErrors(
Expand All @@ -102,7 +103,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => $provider])
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('login')->withErrors(
Expand Down Expand Up @@ -132,19 +133,19 @@ protected function alreadyAuthenticated(Authenticatable $user, ?ConnectedAccount
$this->createsConnectedAccounts->create($user, $provider, $providerAccount);

return redirect()->route('profile')->with(
'status', __('You have successfully connected :Provider to your account.', ['provider' => $provider])
'status', __('You have successfully connected :Provider to your account.', ['provider' => Providers::name($provider)])
);
}

if ($account->user_id !== $user->id) {
return redirect()->route('profile')->withErrors(
['callback' => __('This :Provider sign in account is already associated with another user. Please log in with that user or connect a different :Provider account.', ['provider' => $provider])]
['callback' => __('This :Provider sign in account is already associated with another user. Please log in with that user or connect a different :Provider account.', ['provider' => Providers::name($provider)])]
);
}

// Account already connected
return redirect()->route('profile')->withErrors(
['callback' => __('This :Provider sign in account is already associated with your user.', ['provider' => $provider])]
['callback' => __('This :Provider sign in account is already associated with your user.', ['provider' => Providers::name($provider)])]
);
}

Expand All @@ -163,7 +164,7 @@ protected function alreadyRegistered(Authenticatable $user, ?ConnectedAccount $a
}

$messageBag = new MessageBag;
$messageBag->add('socialstream', __('An account with that :Provider sign in already exists, please login.', ['provider' => $provider]));
$messageBag->add('socialstream', __('An account with that :Provider sign in already exists, please login.', ['provider' => Providers::name($provider)]));

return redirect()->route('login')->withErrors($messageBag);
}
Expand All @@ -177,7 +178,7 @@ protected function register(string $provider, ProviderUser $providerAccount): Re
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('No email address is associated with this :Provider account. Please try a different account.', ['provider' => $provider])
__('No email address is associated with this :Provider account. Please try a different account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('register')->withErrors($messageBag);
Expand All @@ -187,7 +188,7 @@ protected function register(string $provider, ProviderUser $providerAccount): Re
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => $provider])
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('register')->withErrors($messageBag);
Expand Down
21 changes: 11 additions & 10 deletions src/Actions/Auth/Filament/AuthenticateOauthCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use JoelButcher\Socialstream\Contracts\CreatesUserFromProvider;
use JoelButcher\Socialstream\Contracts\UpdatesConnectedAccounts;
use JoelButcher\Socialstream\Features;
use JoelButcher\Socialstream\Providers;
use JoelButcher\Socialstream\Socialstream;
use Laravel\Socialite\Contracts\User as ProviderUser;

Expand Down Expand Up @@ -59,7 +60,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => $provider])
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => Providers::name($provider)])
);

return redirect()->route('filament.admin.auth.login')->withErrors(
Expand All @@ -72,7 +73,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => $provider])
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('filament.admin.auth.login')->withErrors(
Expand All @@ -89,7 +90,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => $provider])
__('An account with this :Provider sign in was not found. Please register or try a different sign in method.', ['provider' => Providers::name($provider)])
);

return redirect()->route('filament.admin.auth.login')->withErrors(
Expand All @@ -102,7 +103,7 @@ public function authenticate(string $provider, ProviderUser $providerAccount): R
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => $provider])
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('filament.admin.auth.login')->withErrors(
Expand Down Expand Up @@ -132,19 +133,19 @@ protected function alreadyAuthenticated(Authenticatable $user, ?ConnectedAccount
$this->createsConnectedAccounts->create($user, $provider, $providerAccount);

return redirect()->route('profile')->with(
'status', __('You have successfully connected :Provider to your account.', ['provider' => $provider])
'status', __('You have successfully connected :Provider to your account.', ['provider' => Providers::name($provider)])
);
}

if ($account->user_id !== $user->id) {
return redirect()->route('profile')->withErrors(
['callback' => __('This :Provider sign in account is already associated with another user. Please log in with that user or connect a different :Provider account.', ['provider' => $provider])]
['callback' => __('This :Provider sign in account is already associated with another user. Please log in with that user or connect a different :Provider account.', ['provider' => Providers::name($provider)])]
);
}

// Account already connected
return redirect()->route('profile')->withErrors(
['callback' => __('This :Provider sign in account is already associated with your user.', ['provider' => $provider])]
['callback' => __('This :Provider sign in account is already associated with your user.', ['provider' => Providers::name($provider)])]
);
}

Expand All @@ -163,7 +164,7 @@ protected function alreadyRegistered(Authenticatable $user, ?ConnectedAccount $a
}

$messageBag = new MessageBag;
$messageBag->add('socialstream', __('An account with that :Provider sign in already exists, please login.', ['provider' => $provider]));
$messageBag->add('socialstream', __('An account with that :Provider sign in already exists, please login.', ['provider' => Providers::name($provider)]));

return redirect()->route('filament.admin.auth.login')->withErrors($messageBag);
}
Expand All @@ -177,7 +178,7 @@ protected function register(string $provider, ProviderUser $providerAccount): Re
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('No email address is associated with this :Provider account. Please try a different account.', ['provider' => $provider])
__('No email address is associated with this :Provider account. Please try a different account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('filament.admin.auth.login')->withErrors($messageBag);
Expand All @@ -187,7 +188,7 @@ protected function register(string $provider, ProviderUser $providerAccount): Re
$messageBag = new MessageBag;
$messageBag->add(
'socialstream',
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => $provider])
__('An account with that email address already exists. Please login to connect your :Provider account.', ['provider' => Providers::name($provider)])
);

return redirect()->route('filament.admin.auth.login')->withErrors($messageBag);
Expand Down
Loading

0 comments on commit 24a99bb

Please sign in to comment.