mirror of https://github.com/pixelfed/pixelfed
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
PHTML
55 lines
1.5 KiB
PHTML
7 years ago
|
<?php
|
||
|
|
||
|
namespace App\Observers;
|
||
|
|
||
7 years ago
|
use App\Jobs\AvatarPipeline\CreateAvatar;
|
||
7 years ago
|
use App\Profile;
|
||
|
use App\User;
|
||
|
use App\UserSetting;
|
||
6 years ago
|
use DB;
|
||
7 years ago
|
|
||
|
class UserObserver
|
||
|
{
|
||
|
/**
|
||
|
* Listen to the User created event.
|
||
|
*
|
||
7 years ago
|
* @param \App\User $user
|
||
|
*
|
||
7 years ago
|
* @return void
|
||
|
*/
|
||
|
public function saved(User $user)
|
||
|
{
|
||
7 years ago
|
if (empty($user->profile)) {
|
||
6 years ago
|
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'];
|
||
7 years ago
|
|
||
6 years ago
|
$profile->private_key = $pki_private;
|
||
|
$profile->public_key = $pki_public;
|
||
|
$profile->save();
|
||
7 years ago
|
|
||
6 years ago
|
CreateAvatar::dispatch($profile);
|
||
|
});
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
if (empty($user->settings)) {
|
||
6 years ago
|
DB::transaction(function() use($user) {
|
||
|
UserSetting::firstOrCreate([
|
||
|
'user_id' => $user->id
|
||
|
]);
|
||
|
});
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|