|
|
|
|
@ -2,22 +2,21 @@
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\EmailVerification;
|
|
|
|
|
use App\Follower;
|
|
|
|
|
use App\FollowRequest;
|
|
|
|
|
use App\Jobs\FollowPipeline\FollowPipeline;
|
|
|
|
|
use App\Mail\ConfirmEmail;
|
|
|
|
|
use App\Notification;
|
|
|
|
|
use App\Profile;
|
|
|
|
|
use App\User;
|
|
|
|
|
use App\UserFilter;
|
|
|
|
|
use Auth;
|
|
|
|
|
use Cache;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use App\Mail\ConfirmEmail;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Mail;
|
|
|
|
|
use Redis;
|
|
|
|
|
use {Auth, Cache, Mail, Redis};
|
|
|
|
|
use PragmaRX\Google2FA\Google2FA;
|
|
|
|
|
use App\Jobs\FollowPipeline\FollowPipeline;
|
|
|
|
|
use App\{
|
|
|
|
|
EmailVerification,
|
|
|
|
|
Follower,
|
|
|
|
|
FollowRequest,
|
|
|
|
|
Notification,
|
|
|
|
|
Profile,
|
|
|
|
|
User,
|
|
|
|
|
UserFilter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class AccountController extends Controller
|
|
|
|
|
{
|
|
|
|
|
@ -42,11 +41,14 @@ class AccountController extends Controller
|
|
|
|
|
'page' => 'nullable|min:1|max:3',
|
|
|
|
|
'a' => 'nullable|alpha_dash',
|
|
|
|
|
]);
|
|
|
|
|
$profile = Auth::user()->profile;
|
|
|
|
|
|
|
|
|
|
$action = $request->input('a');
|
|
|
|
|
$allowed = ['like', 'follow'];
|
|
|
|
|
$timeago = Carbon::now()->subMonths(3);
|
|
|
|
|
|
|
|
|
|
$profile = Auth::user()->profile;
|
|
|
|
|
$following = $profile->following->pluck('id');
|
|
|
|
|
|
|
|
|
|
$notifications = Notification::whereIn('actor_id', $following)
|
|
|
|
|
->whereIn('action', $allowed)
|
|
|
|
|
->where('actor_id', '<>', $profile->id)
|
|
|
|
|
@ -75,7 +77,7 @@ class AccountController extends Controller
|
|
|
|
|
EmailVerification::whereUserId(Auth::id())->delete();
|
|
|
|
|
|
|
|
|
|
$user = User::whereNull('email_verified_at')->find(Auth::id());
|
|
|
|
|
$utoken = str_random(40);
|
|
|
|
|
$utoken = str_random(64);
|
|
|
|
|
$rtoken = str_random(128);
|
|
|
|
|
|
|
|
|
|
$verify = new EmailVerification();
|
|
|
|
|
@ -93,12 +95,11 @@ class AccountController extends Controller
|
|
|
|
|
public function confirmVerifyEmail(Request $request, $userToken, $randomToken)
|
|
|
|
|
{
|
|
|
|
|
$verify = EmailVerification::where('user_token', $userToken)
|
|
|
|
|
->where('created_at', '>', now()->subWeeks(2))
|
|
|
|
|
->where('random_token', $randomToken)
|
|
|
|
|
->firstOrFail();
|
|
|
|
|
|
|
|
|
|
if (Auth::id() === $verify->user_id &&
|
|
|
|
|
$verify->user_token === $userToken &&
|
|
|
|
|
$verify->random_token === $randomToken) {
|
|
|
|
|
if (Auth::id() === $verify->user_id && $verify->user_token === $userToken && $verify->random_token === $randomToken) {
|
|
|
|
|
$user = User::find(Auth::id());
|
|
|
|
|
$user->email_verified_at = Carbon::now();
|
|
|
|
|
$user->save();
|
|
|
|
|
@ -109,32 +110,6 @@ class AccountController extends Controller
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function fetchNotifications(int $id)
|
|
|
|
|
{
|
|
|
|
|
$key = config('cache.prefix').":user.{$id}.notifications";
|
|
|
|
|
$redis = Redis::connection();
|
|
|
|
|
$notifications = $redis->lrange($key, 0, 30);
|
|
|
|
|
if (empty($notifications)) {
|
|
|
|
|
$notifications = Notification::whereProfileId($id)
|
|
|
|
|
->orderBy('id', 'desc')->take(30)->get();
|
|
|
|
|
} else {
|
|
|
|
|
$notifications = $this->hydrateNotifications($notifications);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $notifications;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hydrateNotifications($keys)
|
|
|
|
|
{
|
|
|
|
|
$prefix = 'notification.';
|
|
|
|
|
$notifications = collect([]);
|
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
|
$notifications->push(Cache::get("{$prefix}{$key}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $notifications;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function messages()
|
|
|
|
|
{
|
|
|
|
|
return view('account.messages');
|
|
|
|
|
@ -176,10 +151,6 @@ class AccountController extends Controller
|
|
|
|
|
$filterable['id'] = $profile->id;
|
|
|
|
|
$filterable['type'] = $class;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// code...
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$filter = UserFilter::firstOrCreate([
|
|
|
|
|
@ -279,10 +250,6 @@ class AccountController extends Controller
|
|
|
|
|
Follower::whereProfileId($profile->id)->whereFollowingId($user->id)->delete();
|
|
|
|
|
Notification::whereProfileId($user->id)->whereActorId($profile->id)->delete();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// code...
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$filter = UserFilter::firstOrCreate([
|
|
|
|
|
@ -455,7 +422,6 @@ class AccountController extends Controller
|
|
|
|
|
$codes = json_decode($backupCodes, true);
|
|
|
|
|
foreach ($codes as $c) {
|
|
|
|
|
if(hash_equals($c, $code)) {
|
|
|
|
|
// remove code
|
|
|
|
|
$codes = array_flatten(array_diff($codes, [$code]));
|
|
|
|
|
$user->{'2fa_backup_codes'} = json_encode($codes);
|
|
|
|
|
$user->save();
|
|
|
|
|
@ -472,6 +438,5 @@ class AccountController extends Controller
|
|
|
|
|
|
|
|
|
|
public function accountRestored(Request $request)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|