Compare commits
5 Commits
feature/do
...
feature/Ex
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a2077a164 | |||
| 363c7005d0 | |||
| fda129875e | |||
| 2d31eccc4a | |||
| ea68943354 |
@@ -2,26 +2,34 @@
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Requests\Auth\LoginRequest;
|
||||
use App\Admin\Requests\Auth\RegisterRequest;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Expert;
|
||||
use App\Traits\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function register(Request $request): JsonResponse
|
||||
public function register(RegisterRequest $request): JsonResponse
|
||||
{
|
||||
// Expert::query()->create();
|
||||
Expert::query()->create([
|
||||
'username' => $request->username,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function login(Request $request): JsonResponse
|
||||
public function login(LoginRequest $request): JsonResponse
|
||||
{
|
||||
$credentials = ['password' => $request->password];
|
||||
|
||||
@@ -35,13 +43,7 @@ class AuthController extends Controller
|
||||
{
|
||||
$request->session()->regenerate();
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
return $this->successResponse([
|
||||
'id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'email' => $user->email,
|
||||
]);
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
return $this->errorResponse(__('messages.incorrect_or_username_password'));
|
||||
@@ -49,7 +51,7 @@ class AuthController extends Controller
|
||||
|
||||
public function logout(Request $request): JsonResponse
|
||||
{
|
||||
Auth::logout();
|
||||
Auth::guard('expert')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Requests\Documentation\RejectRequest;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
@@ -36,16 +37,17 @@ class DocumentationController extends Controller
|
||||
public function confirm(User $user): JsonResponse
|
||||
{
|
||||
$user->update([
|
||||
|
||||
'authority_level' => 1
|
||||
]);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function reject(User $user): JsonResponse
|
||||
public function reject(RejectRequest $request, User $user): JsonResponse
|
||||
{
|
||||
$user->update([
|
||||
|
||||
'kyc_status' => 0,
|
||||
'kyc_reject_reason' => $request->kyc_reject_reason
|
||||
]);
|
||||
|
||||
return $this->successResponse();
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Requests\Profile\ChangePasswordRequest;
|
||||
use App\Admin\Resources\ExpertResource;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
@@ -14,6 +16,22 @@ class ProfileController extends Controller
|
||||
|
||||
public function info(): JsonResponse
|
||||
{
|
||||
return $this->successResponse(new ExpertResource(Auth::user()));
|
||||
return $this->successResponse(new ExpertResource(Auth::guard('expert')->user()));
|
||||
}
|
||||
|
||||
public function changePassword(ChangePasswordRequest $request): JsonResponse
|
||||
{
|
||||
$expert = Auth::guard('expert')->user();
|
||||
|
||||
if (! Hash::check($request->current_password, $expert->password))
|
||||
{
|
||||
return $this->errorResponse(__('messages.incorrect_current_password'));
|
||||
}
|
||||
|
||||
$expert->update([
|
||||
'password' => Hash::make($request->new_password)
|
||||
]);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
}
|
||||
|
||||
30
backend/app/Admin/Requests/Auth/LoginRequest.php
Normal file
30
backend/app/Admin/Requests/Auth/LoginRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Requests\Auth;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'login' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
31
backend/app/Admin/Requests/Auth/RegisterRequest.php
Normal file
31
backend/app/Admin/Requests/Auth/RegisterRequest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Requests\Auth;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RegisterRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'username' => 'required|unique:experts,username',
|
||||
'email' => 'required|email|unique:experts,email',
|
||||
'password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:6|confirmed',
|
||||
];
|
||||
}
|
||||
}
|
||||
29
backend/app/Admin/Requests/Documentation/RejectRequest.php
Normal file
29
backend/app/Admin/Requests/Documentation/RejectRequest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Requests\Documentation;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RejectRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'kyc_reject_reason' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
30
backend/app/Admin/Requests/Profile/ChangePasswordRequest.php
Normal file
30
backend/app/Admin/Requests/Profile/ChangePasswordRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Requests\Profile;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ChangePasswordRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'current_password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:8',
|
||||
'new_password' => 'required|string|regex:/^(?=.*[a-zA-Z])(?=.*\d).+$/|min:8',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,14 @@ class AuthController extends Controller
|
||||
|
||||
public function register(RegisterRequest $request): JsonResponse
|
||||
{
|
||||
User::query()->create([
|
||||
$user = User::query()->create([
|
||||
'username' => $request->username,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
Auth::guard('web')->login($user);
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return $this->successResponse();
|
||||
@@ -43,13 +45,7 @@ class AuthController extends Controller
|
||||
{
|
||||
$request->session()->regenerate();
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
return $this->successResponse([
|
||||
'id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'email' => $user->email,
|
||||
]);
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
return $this->errorResponse(__('messages.incorrect_or_username_password'));
|
||||
@@ -57,7 +53,7 @@ class AuthController extends Controller
|
||||
|
||||
public function logout(Request $request): JsonResponse
|
||||
{
|
||||
Auth::logout();
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('kyc_reject_reason')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('kyc_reject_reason');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,10 +1,20 @@
|
||||
<?php
|
||||
|
||||
use App\Admin\Controllers\AuthController;
|
||||
use App\Admin\Controllers\DocumentationController;
|
||||
|
||||
Route::prefix('auth')
|
||||
->name('auth.')
|
||||
->controller(AuthController::class)
|
||||
->group(function () {
|
||||
Route::post('register', 'register')->name('register');
|
||||
Route::post('login', 'login')->name('login');
|
||||
Route::post('logout', 'logout')->name('logout');
|
||||
});
|
||||
|
||||
Route::prefix('documents')
|
||||
->name('documents.')
|
||||
->middleware('auth')
|
||||
->middleware('auth:expert')
|
||||
->controller(DocumentationController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
|
||||
Reference in New Issue
Block a user