Wip
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Rules\PhoneCodeVerification;
|
|||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class ResetPasswordController extends Controller
|
class ResetPasswordController extends Controller
|
||||||
{
|
{
|
||||||
@@ -27,20 +28,38 @@ class ResetPasswordController extends Controller
|
|||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'username' => ['required', 'string', 'max:250', 'exists:users,username'],
|
'username' => ['required', 'string', 'max:250', 'exists:users,username'],
|
||||||
'verification' => ['nullable', 'integer', 'digits:5'],
|
'verification' => ['nullable', 'integer', 'digits:5', Rule::requiredIf(fn () => $request->filled('step-verification'))],
|
||||||
'password' => ['bail', 'nullable', 'string', 'min:8', 'confirmed'],
|
'step-sms' => ['nullable'],
|
||||||
|
'step-verification' => ['nullable'],
|
||||||
|
'step-password' => ['nullable'],
|
||||||
|
'password' => ['bail', 'nullable', 'string', 'min:8', 'confirmed', Rule::requiredIf(fn () => $request->filled('step-password'))],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->filled('verification')) {
|
|
||||||
return $this->verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = User::where('username', $request->username)->first();
|
$user = User::where('username', $request->username)->first();
|
||||||
|
|
||||||
// sendSMSVerification($user->phone);
|
if ($request->filled('step-sms') && $request->isNotFilled('step-verification') && $request->isNotFilled('step-password')) {
|
||||||
$phone_code = rand(10000, 99999);
|
return $this->sendVerification($request, $user);
|
||||||
$verification = Verification::where(['username' => $user->phone])->first();
|
}
|
||||||
$verification ? $verification->update(['code' => $phone_code]) : Verification::create(['username' => $user->phone, 'code' => $phone_code]);
|
|
||||||
|
if ($request->filled('step-verification') && $request->isNotFilled('step-password')) {
|
||||||
|
return $this->verify($request, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('step-password')) {
|
||||||
|
return $this->updatePassword($request, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send verification code
|
||||||
|
* @param Request $request
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function sendVerification(Request $request, User $user): JsonResponse
|
||||||
|
{
|
||||||
|
sendSMSVerification($user->phone);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'step' => 1,
|
'step' => 1,
|
||||||
@@ -50,10 +69,12 @@ class ResetPasswordController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify phone number
|
* Verify phone number
|
||||||
|
* @param Request $request
|
||||||
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
public function verify(): JsonResponse
|
public function verify(Request $request, User $user): JsonResponse
|
||||||
{
|
{
|
||||||
$verification = Verification::where('username', $request->username)
|
$verification = Verification::where('username', $user->phone)
|
||||||
->where('code', $request->verification)
|
->where('code', $request->verification)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@@ -70,7 +91,22 @@ class ResetPasswordController extends Controller
|
|||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'step' => 2,
|
'step' => 2,
|
||||||
'message' => __("Now you can set your password, but please make sure that you dont forget it")
|
'message' => __("Now you can set your password, but please make sure that you don't forget it!")
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update password
|
||||||
|
* @param Request $request
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function updatePassword(Request $request, User $user): JsonResponse
|
||||||
|
{
|
||||||
|
$user->update(['password' => bcrypt($request->password)]);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'step' => 3,
|
||||||
|
'message' => __('Your password has been updated')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,9 +217,12 @@
|
|||||||
"Username": "Ulanyjy ady",
|
"Username": "Ulanyjy ady",
|
||||||
"Go to login page": "Login sahypa geç",
|
"Go to login page": "Login sahypa geç",
|
||||||
"Submit": "Tassyklamak",
|
"Submit": "Tassyklamak",
|
||||||
|
"Verification": "Tassyklamak",
|
||||||
|
"verification": "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",
|
"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ň!"
|
"Now you can set your password, but please make sure that you don't forget it!": "Indi açar sözüni täzeläp bilersiňiz, ýöne ýatdan çykarmaň!",
|
||||||
|
"Your password has been updated": "Siziň açar sözüňiz üýtgedildi"
|
||||||
}
|
}
|
||||||
|
|||||||
7
migrate.md
Normal file
7
migrate.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Status
|
||||||
|
**pending**
|
||||||
|
**register**
|
||||||
|
**processing**
|
||||||
|
**completed**
|
||||||
|
**cancelled**
|
||||||
|
|
||||||
@@ -43,3 +43,38 @@ function removeValidationClasess() {
|
|||||||
element.innerHTML = ''
|
element.innerHTML = ''
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showVerificationCodeBox() {
|
||||||
|
$_ID('verification-code-box').classList.remove('hidden')
|
||||||
|
$_ID('verification-code-box').insertAdjacentHTML('beforeend', `
|
||||||
|
<input
|
||||||
|
class="form-control form-input form-input-bordered w-full"
|
||||||
|
id="verification"
|
||||||
|
type="text"
|
||||||
|
name="verification"
|
||||||
|
value=""
|
||||||
|
>
|
||||||
|
<input type="hidden" name="step-verification" value="1">
|
||||||
|
|
||||||
|
<span id="verification-error-box" class="text-red-500 text-italic error-box"></span>
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function showPasswordBox() {
|
||||||
|
$_ID('username-box').classList.add('hidden')
|
||||||
|
$_ID('verification-code-box').innerHTML = ''
|
||||||
|
|
||||||
|
$_ID('reset-password-container').classList.remove('hidden')
|
||||||
|
|
||||||
|
$_ID('password-box').insertAdjacentHTML('beforeend', `
|
||||||
|
<input class="form-control form-input form-input-bordered w-full" id="password" type="password" name="password">
|
||||||
|
<input type="hidden" name="step-password" value="1">
|
||||||
|
|
||||||
|
<span id="password-error-box" class="text-red-500 text-italic error-box"></span>
|
||||||
|
`)
|
||||||
|
$_ID('password-confirm-box').insertAdjacentHTML('beforeend', `
|
||||||
|
<input class="form-control form-input form-input-bordered w-full" id="password_confirmation" type="password" name="password_confirmation">
|
||||||
|
|
||||||
|
<span id="password_confirmation-error-box" class="text-red-500 text-italic error-box"></span>
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
class="form-control form-input form-input-bordered w-full"
|
class="form-control form-input form-input-bordered w-full"
|
||||||
autofocus=""
|
autofocus=""
|
||||||
>
|
>
|
||||||
|
<input type="hidden" name="step-sms" value="1">
|
||||||
|
|
||||||
<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>
|
||||||
@@ -48,31 +49,19 @@
|
|||||||
<label class="block mb-2" for="verification">
|
<label class="block mb-2" for="verification">
|
||||||
{{ __('Verification code') }}
|
{{ __('Verification code') }}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input
|
|
||||||
class="form-control form-input form-input-bordered w-full"
|
|
||||||
id="verification"
|
|
||||||
type="text"
|
|
||||||
name="verification"
|
|
||||||
value=""
|
|
||||||
>
|
|
||||||
|
|
||||||
<span id="verification-error-box" class="text-red-500 text-italic error-box"></span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hidden" id="reset-password-container">
|
<div class="hidden" id="reset-password-container">
|
||||||
<div class="mb-6">
|
<div class="mb-6" id="password-box">
|
||||||
<label class="block mb-2" for="password">
|
<label class="block mb-2" for="password">
|
||||||
{{ __('Password') }}
|
{{ __('Password') }}
|
||||||
</label>
|
</label>
|
||||||
<input class="form-control form-input form-input-bordered w-full" id="password" type="password" name="password">
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-6">
|
<div class="mb-6" id="password-confirm-box">
|
||||||
<label class="block mb-2" for="password_confirmation">
|
<label class="block mb-2" for="password_confirmation">
|
||||||
{{ __('Confirm Password') }}
|
{{ __('Confirm Password') }}
|
||||||
</label>
|
</label>
|
||||||
<input class="form-control form-input form-input-bordered w-full" id="password_confirmation" type="password" name="password_confirmation">
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -93,33 +82,39 @@ 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) {
|
||||||
console.log(response.errors);
|
|
||||||
loopObject(response.errors, item => addValidationClasses(item))
|
loopObject(response.errors, item => addValidationClasses(item))
|
||||||
} else {
|
} else {
|
||||||
removeValidationClasess()
|
removeValidationClasess()
|
||||||
|
|
||||||
if (response.step === 1) {
|
if (response.step === 1) {
|
||||||
$_ID('verification-code-box').classList.remove('hidden')
|
showVerificationCodeBox()
|
||||||
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: '{{ __('Verification code') }}',
|
title: '{{ __('Verification code') }}',
|
||||||
text: response.message,
|
text: response.message,
|
||||||
icon: 'info'
|
icon: 'info'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.step === 2) {
|
if (response.step === 2) {
|
||||||
$_ID('username-box').classList.add('hidden')
|
showPasswordBox()
|
||||||
$_ID('verification-code-box').classList.add('hidden')
|
|
||||||
|
|
||||||
$_ID('reset-password-container').classList.remove('hidden')
|
|
||||||
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: '{{ __('Reset password') }}',
|
title: '{{ __('Reset Password') }}',
|
||||||
text: response.message,
|
text: response.message,
|
||||||
icon: 'warning'
|
icon: 'warning'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response.step === 3) {
|
||||||
|
await Swal.fire({
|
||||||
|
title: response.message,
|
||||||
|
showDenyButton: false,
|
||||||
|
showCancelButton: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
window.location.href = '{{ route('login') }}'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user