0

我是 aws cognito 服务的新手。这是我的代码片段。它不适用于重置密码过程。

请检查以下代码并回复我以更改代码。

        var EmailId = document.getElementById('email').value;
        //var Password = document.getElementById('txtPassword').value
        $.ajax({
            url: EndPointURL + '/userapproval',
            type: 'GET',
            data: JSON.stringify(EmailId),
            contentType: 'application/json; charset=utf-8',
            async: false,
            success: function (response) {
                var data = JSON.parse(response);
                //alert(data);
                var len = data.length;
                //alert('len : ' + len);
                for (var i = 0; i < len; i++) {
                    if (EmailId === data[i].EmailId) {
                        var status = data[i].status;

                        if (status.toLowerCase() !== "rejected") {
                            // When using loose Javascript files:
                            var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;

                            var authenticationData = {
                                Username: EmailId
                                //Password: Password,
                            };
                            var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
                            var poolData = {
                                UserPoolId: poolId, // Your user pool id here
                                ClientId: clientId // Your client id here
                            };
                            var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
                            var userData = {
                                Username: EmailId,
                                Pool: userPool
                            };

此代码用于重置密码不起作用我尝试了代码中的大部分更改但没有响应:-

                            var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);

                            cognitoUser.forgotPassword({                                    
                                onSuccess: function (result) {
                                    // console.log('call result: ' + result);
                                },
                                onFailure: function (err) {
                                    //alert(err);
                                    $("#lbl_alert").html(err);
                                    $("#myAlertModal").modal('show');
                                },
                                //Optional automatic callback
                                inputVerificationCode: function (data) {
                                    //console.log('Code sent to: ' + data);
                                    var verificationCode = prompt('Please input verification code ', '');
                                    if (verificationCode == null) {
                                        return false; //break out of the function early
                                    }
                                    if (verificationCode === '')
                                        return false;
                                    var newPassword = prompt('Enter new password ', '');
                                    if (newPassword == null) {
                                        return false; //break out of the function early
                                    }
                                    cognitoUser.confirmPassword(verificationCode, newPassword, this);                                       
                                    //alert("Password reset successfully.");
                                    $("#lbl_alert").html("Password reset successfully.");
                                    $("#myAlertModal").modal('show');
                                    document.location = 'Login.html';
                                }
                            });
4

0 回答 0