wip
This commit is contained in:
@@ -102,7 +102,7 @@ class RegisterController extends Controller
|
|||||||
public function verifySmsCode(Request $request)
|
public function verifySmsCode(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'code' => ['required', 'integer', new PhoneCodeVerification()],
|
'code' => ['required', 'integer', new PhoneCodeVerification(auth()->user()->phone)],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
auth()->user()->update([
|
auth()->user()->update([
|
||||||
|
|||||||
@@ -3,8 +3,11 @@
|
|||||||
namespace App\Http\Controllers\Auth;
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\System\Verification;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Rules\PhoneCodeVerification;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class ResetPasswordController extends Controller
|
class ResetPasswordController extends Controller
|
||||||
@@ -22,12 +25,49 @@ class ResetPasswordController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate(['username' => ['required', 'string', 'max:250', 'exists:users,username']]);
|
$request->validate([
|
||||||
|
'username' => ['required', 'string', 'max:250', 'exists:users,username'],
|
||||||
|
'verification' => ['nullable', 'integer', 'digits:5'],
|
||||||
|
'password' => ['nullable', 'string', 'min:8', 'confirmed'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($request->filled('verification')) {
|
||||||
|
return $this->verify();
|
||||||
|
}
|
||||||
|
|
||||||
$user = User::where('username', $request->username)->first();
|
$user = User::where('username', $request->username)->first();
|
||||||
|
|
||||||
// sendSMSVerification($user->phone);
|
// sendSMSVerification($user->phone);
|
||||||
|
|
||||||
return response()->json(['message' => __('We send you a code')]);
|
return response()->json([
|
||||||
|
'step' => 1,
|
||||||
|
'message' => __('We send you a verification code to ') . '****' .substr($user->phone, 4)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify phone number
|
||||||
|
*/
|
||||||
|
public function verify(): JsonResponse
|
||||||
|
{
|
||||||
|
$verification = Verification::where('username', $request->username)
|
||||||
|
->where('code', $request->verification)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $verification) {
|
||||||
|
return response()->json([
|
||||||
|
'errors' => [
|
||||||
|
'verification' => [
|
||||||
|
__('Incorrect verification code'),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'message' => __('Incorrect verification code')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'step' => 2,
|
||||||
|
'message' => __("Now you can set your password, but please make sure that you dont forget it")
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ use Illuminate\Contracts\Validation\ValidationRule;
|
|||||||
|
|
||||||
class PhoneCodeVerification implements ValidationRule
|
class PhoneCodeVerification implements ValidationRule
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param int|string $phone
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
protected int|string $phone,
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the validation rule.
|
* Run the validation rule.
|
||||||
*
|
*
|
||||||
@@ -15,7 +24,7 @@ class PhoneCodeVerification implements ValidationRule
|
|||||||
*/
|
*/
|
||||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||||
{
|
{
|
||||||
$verification = Verification::where('username', auth()->user()->phone)
|
$verification = Verification::where('username', $this->phone)
|
||||||
->where('code', $value)
|
->where('code', $value)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
|||||||
@@ -219,5 +219,7 @@
|
|||||||
"Submit": "Tassyklamak",
|
"Submit": "Tassyklamak",
|
||||||
"Verification code": "Tassyklaýyş belgi",
|
"Verification code": "Tassyklaýyş belgi",
|
||||||
"Please, verify your phone": "Telefon beligiňizi tassyklamagyňyzy haýyş edýäris.",
|
"Please, verify your phone": "Telefon beligiňizi tassyklamagyňyzy haýyş edýäris.",
|
||||||
"Enter your username to continue": "Dowam etmek üçin ulanyjy adyny giriziň"
|
"Enter your username to continue": "Dowam etmek üçin ulanyjy adyny giriziň",
|
||||||
|
"Incorrect verification code": "Nädogry belgi",
|
||||||
|
"Now you can set your password, but please make sure that you dont forget it!": "Indi açar sözüni täzeläp bilersiňiz, ýöne ýatdan çykarmaň!"
|
||||||
}
|
}
|
||||||
|
|||||||
6
public/assets/js/sweetalert2@11.js
Normal file
6
public/assets/js/sweetalert2@11.js
Normal file
File diff suppressed because one or more lines are too long
@@ -10,14 +10,6 @@
|
|||||||
|
|
||||||
<!-- Styles -->
|
<!-- Styles -->
|
||||||
<link rel="stylesheet" href="/vendor/nova/app.css?id=496e3383c5e2918c7bc875f45870e701">
|
<link rel="stylesheet" href="/vendor/nova/app.css?id=496e3383c5e2918c7bc875f45870e701">
|
||||||
<style>
|
|
||||||
.bg-secondary-500 {
|
|
||||||
background-color: rgb(186,230,253);
|
|
||||||
}
|
|
||||||
.hover:bg-secondary-400 {
|
|
||||||
background-color: rgba(24, 182, 155, 0.5);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body class="min-w-site text-sm font-medium min-h-full text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-900">
|
<body class="min-w-site text-sm font-medium min-h-full text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-900">
|
||||||
<div class="py-6 px-1 md:px-2 lg:px-6">
|
<div class="py-6 px-1 md:px-2 lg:px-6">
|
||||||
@@ -36,7 +28,8 @@
|
|||||||
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
|
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
|
||||||
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
|
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
|
||||||
</svg>
|
</svg>
|
||||||
<div class="mb-6">
|
|
||||||
|
<div id="username-box" class="mb-6">
|
||||||
<label class="block mb-2" for="username">
|
<label class="block mb-2" for="username">
|
||||||
{{ __('Username') }}
|
{{ __('Username') }}
|
||||||
</label>
|
</label>
|
||||||
@@ -51,14 +44,31 @@
|
|||||||
<span id="username-error-box" class="text-red-500 text-italic error-box"></span>
|
<span id="username-error-box" class="text-red-500 text-italic error-box"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-6" id="verification-code-box"></div>
|
<div class="mb-6 hidden" id="verification-code-box">
|
||||||
|
<label class="block mb-2" for="verification">
|
||||||
{{-- <div class="mb-6">
|
{{ __('Verification code') }}
|
||||||
<label class="block mb-2" for="password">
|
|
||||||
{{ __('Password') }}
|
|
||||||
</label>
|
</label>
|
||||||
<input class="form-control form-input form-input-bordered w-full" id="password" type="password" name="password" required="">
|
|
||||||
</div> --}}
|
<input class="form-control form-input form-input-bordered w-full" id="verification" type="text" name="verification">
|
||||||
|
|
||||||
|
<span id="verification-error-box" class="text-red-500 text-italic error-box"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="hidden" id="reset-password-container">
|
||||||
|
<div class="mb-6">
|
||||||
|
<label class="block mb-2" for="password">
|
||||||
|
{{ __('Password') }}
|
||||||
|
</label>
|
||||||
|
<input class="form-control form-input form-input-bordered w-full" id="password" type="password" name="password">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-6">
|
||||||
|
<label class="block mb-2" for="password_confirmation">
|
||||||
|
{{ __('Confirm Password') }}
|
||||||
|
</label>
|
||||||
|
<input class="form-control form-input form-input-bordered w-full" id="password_confirmation" type="password" name="password_confirmation">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center" type="submit">
|
<button class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center" type="submit">
|
||||||
<span class=""><span>{{ __('Submit') }}</span></span>
|
<span class=""><span>{{ __('Submit') }}</span></span>
|
||||||
@@ -70,21 +80,39 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="/assets/js/sweetalert2@11.js"></script>
|
||||||
<script src="/assets/js/fn.js"></script>
|
<script src="/assets/js/fn.js"></script>
|
||||||
<script>
|
<script>
|
||||||
async function resetPassword(event) {
|
async function resetPassword(event) {
|
||||||
const response = await postData(event.target.action, getFormData(event))
|
const response = await postData(event.target.action, getFormData(event))
|
||||||
|
|
||||||
if (response.errors) {
|
if (response.errors) {
|
||||||
loopObject(response.errors, item => addValidationClasses(item));
|
loopObject(response.errors, item => addValidationClasses(item))
|
||||||
} else {
|
} else {
|
||||||
removeValidationClasess()
|
removeValidationClasess()
|
||||||
$_ID('verification-code-box').innerHTML = `
|
|
||||||
<label class="block mb-2" for="password">
|
if (response.step === 1) {
|
||||||
{{ __('Verification code') }}
|
$_ID('verification-code-box').classList.remove('hidden')
|
||||||
</label>
|
|
||||||
<input class="form-control form-input form-input-bordered w-full" id="password" type="password" name="password" required="">
|
Swal.fire({
|
||||||
`;
|
title: '{{ __('Verification code') }}',
|
||||||
|
text: response.message,
|
||||||
|
icon: 'info'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.step === 2) {
|
||||||
|
$_ID('username-box').classList.add('hidden')
|
||||||
|
$_ID('verification-code-box').classList.add('hidden')
|
||||||
|
|
||||||
|
$_ID('reset-password-container').classList.remove('hidden')
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: '{{ __('Reset password') }}',
|
||||||
|
text: response.message,
|
||||||
|
icon: 'warning'
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user