From 12486ae75e3602d628ddd33ae6c4fdc2fcd368fc Mon Sep 17 00:00:00 2001 From: DariusIII Date: Wed, 20 Jun 2018 12:43:11 +0200 Subject: [PATCH] Add function to delete users that have not verified their accounts for 3 or more days --- Changelog | 1 + app/Http/Controllers/Admin/UserController.php | 1 + app/Http/Controllers/Auth/RegisterController.php | 11 +++++++++-- app/Models/User.php | 12 +++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Changelog b/Changelog index a8c510996..57778a0f3 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-06-20 DariusIII + * Chg: Add function to delete users that have not verified their accounts for 3 or more days * Chg: Update users migration and add patch for existing users table * Chg: Update routes, fix user verification * Chg: Add isVerified middleware to routes diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 56e71b144..513a5abe3 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -60,6 +60,7 @@ class UserController extends BasePageController ); User::updateExpiredRoles(); + User::deleteUnVerified(); foreach ($ordering as $orderType) { $this->smarty->assign('orderby'.$orderType, WWW_TOP.'user-list?ob='.$orderType); diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 7f9bbfd94..ce20020a4 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -10,6 +10,7 @@ use Illuminate\Http\Request; use Blacklight\utility\Utility; use App\Http\Controllers\Controller; use Illuminate\Auth\Events\Registered; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Password; use Illuminate\Foundation\Auth\RegistersUsers; use Jrean\UserVerification\Traits\VerifiesUsers; @@ -173,8 +174,14 @@ class RegisterController extends Controller UserVerification::send($user, 'User verification required'); - return $this->registered($request, $user) - ?: redirect($this->redirectPath()); + if ($user->id > 0 && (new User())->isVerified()) { + Auth::loginUsingId($user->id); + User::updateSiteAccessed($user->id, (int) Settings::settingValue('..storeuserips') === 1 ? $request->getClientIp() : ''); + + return redirect()->intended($this->redirectPath()); + } + + return $this->registered($request, $user) ?: redirect($this->redirectPath()); break; case 'view': { diff --git a/app/Models/User.php b/app/Models/User.php index 8b48af127..fe35b9369 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -12,6 +12,7 @@ use Illuminate\Support\Facades\Mail; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Password; use Illuminate\Foundation\Auth\User as Authenticatable; +use Jrean\UserVerification\Traits\UserVerification; /** * App\Models\User. @@ -111,6 +112,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; + use UserVerification; public const ERR_SIGNUP_BADUNAME = -1; public const ERR_SIGNUP_BADPASS = -2; @@ -1033,7 +1035,7 @@ class User extends Authenticatable } /** - * deletes old rows FROM the user_requests and user_downloads tables. + * Deletes old rows FROM the user_requests and user_downloads tables. * if site->userdownloadpurgedays SET to 0 then all release history is removed but * the download/request rows must remain for at least one day to allow the role based * limits to apply. @@ -1050,4 +1052,12 @@ class User extends Authenticatable UserRequest::query()->where('timestamp', '<', now()->subDays($days))->delete(); UserDownload::query()->where('timestamp', '<', now()->subDays($days))->delete(); } + + /** + * Deletes users that have not verified their accounts for 3 or more days + */ + public static function deleteUnVerified() + { + static::query()->where('verified', '=', 0)->where('created_at', '<', now()->subDays(3))->delete(); + } }