Enter Your Name
// error messages showError: false, errorMessage: '', loading: false,
async sendOTP() { this.email = document.getElementById('lyda-email').value; if (!validateEmail(this.email)) { this.setError('Invalid Email Address'); this.loading = false; return false; } this.resetError();
var body = new FormData(); body.append('action', lyda_settings.action.lyda_send_otp); body.append('email', this.email); body.append('security', lyda_settings.security);
await fetch(lyda_settings.ajaxurl, { method: 'POST', body: body, }).then(response => response.json()).then(result => { if (result.success == false) { this.setError(result.data); return false; } console.log(result); this.OTPInputDiv = true; this.emailInputDiv = false;
}).catch(error => { this.setError(error.message); return false; }); this.loading = false; },
async confirmOTP() { this.loading = true; this.resetError(); otp_value = document.getElementById('lyda-otp').value; this.OTPValue = otp_value; console.log('otp ' + otp_value); if (otp_value == '') { this.setError('Please Enter OTP'); this.loading = false; return false; } var body = new FormData(); body.append('action', lyda_settings.action.lyda_confirm_otp); body.append('email', this.email); body.append('otp', otp_value); body.append('security', lyda_settings.security);
await fetch(lyda_settings.ajaxurl, { method: 'POST', body: body, headers: { 'Accept': 'application/json' } }).then(response => response.json()).then(result => { if (result.success == false) { this.setError(result.data); return false; }
this.emailInputDiv = false; this.OTPInputDiv = false;
if (result.data.status == 'OK') { this.first_name = result.data.data.first_name; this.last_name = result.data.data.last_name; this.userById = result.data.data.userById this.userForId = result.data.data.id; this.showNameDisplayDiv = true; this.showNameInputDiv = false; } if (result.data.status == 'NOTFOUND') { this.first_name = ''; this.last_name = ''; this.userById = result.data.data.userById this.userForId = ''; this.showNameInputDiv = true; this.showNameDisplayDiv = false; } }).catch(error => { this.setError(error.message); return false; }); this.loading = false; },
async createNewUser() {
this.resetError();
const body = new FormData(); body.append('email', this.email); body.append('first_name', this.first_name); body.append('last_name', this.last_name); body.append('action', lyda_create_user.action); body.append('security', lyda_settings.security);
await fetch(lyda_settings.ajaxurl, { method: 'POST', body: body }).then(response => response.json()).then(result => { if (result.success == false) { this.setError(result.data.message); return false; } if (result.data.status == 'OK') { this.userById = result.data.data.userById this.userForId = result.data.data.id; this.showNameDisplayDiv = true; this.showNameInputDiv = false; } }).catch(error => { this.setError(error.message); return false; }); this.loading = false; },
async runTask() {
this.resetError();
const body = new FormData(); body.append('action', lyda_run_task.action); body.append('userBy', this.userById); body.append('userFor', this.userForId); body.append('security', lyda_settings.security);
await fetch(lyda_settings.ajaxurl, { method: 'POST', body: body, }).then(response => response.json()).then(result => { if (result.success == false) { this.setError(result.data.message); return false; } this.iframeUrl = result.data; this.iframeShow = true; this.emailInputDiv = false; this.showNameDisplayDiv = false; this.showNameInputDiv = false; }).catch(error => { this.setError(error.message); return false; }); this.loading = false; },
setError(message) { this.showError = true; this.errorMessage = message; },
resetError() { this.showError = false; this.errorMessage = ''; }, })) })