Skip to content

Commit 806b2f9

Browse files
authored
Merge pull request #549 from HiEventsDev/develop
2 parents a799bc5 + 79d04b1 commit 806b2f9

File tree

57 files changed

+5125
-2126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+5125
-2126
lines changed

backend/app/Http/Actions/Accounts/CreateAccountAction.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use HiEvents\Services\Application\Handlers\Auth\DTO\LoginCredentialsDTO;
1818
use HiEvents\Services\Application\Handlers\Auth\LoginHandler;
1919
use HiEvents\Services\Application\Locale\LocaleService;
20+
use Illuminate\Contracts\Encryption\DecryptException;
2021
use Illuminate\Http\JsonResponse;
2122
use Illuminate\Validation\ValidationException;
2223
use Throwable;
@@ -54,6 +55,10 @@ public function __invoke(CreateAccountRequest $request): JsonResponse
5455
throw ValidationException::withMessages([
5556
'email' => $e->getMessage(),
5657
]);
58+
} catch (DecryptException $e) {
59+
throw ValidationException::withMessages([
60+
'invite_token' => __('Invalid invite token'),
61+
]);
5762
} catch (AccountRegistrationDisabledException) {
5863
return $this->errorResponse(
5964
message: __('Account registration is disabled'),

backend/app/Http/Actions/Auth/ResetPasswordAction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace HiEvents\Http\Actions\Auth;
44

5+
use HiEvents\Exceptions\InvalidPasswordResetTokenException;
56
use HiEvents\Exceptions\PasswordInvalidException;
67
use HiEvents\Http\Actions\BaseAction;
78
use HiEvents\Http\Request\Auth\ResetPasswordRequest;
@@ -37,6 +38,8 @@ public function __invoke(ResetPasswordRequest $request): JsonResponse
3738
throw ValidationException::withMessages([
3839
'current_password' => $exception->getMessage(),
3940
]);
41+
} catch (InvalidPasswordResetTokenException $e) {
42+
throw new ResourceNotFoundException($e->getMessage());
4043
}
4144

4245
return $this->jsonResponse(

backend/app/Jobs/Event/SendEventEmailJob.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
use HiEvents\DomainObjects\Generated\OutgoingMessageDomainObjectAbstract;
66
use HiEvents\DomainObjects\Status\OutgoingMessageStatus;
77
use HiEvents\Mail\Event\EventMessage;
8-
use HiEvents\Providers\AppServiceProvider;
98
use HiEvents\Repository\Interfaces\OutgoingMessageRepositoryInterface;
109
use HiEvents\Services\Application\Handlers\Message\DTO\SendMessageDTO;
1110
use Illuminate\Bus\Queueable;
1211
use Illuminate\Contracts\Queue\ShouldQueue;
1312
use Illuminate\Foundation\Bus\Dispatchable;
1413
use Illuminate\Mail\Mailer;
1514
use Illuminate\Queue\InteractsWithQueue;
16-
use Illuminate\Queue\Middleware\RateLimited;
1715
use Illuminate\Queue\SerializesModels;
1816
use Throwable;
1917

@@ -30,13 +28,6 @@ public function __construct(
3028
{
3129
}
3230

33-
public function middleware(): array
34-
{
35-
return [
36-
(new RateLimited(AppServiceProvider::MAIL_RATE_LIMIT_PER_SECOND)),
37-
];
38-
}
39-
4031
/**
4132
* @throws Throwable
4233
*/

backend/app/Models/Account.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
namespace HiEvents\Models;
66

77
use HiEvents\DomainObjects\Enums\Role;
8+
use Illuminate\Database\Eloquent\Factories\HasFactory;
89
use Illuminate\Database\Eloquent\Relations\BelongsTo;
910
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
1011
use Illuminate\Database\Eloquent\SoftDeletes;
1112

1213
class Account extends BaseModel
1314
{
1415
use SoftDeletes;
16+
use HasFactory;
1517

1618
public function users(): BelongsToMany
1719
{

backend/app/Models/User.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
1111
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
1212
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
13+
use Illuminate\Database\Eloquent\Factories\HasFactory;
1314
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
1415
use Illuminate\Database\Eloquent\Relations\HasOne;
1516
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
@@ -27,6 +28,7 @@ class User extends BaseModel implements AuthenticatableContract, AuthorizableCon
2728
use Authorizable;
2829
use CanResetPassword;
2930
use MustVerifyEmail;
31+
use HasFactory;
3032

3133
/** @var array */
3234
protected $guarded = [];

backend/app/Providers/AppServiceProvider.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@
1212
use HiEvents\Services\Infrastructure\CurrencyConversion\CurrencyConversionClientInterface;
1313
use HiEvents\Services\Infrastructure\CurrencyConversion\NoOpCurrencyConversionClient;
1414
use HiEvents\Services\Infrastructure\CurrencyConversion\OpenExchangeRatesCurrencyConversionClient;
15-
use Illuminate\Cache\RateLimiting\Limit;
16-
use Illuminate\Contracts\Queue\ShouldQueue;
1715
use Illuminate\Database\Eloquent\Model;
1816
use Illuminate\Database\Eloquent\Relations\Relation;
1917
use Illuminate\Support\Facades\DB;
2018
use Illuminate\Support\Facades\File;
21-
use Illuminate\Support\Facades\RateLimiter;
2219
use Illuminate\Support\Facades\URL;
2320
use Illuminate\Support\ServiceProvider;
2421
use Stripe\StripeClient;
2522

2623
class AppServiceProvider extends ServiceProvider
2724
{
28-
public const MAIL_RATE_LIMIT_PER_SECOND = 'mail-rate-limit-per-second';
29-
3025
public function register(): void
3126
{
3227
$this->bindDoctrineConnection();
@@ -46,18 +41,6 @@ public function boot(): void
4641
$this->disableLazyLoading();
4742

4843
$this->registerMorphMaps();
49-
50-
$this->registerJobRateLimiters();
51-
}
52-
53-
private function registerJobRateLimiters(): void
54-
{
55-
RateLimiter::for(
56-
name: self::MAIL_RATE_LIMIT_PER_SECOND,
57-
callback: static fn(ShouldQueue $job) => Limit::perMinute(
58-
maxAttempts: config('mail.rate_limit_per_second')
59-
)
60-
);
6144
}
6245

6346
private function bindDoctrineConnection(): void

backend/app/Services/Application/Handlers/Auth/ForgotPasswordHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use HiEvents\Repository\Interfaces\UserRepositoryInterface;
99
use HiEvents\Services\Infrastructure\TokenGenerator\TokenGeneratorService;
1010
use Illuminate\Database\DatabaseManager;
11-
use Illuminate\Mail\Mailer;
11+
use Illuminate\Contracts\Mail\Mailer;
1212
use Psr\Log\LoggerInterface;
1313
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
1414
use Throwable;

backend/app/Services/Application/Handlers/Auth/ResetPasswordHandler.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace HiEvents\Services\Application\Handlers\Auth;
44

55
use HiEvents\DomainObjects\UserDomainObject;
6+
use HiEvents\Exceptions\PasswordInvalidException;
67
use HiEvents\Mail\User\ResetPasswordSuccess;
78
use HiEvents\Repository\Interfaces\PasswordResetTokenRepositoryInterface;
89
use HiEvents\Repository\Interfaces\UserRepositoryInterface;
910
use HiEvents\Services\Application\Handlers\Auth\DTO\ResetPasswordDTO;
1011
use HiEvents\Services\Domain\Auth\ResetPasswordTokenValidateService;
12+
use Illuminate\Contracts\Mail\Mailer;
1113
use Illuminate\Database\DatabaseManager;
1214
use Illuminate\Hashing\HashManager;
13-
use Illuminate\Mail\Mailer;
1415
use Psr\Log\LoggerInterface;
1516
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
1617
use Throwable;
@@ -38,13 +39,22 @@ public function handle(ResetPasswordDTO $resetPasswordData): void
3839
$resetToken = $this->passwordTokenValidateService->validateAndFetchToken($resetPasswordData->token);
3940
$user = $this->validateUser($resetToken->getEmail());
4041

42+
if ($this->checkNewPasswordIsOldPassword($user, $resetPasswordData->password)) {
43+
throw new PasswordInvalidException(__('New password must be different from the old password.'));
44+
}
45+
4146
$this->resetUserPassword($user->getId(), $resetPasswordData->password);
4247
$this->deleteResetToken($resetToken->getEmail());
4348
$this->logResetPasswordSuccess($user);
4449
$this->sendResetPasswordEmail($user);
4550
});
4651
}
4752

53+
private function checkNewPasswordIsOldPassword(UserDomainObject $user, string $newPassword): bool
54+
{
55+
return $this->hashManager->check($newPassword, $user->getPassword());
56+
}
57+
4858
private function validateUser(string $email): UserDomainObject
4959
{
5060
$user = $this->userRepository->findFirstWhere(['email' => $email]);
@@ -72,7 +82,7 @@ private function deleteResetToken(string $email): void
7282
$this->passwordResetTokenRepository->deleteWhere(['email' => $email]);
7383
}
7484

75-
private function logResetPasswordSuccess($user): void
85+
private function logResetPasswordSuccess(UserDomainObject $user): void
7686
{
7787
$this->logger->info('Password reset successfully', [
7888
'user_id' => $user->getId(),

backend/app/Services/Domain/Payment/Stripe/EventHandlers/PaymentIntentSucceededHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private function storeApplicationFeePayment(OrderDomainObject $updatedOrder, Pay
233233
{
234234
$this->orderApplicationFeeService->createOrderApplicationFee(
235235
orderId: $updatedOrder->getId(),
236-
applicationFeeAmountMinorUnit: $paymentIntent->application_fee_amount,
236+
applicationFeeAmountMinorUnit: $paymentIntent->application_fee_amount ?? 0,
237237
orderApplicationFeeStatus: OrderApplicationFeeStatus::PAID,
238238
paymentMethod: PaymentProviders::STRIPE,
239239
currency: $updatedOrder->getCurrency(),
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Database\Factories;
6+
7+
use HiEvents\Helper\IdHelper;
8+
use Illuminate\Database\Eloquent\Factories\Factory;
9+
10+
/**
11+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\HiEvents\Models\Account>
12+
*/
13+
class AccountFactory extends Factory
14+
{
15+
/**
16+
* Define the model's default state.
17+
*
18+
* @return array<string, mixed>
19+
*/
20+
public function definition(): array
21+
{
22+
$currencies = include base_path('data/currencies.php');
23+
24+
return [
25+
'name' => fake()->name(),
26+
'email' => fake()->unique()->safeEmail(),
27+
'timezone' => fake()->timezone(),
28+
'currency_code' => fake()->randomElement(array_values($currencies)),
29+
'short_id' => IdHelper::shortId(IdHelper::ACCOUNT_PREFIX),
30+
'account_configuration_id' => 1, // Default account configuration is first entry
31+
];
32+
}
33+
34+
/**
35+
* Indicate that the model's stripe account id is set.
36+
*/
37+
public function stripeAccount(): self
38+
{
39+
return $this->state(fn(array $attributes) => [
40+
'stripe_account_id' => fake()->stripeConnectAccountId(),
41+
]);
42+
}
43+
44+
/**
45+
* Indicate that the model's stripe account connection setup is complete.
46+
*/
47+
public function stripeConnectSetupComplete(bool $isComplete = true): self
48+
{
49+
return $this->state(fn(array $attributes) => [
50+
'stripe_connect_setup_complete' => $isComplete,
51+
]);
52+
}
53+
54+
/**
55+
* Indicate that the model is verified.
56+
*/
57+
public function verified(): self
58+
{
59+
return $this->state(fn(array $attributes) => [
60+
'account_verified_at' => now(),
61+
]);
62+
}
63+
64+
/**
65+
* Indicate that the model has been manually verified.
66+
*/
67+
public function manuallyVerified(): self
68+
{
69+
return $this->state(fn(array $attributes) => [
70+
'is_manually_verified' => true,
71+
]);
72+
}
73+
}

0 commit comments

Comments
 (0)