Add function to delete users that have not verified their accounts for 3 or more days

This commit is contained in:
DariusIII
2018-06-20 12:43:11 +02:00
parent 1db9665a05
commit 12486ae75e
4 changed files with 22 additions and 3 deletions
+1
View File
@@ -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
@@ -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);
@@ -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': {
+11 -1
View File
@@ -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();
}
}