You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
2.1 KiB

/** @odoo-module **/
import publicWidget from "@web/legacy/js/public/public_widget";
import { rpc } from "@web/core/network/rpc";
publicWidget.registry.SignUpFormExtension = publicWidget.Widget.extend({
selector: '.oe_signup_form_mobile, .oe_reset_password_form',
events: {
'click .sent-otp': '_onClick',
'change .check_login': '_onClickCheck',
'click button[type="submit"]': '_onSubmitClick',
},
init() {
this._super(...arguments);
},
_onClick: function (ev) {
/** OTP will be create and collect the to number and redirected
to the twilio function o send the otp, and enable the signup
button to signup the user **/
ev.stopPropagation();
ev.preventDefault();
this.$('.sign-up').removeAttr('disabled');
this.$('.sent-otp').attr('disabled','disabled');
const CountryCode = $(".div_code")[0].value
const Mobile = $(".login_mobile")[0].value
let OTP = '';
var digits = '0123456789';
for (let i = 0; i < 4; i++ ) {
OTP += digits[Math.floor(Math.random() * 10)];
}
window.localStorage.setItem("OTP", OTP)
rpc('/web/send_otp', {
'country_code' : CountryCode,
'mobile': Mobile,
'otp': OTP,
})
},
_onSubmitClick: function (ev) {
/**Signup button will check the sent and receive otp to block the
user creation if it is not same, and also enable the otp button to
send the sms again **/
this.$('.sent-otp').removeAttr('disabled');
let otp_val = $("#sms_otp_verify")[0].value
let OTP = window.localStorage.getItem("OTP")
if (OTP && otp_val && OTP != otp_val){
ev.preventDefault();
alert('OTP is not matching');
}
},
_onClickCheck: function (ev) {
/**This will update the email page if it has the same login**/
let checked = $('.check_login')[0].checked
if (checked) {
$('#login_mail')[0].value = $(".field-login")[0].children[1].value
}
},
});