added SMS gateway for forgot password

This commit is contained in:
mrNikto9 2024-07-03 11:58:14 +05:00
parent 5cd564afc2
commit 8d8ebf5917
21 changed files with 1623 additions and 1232 deletions

0
bash_scripts/meilisearch_add_sortableAttributes.sh Executable file → Normal file
View File

0
bash_scripts/meilisearch_get_index_settings.sh Executable file → Normal file
View File

0
bootstrap/cache/.gitignore vendored Executable file → Normal file
View File

2706
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -188,6 +188,9 @@ return [
],
],
'sms_gateway' => env('SMS_GATEWAY'),
'check_sms_gateway' => env('CHECK_SMS_GATEWAY'),
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers

View File

@ -157,14 +157,10 @@ class Registration extends Controller
public function update(CustomerProfileRequest $customerProfileRequest)
{
// dd("hi");
$isPasswordChanged = false;
// dd($customerProfileRequest);
$data = $customerProfileRequest->validated();
// dd($data);
if (isset($data['date_of_birth']) && $data['date_of_birth'] == '') {
unset($data['date_of_birth']);
}
@ -245,6 +241,7 @@ class Registration extends Controller
}
public function resetPassword(Request $request){
$request->validate([
'phone' => 'required|digits:8'
]);
@ -253,17 +250,20 @@ class Registration extends Controller
->where('phone', $request->phone)
->first()){
$token = rand(1000,9999);
$res = Event::dispatch('shop.register.verify', $request);
$customer->token = $token;
$customer->save();
$res = $res[0];
$request->merge(['token'=>$token]);
Event::dispatch('shop.register.verify', $request);
if (!$res->successful()) {
return response()->json([
'success' => false,
'status' => $res->status(),
'error' => $res->body()
], $res->status());
}
return response()->json(['success' => true]);
}else{
return response([
'message' => trans('shop::app.customer.login-text.no_account'),
@ -285,9 +285,20 @@ class Registration extends Controller
if($customer = $this->customerRepository
->where('phone', $request->phone)
->where('token', $request->token)
->first()){
$res = Event::dispatch('shop.register.checkVerify', $request);
$res = $res[0];
if ($res->status() !== 200) {
return response()->json([
'success' => false,
'status' => $res->status(),
'error' => $res->body()
], $res->status());
}
$customer->password = bcrypt($request->password);
$customer->save();

View File

@ -6,21 +6,24 @@ use Illuminate\Support\Facades\Log;
class Customer
{
public function __construct(){
// $this->sms_gateway = env('SMS_GATEWAY_ADDRESS','http://sms.digital-tps.tk/api/verify/web');
$this->sms_gateway = 'https://tmex.gov.tm/api/version';
$this->sms_gateway = config('app.sms_gateway');
$this->check_sms_gateway = config('app.check_sms_gateway');
}
public function sendVeificationCode($data){
// Http::withHeaders(['Accept' => 'application/json'])
// ->post($this->sms_gateway, $data->only(['phone','token']));
$response = Http::withHeaders(['Accept' => 'application/json'])
->get($this->sms_gateway, ['to' => '993'.$data->phone,'content'=> $data->token]);
->post($this->sms_gateway, [
'phone_number' => '+993'.$data->phone
]);
return $response;
}
//PARENT_APP=https://tmex.gov.tm/tm/girmek
//[2022-12-14 17:06:30] production.INFO: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`exchange25042022_2`.`exports`, CONSTRAINT `exports_group_id_foreign` FOREIGN KEY (`group_id`) REFERENCES `g
//roups` (`id`) ON DELETE CASCADE) (SQL: insert into `exports` (`locale`, `category_id`, `group_id`, `type`, `currency`, `title`, `unit`, `amount`, `price`, `payment`, `send`, `point`, `country`, `seller`, `place`, `updated_at`, `created_at`) values (tm, 3, q, extern
//al, USD, "Cadillac STS" awtomobili (bronirlenen), 2010ý. nowa belgisi 1G6DU6EA4A0119765 (ýuzt.511169) (Türkmenistanyň Prezidentiniň Diwany, Iş Dolandyryş Müdirligi), sany, 1, 72500, öňünden tölemek, EXW, Aşgabat ş., Germaniýa, 2, =I58, 2022-12-14 17:06:30, 2022-12-14
// 17:06:30))
public function checkVeificationCode($data){
$response = Http::withHeaders(['Accept' => 'application/json'])
->post($this->check_sms_gateway, [
'phone_number' => '+993'.$data->phone,
'otp' => $data->token
]);
return $response;
}
}

View File

@ -14,5 +14,6 @@ class EventServiceProvider extends ServiceProvider
*/
public function boot(){
Event::listen('shop.register.verify', 'TPS\Shop\Listeners\Customer@sendVeificationCode');
Event::listen('shop.register.checkVerify', 'TPS\Shop\Listeners\Customer@checkVeificationCode');
}
}

View File

@ -35,17 +35,16 @@
<span>{{ __('shop::app.customer.reset-password.token') }}</span>
<div class="dif-input">
<input type="text" name="token" v-model="code" v-validate="'required|numeric|min:4'">
<span class="control-error" v-if="errors.has('token')">@{{ errors.first('token') }}</span>
<span class="control-error" v-if="errors.has('reset.token')">@{{ errors.first('reset.token') }}</span>
</div>
</div>
<div class="sign-up-input">
<span>{{ __('shop::app.customer.reset-password.password') }}</span>
<div class="dif-input">
<input type="password" v-model="password" autocomplete="off" name="password" v-validate="'required|min:6'" ref="password">
<span class="control-error" v-if="errors.has('password')">@{{ errors.first('password') }}</span>
<span class="control-error" v-if="errors.has('reset.password')">@{{ errors.first('reset.password') }}</span>
</div>
</div>
<button type="submit" class="log-in topped">{{ __('shop::app.customer.reset-password.submit-btn-title') }}</button>
<div class="sign-up-footer">
<span>{{ __('shop::app.customer.reset-password.no-message') }}</span>
@ -117,33 +116,41 @@
let self = this;
self.message = null;
self.error_message = null;
self.disable_button = true;
// Validate the form fields
this.$validator.validateAll(scope).then(result => {
if (result) {
axios.post('{{ route('customer.register.reset_password') }}', {phone: self.phone,token:self.code,password: self.password})
// Validation successful, send the request
axios.post('{{ route('customer.register.reset_password') }}', {
phone: self.phone,
token: self.code,
password: self.password
})
.then(function(response) {
// console.log(response.data);
window.flashMessages = [{'type': 'alert-success', 'message': response.data.message}];
self.$root.addFlashMessages();
// window.location.href = response.data.redirect;
setTimeout(function() {
let loginForm = document.querySelector('.login-form');
let resetForm = document.querySelector('.reset-password');
loginForm.style.display = 'block';
resetForm.style.display = 'none';
self.reset_password = false
self.reset_password = false;
}, 1500);
self.disable_button = false;
})
.catch(function(error) {
console.error('Error received:', error.response.data);
self.error_message = error.response.data.message;
// self.$setErrorsFromResponse(error.response.data);
self.disable_button = false;
if (error.response.data.errors) {
let errorFields = Object.keys(error.response.data.errors);
errorFields.map(field => {
let errorString = error.response.data.errors[field].join(', ');
@ -153,14 +160,24 @@
scope: scope
});
});
}
});
} else {
// Validation failed
self.disable_button = false;
eventBus.$emit('onFormError')
}
// Display validation errors
let validationErrors = this.$validator.errors.items.filter(e => e.scope === scope);
self.error_message = validationErrors.map(e => e.msg).join(', ');
eventBus.$emit('onFormError');
}
}).catch(err => {
console.error('Validation error:', err);
});
}
}
});
</script>

0
storage/app/.gitignore vendored Executable file → Normal file
View File

0
storage/app/private/.gitignore vendored Executable file → Normal file
View File

0
storage/app/public/.gitignore vendored Executable file → Normal file
View File

0
storage/debugbar/.gitignore vendored Executable file → Normal file
View File

0
storage/fonts/.gitignore vendored Executable file → Normal file
View File

0
storage/framework/.gitignore vendored Executable file → Normal file
View File

0
storage/framework/cache/.gitignore vendored Executable file → Normal file
View File

0
storage/framework/cache/data/.gitignore vendored Executable file → Normal file
View File

0
storage/framework/sessions/.gitignore vendored Executable file → Normal file
View File

0
storage/framework/testing/.gitignore vendored Executable file → Normal file
View File

0
storage/framework/views/.gitignore vendored Executable file → Normal file
View File

0
storage/logs/.gitignore vendored Executable file → Normal file
View File