mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 14:37:59 +01:00
#25: Enable certain email notifications by default for new users.
Also fixes a bug with storing OAuth tokens for new users!
This commit is contained in:
parent
7ebab328d4
commit
8c7fe0ea33
2 changed files with 19 additions and 1 deletions
|
@ -26,6 +26,7 @@ use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
|||
use League\OAuth2\Client\Token\AccessToken;
|
||||
use Log;
|
||||
use Poniverse\Lib\Client;
|
||||
use Poniverse\Ponyfm\Models\Activity;
|
||||
use Poniverse\Ponyfm\Models\User;
|
||||
use Auth;
|
||||
use DB;
|
||||
|
@ -106,12 +107,17 @@ class AuthController extends Controller
|
|||
// Check by login name to see if they already have an account
|
||||
$user = User::findOrCreate($poniverseUser->username, $poniverseUser->display_name, $poniverseUser->email);
|
||||
|
||||
if (!$user->wasRecentlyCreated) {
|
||||
if ($user->wasRecentlyCreated) {
|
||||
// We need to insert a new token row :O
|
||||
$setData['user_id'] = $user->id;
|
||||
$setData['external_user_id'] = $poniverseUser->id;
|
||||
$setData['service'] = 'poniverse';
|
||||
DB::table('oauth2_tokens')->insert($setData);
|
||||
|
||||
// Subscribe the user to default email notifications
|
||||
foreach (Activity::DEFAULT_EMAIL_TYPES as $activityType) {
|
||||
$user->emailSubscriptions()->create(['activity_type' => $activityType]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -79,6 +79,18 @@ class Activity extends Model
|
|||
const TYPE_NEW_COMMENT = 6;
|
||||
const TYPE_CONTENT_FAVOURITED = 7;
|
||||
|
||||
/**
|
||||
* Activity types to subscribe new users to email notifications for.
|
||||
*/
|
||||
const DEFAULT_EMAIL_TYPES = [
|
||||
Activity::TYPE_PUBLISHED_TRACK,
|
||||
Activity::TYPE_PUBLISHED_ALBUM,
|
||||
Activity::TYPE_PUBLISHED_PLAYLIST,
|
||||
Activity::TYPE_NEW_FOLLOWER,
|
||||
Activity::TYPE_NEW_COMMENT,
|
||||
Activity::TYPE_CONTENT_FAVOURITED,
|
||||
];
|
||||
|
||||
/**
|
||||
* These "target" constants are an implementation detail of this model and
|
||||
* should not be used directly in other classes. They're used to efficiently
|
||||
|
|
Loading…
Reference in a new issue