This commit is contained in:
nurmuhammet committed 2023-12-03 14:43:41 +05:00
1 parent 09609ef849
commit 21aab6ca7d
6 files changed
+113 -28

No files matched your search

@@ -102,7 +102,7 @@ public function smsVerification()
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 @@ public function index(): View
*/ */
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")
]);
} }
} }
+10 -1
View File
@@ -8,6 +8,15 @@
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();
+3 -1
View File
@@ -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
View File
@@ -0,0 +1,6 @@
/*!
* sweetalert2 v11.10.1
* Released under the MIT License.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Sweetalert2=e()}(this,(function(){"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,(i=o.key,r=void 0,"symbol"==typeof(r=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(i,"string"))?r:String(r)),o)}var i,r}function o(t,e,o){return e&&n(t.prototype,e),o&&n(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function c(t,e,n){return c=a()?Reflect.construct.bind():function(t,e,n){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return n&&r(i,n.prototype),i},c.apply(null,arguments)}function u(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function s(){return s="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var o=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=i(t)););return t}(t,e);if(o){var r=Object.getOwnPropertyDescriptor(o,e);return r.get?r.get.call(arguments.length<3?t:n):r.value}},s.apply(this,arguments)}function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,i,r,a,c=[],u=!0,s=!1;try{if(r=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;u=!1}else for(;!(u=(o=r.call(n)).done)&&(c.push(o.value),c.length!==e);u=!0);}catch(t){s=!0,i=t}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw i}}return c}}(t,e)||f(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(t){return function(t){if(Array.isArray(t))return p(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||f(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(t,e){if(t){if("string"==typeof t)return p(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(t,e):void 0}}function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function m(t,e){return function(t,e){if(e.get)return e.get.call(t);return e.value}(t,v(t,e,"get"))}function h(t,e,n){return function(t,e,n){if(e.set)e.set.call(t,n);else{if(!e.writable)throw new TypeError("attempted to set read only private field");e.value=n}}(t,v(t,e,"set"),n),n}function v(t,e,n){if(!e.has(t))throw new TypeError("attempted to "+n+" private field on non-instance");return e.get(t)}function g(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}var b={},y=function(t){return new Promise((function(e){if(!t)return e();var n=window.scrollX,o=window.scrollY;b.restoreFocusTimeout=setTimeout((function(){b.previousActiveElement instanceof HTMLElement?(b.previousActiveElement.focus(),b.previousActiveElement=null):document.body&&document.body.focus(),e()}),100),window.scrollTo(n,o)}))},w="swal2-",C=["container","shown","height-auto","iosfix","popup","modal","no-backdrop","no-transition","toast","toast-shown","show","hide","close","title","html-container","actions","confirm","deny","canceLine truncated
"undefined"!=typeof document&&function(e,t){var n=e.createElement("style");if(e.getElementsByTagName("head")[0].appendChild(n),n.styleSheet)n.styleSheet.disabled||(n.styleSheet.cssText=t);else try{n.innerHTML=t}catch(e){n.innerText=t}}(document,".swal2-popup.swal2-toast{box-sizing:border-box;grid-column:1/4 !important;grid-row:1/4 !important;grid-template-columns:min-content auto min-content;padding:1em;overflow-y:hidden;background:#fff;box-shadow:0 0 1px rgba(0,0,0,.075),0 1px 2px rgba(0,0,0,.075),1px 2px 4px rgba(0,0,0,.075),1px 3px 8px rgba(0,0,0,.075),2px 4px 16px rgba(0,0,0,.075);pointer-events:all}.swal2-popup.swal2-toast>*{grid-column:2}.swal2-popup.swal2-toast .swal2-title{margin:.5em 1em;padding:0;font-size:1em;text-align:initial}.swal2-popup.swal2-toast .swal2-loading{justify-content:center}.swal2-popup.swal2-toast .swal2-input{height:2em;margin:.5em;font-size:1em}.swal2-popup.swal2-toast .swal2-validation-message{font-size:1em}.swal2-popup.swal2-toast .swal2-footer{margin:.5em 0 0;padding:.5em 0 0;font-size:.8em}.swal2-popup.swal2-toast .swal2-close{grid-column:3/3;grid-row:1/99;align-self:center;width:.8em;height:.8em;margin:0;font-size:2em}.swal2-popup.swal2-toast .swal2-html-container{margin:.5em 1em;padding:0;overflow:initial;font-size:1em;text-align:initial}.swal2-popup.swal2-toast .swal2-html-container:empty{padding:0}.swal2-popup.swal2-toast .swal2-loader{grid-column:1;grid-row:1/99;align-self:center;width:2em;height:2em;margin:.25em}.swal2-popup.swal2-toast .swal2-icon{grid-column:1;grid-row:1/99;align-self:center;width:2em;min-width:2em;height:2em;margin:0 .5em 0 0}.swal2-popup.swal2-toast .swal2-icon .swal2-icon-content{display:flex;align-items:center;font-size:1.8em;font-weight:bold}.swal2-popup.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-popup.swal2-toast .swal2-actions{justify-content:flex-start;height:auto;margin:0;margin-top:.5em;padding:0 .5em}.swal2-popup.swal2-toast .swal2-styled{margin:.25em .5em;padding:.4em .6em;font-size:1em}.swal2-popup.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line]{position:absolute;width:1.6em;height:3em;transform:rotate(45deg);border-radius:50%}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.8em;left:-0.5em;transform:rotate(-45deg);transform-origin:2em 2em;border-radius:4em 0 0 4em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.25em;left:.9375em;transform-origin:0 1.5em;border-radius:0 4em 4em 0}.swal2-popup.swal2-toast .swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-success .swal2-success-fix{top:0;left:.4375em;width:.4375em;height:2.6875em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{top:1.125em;left:.1875em;width:.75em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{top:.9375em;right:.1875em;width:1.375em}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-toast-animate-success-line-tip .75s}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-toast-animate-success-line-long .75s}.swal2-popup.swal2-toast.swal2-show{animation:swal2-toast-show .5s}.swal2-popup.swal2-toast.swal2-hide{animation:swal2-toast-hide .1s forwards}div:where(.swal2-container){display:grid;position:fixed;z-index:1060;inset:0;box-sizing:border-box;grid-template-areas:\"top-start top top-end\" \"center-start center center-end\" \"bottom-start bottom-center bottom-end\";grid-template-rows:minmax(min-content, auto) minmax(min-content, auto) minmax(min-content, auto);height:100%;padding:.625em;overflow-x:hidden;transition:background-color .1s;-webkit-overflow-scrolling:touch}div:where(.swal2-container).swal2-backdrop-show,div:where(.swal2-container).swal2-noanimation{background:rgba(0,0,0,.4)}div:where(.swal2-container).swal2-backdrop-hide{background:rgba(0,0,0,0) !important}div:where(.swal2-container).swal2-top-start,div:where(.swal2-container).swal2-center-start,div:where(.swal2-container).swal2-bottom-start{grid-template-columns:minmax(0, 1fr) auto auto}div:where(.swal2-container).swal2-top,div:where(.swal2-container).swal2-center,div:where(.swal2-container).swal2-bottom{grid-template-columns:auto minmax(0, 1fr) auto}div:where(.swal2-container).swal2-top-end,div:where(.swal2-container).swal2-center-end,div:where(.swal2-container).swal2-bottom-end{grid-template-columLine truncated
+51 -23
View File
@@ -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 @@ class="bg-white dark:bg-gray-800 shadow rounded-lg p-8 max-w-lg mx-auto"
<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 @@ class="form-control form-input form-input-bordered w-full"
<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 @@ class="form-control form-input form-input-bordered w-full"
</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>