1
0
Fork 0
pixelfed/app/Listeners/AuthLogin.php

92 lines
2.1 KiB
PHP
Raw Normal View History

2018-07-23 17:29:20 +00:00
<?php
2018-09-16 00:36:04 +00:00
namespace App\Listeners;
2018-07-23 17:29:20 +00:00
2018-11-27 08:54:10 +00:00
use DB, Cache;
use App\{
Follower,
2018-12-16 02:54:47 +00:00
Profile,
2018-11-27 08:54:10 +00:00
User,
2019-03-06 07:55:03 +00:00
UserDevice,
2018-11-27 08:54:10 +00:00
UserFilter,
UserSetting
};
2018-09-16 00:36:04 +00:00
use Illuminate\Queue\InteractsWithQueue;
2018-12-16 02:54:47 +00:00
use App\Jobs\AvatarPipeline\CreateAvatar;
2018-09-16 00:36:04 +00:00
use Illuminate\Contracts\Queue\ShouldQueue;
2018-07-23 17:29:20 +00:00
2018-09-16 00:36:04 +00:00
class AuthLogin
2018-07-23 17:29:20 +00:00
{
2018-09-16 00:36:04 +00:00
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
2018-07-23 17:29:20 +00:00
{
2018-09-16 00:36:04 +00:00
$user = $event->user;
2018-12-21 19:54:14 +00:00
if(!$user) {
return;
}
2019-03-06 07:55:03 +00:00
$this->userSettings($user);
$this->userState($user);
$this->userDevice($user);
}
protected function userSettings($user)
{
2018-08-28 03:07:36 +00:00
if (empty($user->settings)) {
2018-10-24 18:41:14 +00:00
DB::transaction(function() use($user) {
UserSetting::firstOrCreate([
'user_id' => $user->id
]);
});
2018-07-23 17:29:20 +00:00
}
2019-03-06 07:55:03 +00:00
}
protected function userState($user)
{
2018-12-25 05:42:15 +00:00
if($user->status != null) {
$profile = $user->profile;
2019-01-08 02:31:55 +00:00
if(!$profile) {
return;
}
2018-12-25 05:42:15 +00:00
switch ($user->status) {
case 'disabled':
$profile->status = null;
$user->status = null;
$profile->save();
$user->save();
break;
case 'delete':
$profile->status = null;
$profile->delete_after = null;
$user->status = null;
$user->delete_after = null;
$profile->save();
$user->save();
break;
default:
# code...
break;
}
}
2018-07-23 17:29:20 +00:00
}
2019-03-06 07:55:03 +00:00
protected function userDevice($user)
{
$device = DB::transaction(function() use($user) {
return UserDevice::firstOrCreate([
'user_id' => $user->id,
'ip' => request()->ip(),
'user_agent' => request()->userAgent(),
]);
});
}
2018-07-23 17:29:20 +00:00
}