Skip to content

Commit

Permalink
Implemented requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Feb 7, 2024
1 parent 13d90a1 commit 5cdcf0f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
8 changes: 7 additions & 1 deletion app/Http/Controllers/Settings/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\Tier;
use App\Services\SubscriptionService;
use App\Services\SubscriptionUpgradeService;
use App\Services\Users\EmailValidationService;
use App\User;
use Exception;
use Illuminate\Http\Request;
Expand All @@ -22,14 +23,17 @@ class SubscriptionController extends Controller

protected SubscriptionUpgradeService $subscriptionUpgrade;

protected EmailValidationService $emailValidation;

/**
* SubscriptionController constructor.
*/
public function __construct(SubscriptionService $service, SubscriptionUpgradeService $subscriptionUpgradeService)
public function __construct(SubscriptionService $service, SubscriptionUpgradeService $subscriptionUpgradeService, EmailValidationService $validationService)
{
$this->middleware(['auth', 'identity', 'subscriptions']);
$this->subscription = $service;
$this->subscriptionUpgrade = $subscriptionUpgradeService;
$this->emailValidation = $validationService;
}

public function index()
Expand Down Expand Up @@ -93,6 +97,8 @@ public function change(Request $request, Tier $tier)
}
$upgrade = $this->subscriptionUpgrade->user($user)->tier($tier)->upgradePrice($period);
$currency = $user->currencySymbol();

$this->emailValidation->user($user)->requiresEmail();

return view('settings.subscription.change', compact(
'tier',
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Relations/UserRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\Models\UserValidation;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
* Trait UserRelations
Expand Down Expand Up @@ -201,7 +202,7 @@ public function upvotes(): HasMany
return $this->hasMany(FeatureVote::class);
}

public function userValidation(): HasMany
public function userValidation(): HasOne
{
return $this->hasOne(UserValidation::class, 'user_id', 'id');
}
Expand Down
9 changes: 1 addition & 8 deletions app/Models/Scopes/UserScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

namespace App\Models\Scopes;

use Illuminate\Database\Eloquent\Builder;

/**
* Trait UserScope
* @package App\Models\Scopes
*/
trait UserScope
{
/**
*/
public function scopeValid(Builder $query, bool $valid = true): Builder
{
return $query->where(['is_valid' => $valid]);
}

}
12 changes: 12 additions & 0 deletions app/Models/UserValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\Builder;

/**
* @property int $user_id
* @property bool $is_valid
* @property User $user
*/
class UserValidation extends Model
{
Expand All @@ -20,6 +22,9 @@ class UserValidation extends Model
'token'
];

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
Expand All @@ -33,4 +38,11 @@ public function prunable()
{
return static::where('is_valid', false)->where('created_at', '<=', now()->subDays(1));
}

/**
*/
public function scopeValid(Builder $query, bool $valid = true): Builder
{
return $query->where(['is_valid' => $valid]);
}
}
4 changes: 2 additions & 2 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,15 @@ public function hasUnread(): bool
public function isFrauding(): bool
{
// Fraud detection can be turned on or off
if (!config('subscription.fraud_detection')) {
if (config('subscription.fraud_detection')) {
return false;
}
// Someone with a provider (twitter, fb) login is always considered safe
if (!empty($this->provider)) {
return false;
}

$validation = $this->userValidation->valid()->first();
$validation = $this->userValidation()->valid()->first();
if ($validation) {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions lang/en/emails/subscriptions/validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'title' => 'Kanka account email validation.',
];
5 changes: 0 additions & 5 deletions resources/views/settings/subscription/change.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

<x-grid type="1/1">
@if (!$user->isFrauding())
@inject('emailService', 'App\Services\Users\EmailValidationService')
@php
/** @var \App\Services\Users\EmailValidationService $emailService */
$emailService->user($user)->requiresEmail();
@endphp
<x-alert type="warning">
{{ __('emails/validation.modal') }}
</x-alert></div><?php return; ?>
Expand Down

0 comments on commit 5cdcf0f

Please sign in to comment.