【问题标题】:Firebase password and email authentification fails with errorFirebase 密码和电子邮件身份验证失败并出现错误
【发布时间】:2017-01-30 18:19:13
【问题描述】:

我正在使用最新版本/SDK 开发应用程序

  1. Visual Studio
  2. 科尔多瓦
  3. 离子
  4. AngularJS
  5. Firebase
  6. Genymotion

我尝试通过 Firebase(电子邮件和密码)在我的应用中验证用户。 我已经在网上搜索了解决方案,但我根本无法正常工作。

好吧,只要我点击注册按钮(右上角),我就会收到这条错误消息

这是 register.html(包含一个表单)

<ion-modal-view>
<div class="bar bar-header firstStart">
    <div class="button button-clear button-positive" ng-click="closeModal()">
       Schließen
    </div>
    <h1 class="title modalTitle">Registrieren </h1>
    <div class="button button-clear button-positive"
         ng-click="signupEmail()"> Speichern </div>
</div>

<ion-content class="has-header" padding="true">
    <div class="list list-inset">
        <label class="item item-input item-floating-label">
            <i class="icon ion-ios-email placeholder-icon"></i>
            <span class="input-label">E-Mail</span>
            <input type="email" ng-model="data.email" placeholder="E-Mail" id="email">
        </label>
        <label class="item item-input item-floating-label">
            <i class="icon ion-ios-locked placeholder-icon"></i>
            <span class="input-label">Passwort</span>
            <input type="password" ng-model="data.password"
                   placeholder="Passwort" id="password">
        </label>
    </div>
</ion-content>

app.js

    .controller('modalController', ['$scope', '$ionicModal','$firebase', 
     function ($scope, $ionicModal,$firebase)
     {
        $ionicModal.fromTemplateUrl('templates/register.html', {
        scope: $scope,
        animation: 'slide-in-up',
        backdropClickToClose: false,
        hardwareBackButtonClose: false,
        focusFirstInput: true
    }).then(function (modal) {
        $scope.modal = modal;
    });

    $scope.signupEmail = function () {
        $scope.data = {};
        var email = $scope.data.email;
        alert(email);
        var password = $scope.data.password;
        alert(password);
        /*if (email.length < 4) {
            alert('Please enter an email address.');
            return;
        }
        if (password.length < 4) {
            alert('Please enter a password.');
            return;
        }*/

        firebase.auth().createUserWithEmailAndPassword(email, password).catch(
        function (error)
        {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message;
            // [START_EXCLUDE]
            if (errorCode == 'auth/weak-password') {
                alert('The password is too weak.');
            } else {
                alert(errorMessage);
            }
            if (errorCode == 'auth/argument-error') {
                alert('Error with arg');
            } else {
                alert(errorMessage);
            }
            console.log(error);
            // [END_EXCLUDE]
        });
        // [END createwithemail]
    };

    $scope.login = function () {
        firebase.auth().onAuthStateChanged(function (user) {
            if (user) {
                // User is signed in.
                alert("User already signed in");
            } else {
                // No user is signed in.
                firebase.auth().signInWithEmailAndPassword(email, password).catch(
              function (error)
              {
                 // Handle Errors here.
                 var errorCode = error.code;
                 var errorMessage = error.message;
                 alert("error during login:" + errorMessage + "Code: " + errorCode);
               })
            }
        });
    };

    $scope.openModal = function () {
        $scope.modal.show();
    };

    $scope.closeModal = function () {
        $scope.modal.hide();
    };
    // Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function () {
        $scope.modal.remove();
    });
    // Execute action on hide modal
    $scope.$on('modal.hidden', function () {
        // Execute action
    });
    // Execute action on remove modal
    $scope.$on('modal.removed', function () {
        // Execute action
    });
}]);

请注意 app.js 包含两个控制器,因为如果用户点击右上角的按钮,一个模式会打开另一个模式

这个函数导致错误

这个函数放在app.js里,只是想给大家突出一下。

$scope.signupEmail = function () {
    $scope.data = {};
    var email = $scope.data.email;
    alert(email);
    var password = $scope.data.password;
    alert(password);

    firebase.auth().createUserWithEmailAndPassword(email, password).catch(
        function (error) 
        {
           // Handle Errors here.
           var errorCode = error.code;
           var errorMessage = error.message;
           // [START_EXCLUDE]
           if (errorCode == 'auth/weak-password') {
             alert('The password is too weak.');
           } else {
            alert(errorMessage);
           }
           if (errorCode == 'auth/argument-error') {
            alert('Error with arg');
           } else {
            alert(errorMessage);
           }
           console.log(error);
           // [END_EXCLUDE]
       });
       // [END createwithemail]
     };

注意: 如您所见,我正在打印密码并通过电子邮件发送用户输入的密码以查看其值,但我得到的唯一结果是

我做错了什么? 非常感谢您的回答。

谢谢!

【问题讨论】:

    标签: javascript angularjs cordova ionic-framework firebase-authentication


    【解决方案1】:
    $scope.data = {};
    
    var email = $scope.data.email;
    alert(email);
    
    var password = $scope.data.password;
    alert(password);    
    

    电子邮件始终未定义。

    【讨论】:

    • 我认为,因为我将 'register.html' 中的输入字段的值与 '' 到我的控制器中的变量 'var email = $scope.data.email' ,我将获得用户输入内容的值...我该如何实现呢?如果用户正在填写表格,我想收集信息并使用它。以为我会用数据绑定(ng-data)来做到这一点
    • 就像他建议的那样link
    猜你喜欢
    • 2016-11-13
    • 2019-08-05
    • 2019-03-15
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    • 2016-10-13
    • 2018-11-11
    • 2013-07-11
    相关资源
    最近更新 更多