Skip to content

Commit

Permalink
Merge branch 'release/v3.0.0' of https://github.com/corowne/lorekeeper
Browse files Browse the repository at this point in the history
…into extension/character-likes

# Conflicts:
#	app/Console/Commands/AddSiteSettings.php
#	app/Http/Controllers/Characters/CharacterController.php
#	app/Models/Character/CharacterProfile.php
#	app/Models/User/User.php
#	app/Models/User/UserSettings.php
#	app/Services/UserService.php
#	resources/views/account/settings.blade.php
#	resources/views/browse/_sidebar.blade.php
#	resources/views/character/_header.blade.php
#	routes/lorekeeper/browse.php
  • Loading branch information
ScuffedNewt committed Oct 25, 2024
2 parents 33f0578 + 75861a9 commit 9a89295
Show file tree
Hide file tree
Showing 808 changed files with 73,536 additions and 35,075 deletions.
6 changes: 6 additions & 0 deletions .bladeformatterrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"indentSize": 4,
"wrapLineLength": 250,
"endWithNewLine": true,
"useTabs": false
}
1 change: 1 addition & 0 deletions .bladeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/*
27 changes: 27 additions & 0 deletions .github/workflows/Lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
types:
- opened
- edited
- synchronize
- reopened

jobs:
pint:
uses: itinerare/github-actions/.github/workflows/pint.yml@main
with:
php-version: '8.1'
concurrency:
group: ci-${{ github.head_ref || github.ref_name }}

blade-formatter:
uses: itinerare/github-actions/.github/workflows/blade_formatter.yml@main
concurrency:
group: ci-${{ github.head_ref || github.ref_name }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/composer.lock
*.env
/composer.phar
*.cache
45 changes: 45 additions & 0 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Actions\Fortify;

use App\Models\Invitation;
use App\Models\User\User;
use App\Services\InvitationService;
use App\Services\UserService;
use Illuminate\Support\Facades\Hash;
use Laravel\Fortify\Contracts\CreatesNewUsers;

class CreateNewUser implements CreatesNewUsers {
use PasswordValidationRules;

/**
* Validate and create a newly registered user.
*
* @return \App\Models\User
*/
public function create(array $input) {
(new UserService)->validator($input)->validate();

$user = User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
'rank_id' => 2,
'birthday' => $input['dob'],
]);
$user->settings()->create([
'user_id' => $user->id,
]);
$user->profile()->create([
'user_id' => $user->id,
]);

if (isset($input['code'])) {
if (!(new InvitationService)->useInvitation(Invitation::where('code', $input['code'])->whereNull('recipient_id')->first(), $user)) {
throw new \Exception('An error occurred while using the invitation code.');
}
}

return $user;
}
}
16 changes: 16 additions & 0 deletions app/Actions/Fortify/PasswordValidationRules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Actions\Fortify;

use Laravel\Fortify\Rules\Password;

trait PasswordValidationRules {
/**
* Get the validation rules used to validate passwords.
*
* @return array
*/
protected function passwordRules() {
return ['required', 'string', new Password, 'confirmed'];
}
}
26 changes: 26 additions & 0 deletions app/Actions/Fortify/ResetUserPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Actions\Fortify;

use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\ResetsUserPasswords;

class ResetUserPassword implements ResetsUserPasswords {
use PasswordValidationRules;

/**
* Validate and reset the user's forgotten password.
*
* @param mixed $user
*/
public function reset($user, array $input) {
Validator::make($input, [
'password' => $this->passwordRules(),
])->validate();

$user->forceFill([
'password' => Hash::make($input['password']),
])->save();
}
}
31 changes: 31 additions & 0 deletions app/Actions/Fortify/UpdateUserPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Actions\Fortify;

use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;

class UpdateUserPassword implements UpdatesUserPasswords {
use PasswordValidationRules;

/**
* Validate and update the user's password.
*
* @param mixed $user
*/
public function update($user, array $input) {
Validator::make($input, [
'current_password' => ['required', 'string'],
'password' => $this->passwordRules(),
])->after(function ($validator) use ($user, $input) {
if (!isset($input['current_password']) || !Hash::check($input['current_password'], $user->password)) {
$validator->errors()->add('current_password', __('The provided password does not match your current password.'));
}
})->validateWithBag('updatePassword');

$user->forceFill([
'password' => Hash::make($input['password']),
])->save();
}
}
54 changes: 54 additions & 0 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Actions\Fortify;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;

class UpdateUserProfileInformation implements UpdatesUserProfileInformation {
/**
* Validate and update the given user's profile information.
*
* @param mixed $user
*/
public function update($user, array $input) {
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],

'email' => [
'required',
'string',
'email',
'max:255',
Rule::unique('users')->ignore($user->id),
],
])->validateWithBag('updateProfileInformation');

if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
$this->updateVerifiedUser($user, $input);
} else {
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
])->save();
}
}

/**
* Update the given verified user's profile information.
*
* @param mixed $user
*/
protected function updateVerifiedUser($user, array $input) {
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'email_verified_at' => null,
])->save();

$user->sendEmailVerificationNotification();
}
}
105 changes: 105 additions & 0 deletions app/Console/Commands/AddImageHashes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace App\Console\Commands;

use App\Models\Character\CharacterCategory;
use App\Models\Currency\Currency;
use App\Models\Feature\Feature;
use App\Models\Feature\FeatureCategory;
use App\Models\Item\Item;
use App\Models\Item\ItemCategory;
use App\Models\Prompt\Prompt;
use App\Models\Prompt\PromptCategory;
use App\Models\Rarity;
use App\Models\Shop\Shop;
use App\Models\Species\Species;
use App\Models\Species\Subtype;
use App\Services\FeatureService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class AddImageHashes extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'add-image-hashes';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Adds hashes to any existing images that don\'t already have them.';

/**
* Create a new command instance.
*/
public function __construct() {
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
$images = CharacterCategory::where('has_image', 1)->whereNull('hash')->get();
$images = $images->concat(Currency::where('has_image', 1)->whereNull('hash')->orWhere('has_icon', 1)->whereNull('hash')->get());
$images = $images->concat(Feature::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(FeatureCategory::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Item::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(ItemCategory::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Prompt::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(PromptCategory::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Rarity::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Shop::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Species::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Subtype::where('has_image', 1)->whereNull('hash')->get());

if ($images->count()) {
$this->line('Updating images...');
foreach ($images as $image) {
$oldName = $image->id.'-image.png';
$image->hash = randomString(10);
// Any service works, I can't use the abstract one
if (
File::exists(public_path($image->imageDirectory).'/'.$oldName) &&
(new FeatureService)->handleImage(
null,
public_path($image->imageDirectory),
$image->hash.$image->id.'-image.png',
$oldName
)
) {
$image->save();
} else {
$this->info('Didn\'t add hash to '.get_class($image).', this could be expected or an error, id '.$image->id);
}

// Just for currency icons
if ($image instanceof Currency) {
$oldName = $image->id.'-icon.png';
if (
File::exists(public_path($image->imageDirectory).'/'.$oldName) &&
(new FeatureService)->handleImage(
null,
public_path($image->imageDirectory),
$image->hash.$image->id.'-icon.png',
$oldName
)
) {
$image->save();
} else {
$this->info('Didn\'t add hash to currency icon image, this could be expected or an error, id '.$image->id);
}
}
}
$this->info('Updated images.');
} else {
$this->line('No images need updating!');
}
}
}
Loading

0 comments on commit 9a89295

Please sign in to comment.