|
@@ -38,10 +38,19 @@ class AccountController extends Controller
|
|
|
|
|
|
public function sendVerifyEmail(Request $request)
|
|
|
{
|
|
|
- if(EmailVerification::whereUserId(Auth::id())->count() !== 0) {
|
|
|
- return redirect()->back()->with('status', 'A verification email has already been sent! Please check your email.');
|
|
|
+ $timeLimit = Carbon::now()->subDays(1)->toDateTimeString();
|
|
|
+ $recentAttempt = EmailVerification::whereUserId(Auth::id())
|
|
|
+ ->where('created_at', '>', $timeLimit)->count();
|
|
|
+ $exists = EmailVerification::whereUserId(Auth::id())->count();
|
|
|
+
|
|
|
+ if($recentAttempt == 1 && $exists == 1) {
|
|
|
+ return redirect()->back()->with('error', 'A verification email has already been sent recently. Please check your email, or try again later.');
|
|
|
+ } elseif ($recentAttempt == 0 && $exists !== 0) {
|
|
|
+ // Delete old verification and send new one.
|
|
|
+ EmailVerification::whereUserId(Auth::id())->delete();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
$user = User::whereNull('email_verified_at')->find(Auth::id());
|
|
|
$utoken = hash('sha512', $user->id);
|
|
|
$rtoken = str_random(40);
|
|
@@ -60,14 +69,15 @@ class AccountController extends Controller
|
|
|
|
|
|
public function confirmVerifyEmail(Request $request, $userToken, $randomToken)
|
|
|
{
|
|
|
- $verify = EmailVerification::where(DB::raw('BINARY user_token'), $userToken)
|
|
|
- ->where(DB::raw('BINARY random_token'), $randomToken)
|
|
|
+ $verify = EmailVerification::where('user_token', $userToken)
|
|
|
+ ->where('random_token', $randomToken)
|
|
|
->firstOrFail();
|
|
|
+
|
|
|
if(Auth::id() === $verify->user_id) {
|
|
|
$user = User::find(Auth::id());
|
|
|
$user->email_verified_at = Carbon::now();
|
|
|
$user->save();
|
|
|
- return redirect('/timeline');
|
|
|
+ return redirect('/');
|
|
|
}
|
|
|
}
|
|
|
|