ryanmitchell
Okay,
I know, The default customer login mechanism is email & password. and here i am going to add one more feature OTP login without removing the default login.
I have created 2 form at login page one for mobile number input another one for OTP input.
and once the user entered mobile number and submit the form an OTP will genereted and it will sent to provided number.
using onCreateOtp() method at /extension/igniter/user/components/Account.php
public function onCreateOtp()
{
try {
$namedRules = [
['mobile', 'lang:igniter.user::default.settings.label_mobile', 'required|between:10,13']
];
$this->validate(post(), $namedRules);
$OTP = rand(100000, 999999);
$MOBILE = post('mobile');
$client = new OtpClient();
$response = $client->send($MOBILE, $OTP); //Sending OTP With my sms channel.
if($response->status == 'error')
throw new ApplicationException("Something went wrong, try again!");
Cache::put(['OTP' => $OTP], now()->addMinute(5));
flash->success("An OTP Sent to your Mobile number: {$MOBILE}");
return Redirect::back();
} catch (ValidationException $ex) {
throw new ExceptionApplicationException(implode(PHP_EOL, $ex->getErrors()->all()));
}
}
and below method i have to verify OTP and login to user.
public function onSubmitOtp()
{
try {
$namedRules = [
['OTP', 'lang:igniter.user::default.settings.label_otp', 'required|numeric|digits:6']
];
$this->validate(post(), $namedRules);
$cacheOTP = Cache::get('OTP');
$postOTP = post('OTP');
if ($postOTP == $cacheOTP) {
//Here i have to make login and redirect customer respective page same as default login.
Event::fire('igniter.user.login', [$this], TRUE);
if ($redirect = input('redirect'))
return Redirect::to($this->controller->pageUrl($redirect));
if ($redirectUrl = $this->controller->pageUrl($this->property('redirectPage')))
return Redirect::intended($redirectUrl);
} else {
flash()->error("OTP Missmatch or Expired! Please retry again.");
return Redirect::back();
}
} catch (ValidationException $ex) {
throw new ApplicationException(implode(PHP_EOL, $ex->getErrors()->all()));
}
}
in my case i just need to verify customer telephone field and start user session if the user not registered, redirect them to account page to fill some mandate information for checkout.