Файловый менеджер - Редактировать - /home/clickysoft/public_html/travel-guru.clickysoft.net/app/Repositories/UserRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\UserRepositoryInterface; use App\Models\Role; use App\Models\User; use App\Notifications\UserResetPassword; use Carbon\Carbon; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Str; class UserRepository implements UserRepositoryInterface { public function getAllUser() { return User::with('roles')->get(); } public function getUserById($userId): mixed { return User::findOrFail($userId); } public function deleteUser($userId): bool { return User::destroy($userId); } public function createUser(array $userDetails): object { return User::create($userDetails); } public function updateUser($userId, array $updatedDetails): object { return User::whereId($userId)->update($updatedDetails); } public function loginAttempt($req) { $user = $this->checkUserExist($req->email); if (empty($user)) return redirect()->back()->withInput()->with('error_msg', 'Invalid credentials.'); if (!$this->isVerified($user)) return redirect()->back()->withInput()->with('error_msg', 'Please verify your account first.'); if (!$this->isActive($user)) return redirect()->back()->withInput()->with('error_msg', 'Your account is currently inactive, Please contact your admin.'); $rememberMe = !empty($req->remember_me); if (Auth::attempt(['email' => $req->email, 'password' => $req->password], $rememberMe)) { return redirect()->route('dashboard'); } else { return redirect()->back()->withInput()->with('error_msg', 'Invalid credentials.'); } } public function checkUserExist($email) { return User::where('email', $email)->first(); } public function isVerified($user): bool { if (!empty($user->is_verified)) { return true; } return false; } public function isActive($user): bool { if (!empty($user->is_active)) { return true; } return false; } public function checkAttempts($req): bool { if (!RateLimiter::tooManyAttempts($this->throttleKey($req), 2)) { return true; } return false; } public function throttleKey($req) { return $req->ip(); } public function clearAttempts($req): void { RateLimiter::clear($this->throttleKey($req)); } public function submitForgotPasswordReq($req) { $user = $this->checkEmailExist($req->email); if (!empty($user)) { $user->update([ 'verification_code' => Str::random(5) . Carbon::now()->timestamp . Str::random(5) ]); $data = [ 'user' => $user, 'route' => 'admin.reset.password' ]; $user->notify((new UserResetPassword($data))->delay(now()->addSeconds(5))); return redirect()->back()->with('success_msg', 'Please check your email, We have sent you reset password link.'); } else { return redirect()->back()->withInput()->with('error_msg', 'Email does not exist.'); } } public function checkEmailExist($email) { return User::where('email', $email)->first(); } public function resetPasswordReq($token, $req) { $user = $this->checkResetToken($token); if (!empty($user)) { $user->update([ 'verification_code' => null, 'password' => $req->password ]); return redirect()->route('admin.login')->with('success_msg', 'Your password successfully reset.'); } else { abort(404); } } public function checkResetToken($token) { return User::where('verification_code', $token)->first(); } public function logout() { Auth::logout(); return redirect()->route('admin.login'); } public function getChattedUsersDashboard($authUserId) { return User::select('users.*') ->join('user_chats', function($join) { $join->on('users.id', '=', 'user_chats.sender_id') ->orOn('users.id', '=', 'user_chats.receiver_id'); }) ->where(function($query) use ($authUserId) { $query->where('user_chats.sender_id', $authUserId) ->orWhere('user_chats.receiver_id', $authUserId); }) ->where('users.id', '!=', $authUserId) ->groupBy('users.id') ->orderByRaw('MAX(user_chats.created_at) DESC') ->limit(5) ->get(); } public function getReviewsGiven($user, $limit = 4, $paginate = false) { $query = $user->reviewsGiven()->with('agent')->orderByDesc('created_at'); if ($paginate) { return $query->paginate(); } else { return $query->limit($limit)->get(); } } public function getReviewsReceived($agent, $limit = 4, $paginate = false) { $query = $agent->userReviews()->with('user')->orderByDesc('created_at'); if ($paginate) { return $query->paginate(); } else { return $query->limit($limit)->get(); } } public function registerCustomer($request) { $user = User::create([ 'full_name' => $request->full_name, 'email' => $request->email, 'phone_number' => $request->phone, 'password' => $request->password, 'country' => $request->country, 'uuid' => (string) Str::uuid(), ]); $userRole = Role::where('name', 'User')->first(); $user->assignRole([$userRole->id]); $user->sendEmailVerificationNotification(); return $user; } public function registerAgent($request) { $agent = User::create([ 'full_name' => $request->input('full_name'), 'email' => $request->input('email'), 'phone' => $request->input('phone'), 'password' => $request->input('password'), 'summary' => $request->input('summary'), 'uuid' => (string) Str::uuid(), ]); $agentRole = Role::where('name', 'Travel Agent')->first(); $agent->assignRole([$agentRole->id]); return $agent; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка