问题描述
我写了一个脚本来调用api,然后输入电子邮件,它将otp发送到我的电子邮件,然后它将验证otp并登录。但我在电子邮件中收到了otp,但问题是我无法输入otp,因为它没有修改otp字段。谁能在这方面帮助我,以便我可以输入电子邮件,然后输入otp并登录。而且还会引发错误
undefined is not an object (evaluating 'otpResponse.jwt_token')
class LoginController extends DocumentController {
setupDocument(document) {
super.setupDocument(document);
console.log("login controller file print invoked");
registerEventListeners();
let otpRequest;
let otp;
let loginMode = 0; // mode 0 - call send_otp api; mode 1 - call verify_otp api
const otpBaseURL = "-------------------------------------------------";
let email;
function addParamsToAPIEndpointAndFire() {
const configParams = encryption_config();
let urlParams = [
`txnid=${configParams['txnid']}`,`email=${email}`,`api_user_id=${configParams['api_user_id']}`,`securehash=${configParams['securehash']}`
].join("&");
if(loginMode == 1) {
urlParams = urlParams + `&otp=${otp}`;
}
const otpURL = otpBaseURL + urlParams;
console.log(otpURL);
otpRequest = new XMLHttpRequest();
otpRequest.open("GET",otpURL);
otpRequest.responseType = "json";
otpRequest.onload = showOTPResponse;
otpRequest.onerror = showOTPError;
otpRequest.send();
}
function showOTPError() {
const title = "An error has occurred";
const alertDocument = createalertDocument(title,"");
console.log(navigationDocument.documents);
console.log("send otp error");
navigationDocument.clear();
navigationDocument.pushDocument(alertDocument);
}
function showOTPResponse() {
const otpResponse = otpRequest.response;
console.log("otpResponse",otpResponse);
if(loginMode == 0) {
loginMode = 1;
const textFieldElem = document.getElementsByTagName('textField').item(0);
var keyboard = textFieldElem.getFeature('Keyboard');
keyboard.text = "";
// modify text contents - change email text field to otp text field
} else {
if(otpResponse.jwt_token) {
// auth success - redirect user
console.log("auth success!");
} else {
// invalid otp
console.log("invalid otp.. try again");
}
}
}
function registerEventListeners() {
console.log("my register event listeners method invoked");
const myButton = document.getElementById('myButton');
myButton.addEventListener("select",getUserInputAndMakeAPICall);
}
function getUserInputAndMakeAPICall() {
// getting email from the text field
console.log("make api call invoked");
const textFieldElem = document.getElementsByTagName('textField').item(0);
var keyboard = textFieldElem.getFeature('Keyboard');
if(loginMode == 0) {
email = keyboard.text;
console.log("user email id is: ");
console.log(email);
// make api call
addParamsToAPIEndpointAndFire();
} else {
otp = keyboard.text;
console.log("user entered otp is: ");
console.log(otp);
addParamsToAPIEndpointAndFire();
}
}
}
}
registerattributeName('loginDocumentURL',LoginController);
模板
<?xml version="1.0" encoding="UTF-8" ?>
<!--
See LICENSE folder for this sample’s licensing information.
-->
<document>
<head>
<style>
.longDescriptionLayout {
max-width: 1280;
}
</style>
</head>
<formTemplate>
<banner>
<title>Enter Email ID to login to Flixjini</title>
<description class="longDescriptionLayout">Login to Flixjini for Personalized Experience!
A One-Time Password will be sent to your Email ID for authentication</description>
</banner>
<textField>username@example.com</textField>
<footer>
<button id = "myButton">
<text>Send OTP</text>
</button>
</footer>
</formTemplate>
</document>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)