Форма забытого пароля с помощью AWS Cognito - PullRequest
0 голосов
/ 23 января 2019

Я реализую логику забытого пароля с помощью AWS Cognito.Я до сих пор успешно меняю пароль с помощью подсказок, как указано в документации.Вот код

var username = document.getElementById('reset-pass').value;
    var data = {
        UserPoolId: _config.cognito.userPoolId,
        ClientId: _config.cognito.clientId
    };
    var userPool = new AmazonCognitoIdentity.CognitoUserPool(data);

    // setup cognitoUser first
    var cognitoUser = new AmazonCognitoIdentity.CognitoUser({
        Username: username,
        Pool: userPool
    });

cognitoUser.forgotPassword({
        onSuccess: function (result) {
            console.log('call result: ' + result);
        },
        onFailure: function(err) {
            alert(err);
        },
        inputVerificationCode() {
            var verificationCode = prompt('Please input verification code ' ,'');
            var newPassword = prompt('Enter new password ' ,'');
            cognitoUser.confirmPassword(verificationCode, newPassword, this);
        }
    });

Мой вопрос, вместо того, чтобы использовать подсказки, как я могу подтвердить пользователя на следующей странице.Пример
На первой странице пользователь вводит электронное письмо, и почта отправляется с помощью forgotPassword().
Теперь пользователь перенаправлен на новую страницу.Там я хотел ввести код, а также новый пароль и вызвать метод cognitoUser.confirmPassword.

Я попытался создать интервал задержки, и после ввода подробностей это вызвало бы сброс интервала при нажатии кнопки.

   function resetPassword() {
    var username = document.getElementById('reset-pass').value;
    var data = {
        UserPoolId: _config.cognito.userPoolId,
        ClientId: _config.cognito.clientId
    };
    var userPool = new AmazonCognitoIdentity.CognitoUserPool(data);

    // setup cognitoUser first
    var cognitoUser = new AmazonCognitoIdentity.CognitoUser({
        Username: username,
        Pool: userPool
    });
    // call forgotPassword on cognitoUser
    cognitoUser.forgotPassword({
        onSuccess: function (result) {
            alert("Mail Sent")
        },
        onFailure: function (err) {
            console.log(err)
        },
        inputVerificationCode()
        {
            window.myVar = setInterval(function(){
                console.log('check');
            }, 10000);
            var verificationCode = document.getElementById('code').value;
            var newPassword = document.getElementById('fpass').value;
            cognitoUser.confirmPassword(verificationCode, newPassword, this);
        }
    });
}

HTML-часть кода -

<div class="change">
    <form>
        <label>Enter Email ID</label>
        <input type="email" id="reset-pass" required />
        <br />
        <div class=""><a href="#" class="btn btn_red" id="next" onclick="resetPassword()">Next</a></div>
    </form>
</div>

div class="change-confirm">
<form>
    <label>Enter Code</label>
    <input type="number" id="code" required />
    <br />
    <label>Enter New Password</label>
    <input type="password" id="fpass" required />
    <br />
    <div class=""><a href="#" class="btn btn_red" onclick="clearInterval(window.myVar);"> Reset</a></div>
</form>
</div>

Но приведенный выше код никогда не выполнялся.Вместо этого он останавливает выполнение через некоторое время.Итак, мой вопрос, есть ли способ отложить вызов функции cognitoUser.confirmPassword метода?Я не хочу использовать подсказки вместо того, чтобы получать электронную почту и код в текстовом поле после отправки почты.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...