Skip to content

Commit

Permalink
added feature to generate email addresses for accounts with missing e…
Browse files Browse the repository at this point in the history
…mails
  • Loading branch information
Joel Butcher committed Feb 5, 2021
1 parent 3ea3592 commit 83f9141
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public static function enabled(string $feature)
return in_array($feature, config('socialstream.features', []));
}

/**
* Determine if the application has the generates missing emails feature enabled.
*
* @return bool
*/
public static function generatesMissingEmails()
{
return static::enabled(static::generateMissingEmails());
}

/**
* Determine if the application supports creating accounts
* when logging in for the first time via a provider.
Expand Down Expand Up @@ -46,6 +56,16 @@ public static function hasRememberSessionFeatures()
return static::enabled(static::rememberSession());
}

/**
* Enabled the generate missing emails feature.
*
* @return string
*/
public static function generateMissingEmails()
{
'generate-missing-emails';
}

/**
* Enable the create account on first login feature.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Http/Controllers/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public function handleProviderCallback(Request $request, string $provider)

try {
$providerAccount = Socialite::driver($provider)->user();

if (Socialstream::generatesMissingEmails()) {
$providerAccount->email = $providerAccount->getEmail() ?? "{$providerAccount->id}@{$provider}".config('app.domain');
}

} catch (InvalidStateException $e) {
$this->invalidStateHandler->handle($e);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Socialstream.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ public static function hasTwitterSupport()
return Providers::hasTwitterSupport();
}

/**
* Determine if the application has the generates missing emails feature enabled.
*
* @return bool
*/
public static function generatesMissingEmails()
{
return Features::generatesMissingEmails();
}

/**
* Determine if the application has the create account on first login feature.
*
Expand Down

0 comments on commit 83f9141

Please sign in to comment.