pixelfed/app/Listeners/AuthLogin.php

61 lines
1.6 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,
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-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
}
2018-12-09 02:36:03 +00:00
if(empty($user->profile)) {
DB::transaction(function() use($user) {
$profile = new Profile();
$profile->user_id = $user->id;
$profile->username = $user->username;
$profile->name = $user->name;
$pkiConfig = [
'digest_alg' => 'sha512',
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
];
$pki = openssl_pkey_new($pkiConfig);
openssl_pkey_export($pki, $pki_private);
$pki_public = openssl_pkey_get_details($pki);
$pki_public = $pki_public['key'];
2018-11-27 08:54:10 +00:00
2018-12-09 02:36:03 +00:00
$profile->private_key = $pki_private;
$profile->public_key = $pki_public;
$profile->save();
2018-11-27 08:54:10 +00:00
2018-12-09 02:36:03 +00:00
CreateAvatar::dispatch($profile);
});
}
2018-07-23 17:29:20 +00:00
}
}