diff --git a/app/Models/Meetup.php b/app/Models/Meetup.php index 1853b1e..1969f2c 100644 --- a/app/Models/Meetup.php +++ b/app/Models/Meetup.php @@ -63,7 +63,8 @@ class Meetup extends Model implements HasMedia ->addMediaConversion('preview') ->fit(Fit::Crop, 300, 300) ->nonQueued(); - $this->addMediaConversion('thumb') + $this + ->addMediaConversion('thumb') ->fit(Fit::Crop, 130, 130) ->width(130) ->height(130); @@ -71,7 +72,8 @@ class Meetup extends Model implements HasMedia public function registerMediaCollections(): void { - $this->addMediaCollection('logo') + $this + ->addMediaCollection('logo') ->singleFile() ->useFallbackUrl(asset('img/einundzwanzig.png')); } @@ -101,7 +103,8 @@ class Meetup extends Model implements HasMedia } return Attribute::make( - get: fn() => url()->route('img', + get: fn() + => url()->route('img', [ 'path' => $path, 'w' => 900, @@ -117,9 +120,11 @@ class Meetup extends Model implements HasMedia $nextEvent = $this->meetupEvents()->where('start', '>=', now())->orderBy('start')->first(); return Attribute::make( - get: fn() => $nextEvent ? [ + get: fn() + => $nextEvent ? [ 'start' => $nextEvent->start, - 'portalLink' => url()->route('meetups.landingpage-event', ['country' => $this->city->country, 'meetup' => $this, 'event' => $nextEvent]), + 'portalLink' => url()->route('meetups.landingpage-event', + ['country' => $this->city->country, 'meetup' => $this, 'event' => $nextEvent]), 'location' => $nextEvent->location, 'description' => $nextEvent->description, 'link' => $nextEvent->link, @@ -130,6 +135,13 @@ class Meetup extends Model implements HasMedia ); } + protected function belongsToMe(): Attribute + { + return Attribute::make( + get: fn() => false, + ); + } + public function meetupEvents(): HasMany { return $this->hasMany(MeetupEvent::class); diff --git a/app/Models/User.php b/app/Models/User.php index f9d0cb3..89477ba 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -5,7 +5,9 @@ namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Http\UploadedFile; use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use ParagonIE\CipherSweet\BlindIndex; use ParagonIE\CipherSweet\EncryptedRow; @@ -14,7 +16,7 @@ use Spatie\LaravelCipherSweet\Concerns\UsesCipherSweet; use Spatie\LaravelCipherSweet\Contracts\CipherSweetEncrypted; use Spatie\Permission\Traits\HasRoles; -class User extends Authenticatable implements MustVerifyEmail, CipherSweetEncrypted +class User extends Authenticatable implements CipherSweetEncrypted { use UsesCipherSweet; use HasFactory; @@ -101,4 +103,73 @@ class User extends Authenticatable implements MustVerifyEmail, CipherSweetEncryp { return $this->belongsToMany(LibraryItem::class, 'library_item_user', 'user_id', 'library_item_id'); } + + public function updateProfilePhoto(UploadedFile $photo) + { + tap($this->profile_photo_path, function ($previous) use ($photo) { + $this->forceFill([ + 'profile_photo_path' => $photo->storePublicly( + 'profile-photos', ['disk' => $this->profilePhotoDisk()] + ), + ])->save(); + + if ($previous) { + Storage::disk($this->profilePhotoDisk())->delete($previous); + } + }); + } + + /** + * Delete the user's profile photo. + * + * @return void + */ + public function deleteProfilePhoto() + { + if (is_null($this->profile_photo_path)) { + return; + } + + Storage::disk($this->profilePhotoDisk())->delete($this->profile_photo_path); + + $this->forceFill([ + 'profile_photo_path' => null, + ])->save(); + } + + /** + * Get the URL to the user's profile photo. + * + * @return string + */ + public function getProfilePhotoUrlAttribute() + { + return $this->profile_photo_path + ? Storage::disk($this->profilePhotoDisk())->url($this->profile_photo_path) + : $this->defaultProfilePhotoUrl(); + } + + /** + * Get the default profile photo URL if no profile photo has been uploaded. + * + * @return string + */ + protected function defaultProfilePhotoUrl() + { + $name = trim(collect(explode(' ', $this->name))->map(function ($segment) { + return mb_substr($segment, 0, 1); + })->join(' ')); + + return 'https://ui-avatars.com/api/?name='.urlencode($name).'&color=7F9CF5&background=EBF4FF'; + } + + /** + * Get the disk that profile photos should be stored on. + * + * @return string + */ + protected function profilePhotoDisk() + { + return isset($_ENV['VAPOR_ARTIFACT_NAME']) ? 's3' : config('jetstream.profile_photo_disk', 'public'); + } } diff --git a/package.json b/package.json index 0deff57..db2e2da 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "axios": "^1.7.4", "concurrently": "^9.0.1", "laravel-vite-plugin": "^1.0", + "nostr-tools": "^2.17.4", "shiki": "^3.15.0", "tailwindcss": "^4.0.7", "vite": "^6.0" diff --git a/resources/js/app.js b/resources/js/app.js index e69de29..96a0138 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -0,0 +1,3 @@ +import nostrLogin from "./nostrLogin.js"; + +Alpine.data('nostrLogin', nostrLogin); diff --git a/resources/js/nostrLogin.js b/resources/js/nostrLogin.js new file mode 100644 index 0000000..50dfdcc --- /dev/null +++ b/resources/js/nostrLogin.js @@ -0,0 +1,17 @@ +import {npubEncode} from "nostr-tools/nip19"; + +export default () => ({ + + async init() { + + }, + + async openNostrLogin() { + const pubkey = await window.nostr.getPublicKey(); + const npub = npubEncode(pubkey); + console.log(pubkey); + console.log(npub); + this.$dispatch('nostrLoggedIn', {pubkey: npub}); + }, + +}); diff --git a/resources/views/components/layouts/app/header.blade.php b/resources/views/components/layouts/app/header.blade.php index 7065056..70d7ae0 100644 --- a/resources/views/components/layouts/app/header.blade.php +++ b/resources/views/components/layouts/app/header.blade.php @@ -155,5 +155,7 @@ }); + + diff --git a/resources/views/components/layouts/app/sidebar.blade.php b/resources/views/components/layouts/app/sidebar.blade.php index b9682f7..3e139d5 100644 --- a/resources/views/components/layouts/app/sidebar.blade.php +++ b/resources/views/components/layouts/app/sidebar.blade.php @@ -58,6 +58,7 @@