Benutzer-login mit Angularjs und Firebase

Ich versuche einen Weg zu finden, erstellen Sie eine einfache login-Formular mit Angularjs und Firebase. Ich habe derzeit ein einfaches Anmeldeformular, das fügt einen Benutzernamen in mein FB-Datenbank. Alles was ich wissen muss ist wie man eine login-Seite, akzeptiert der Benutzer, sobald der userName identifiziert wird, in dem FB-system, und möglicherweise einen callback-Fehler, wenn keine entsprechenden Benutzernamen innerhalb der Datenbank. Dies ist mein signup form:

<html ng-app="myApp">
<body ng-controller="userCtrl">
    <div class="centerForm">

        <form>
          <div class="form-group">
            <label for="exampleInputUser">Username</label>
            <input type="username" ng-model="userName" class="form-control" id="exampleInputUser" placeholder="username">
          </div>
          <div class="form-group">
            <label for="exampleInputPassword1">Password</label>
            <input type="password" ng-model="userPassword" class="form-control" id="exampleInputPassword1" placeholder="Password">
          </div>
          <table class="nav" align="center">
            <tr>
                <td>
                    <p><button type="submit" class="btn btn-primary" ng-click="saveUser()">Submit</button>
                    <a href="#" class="btn btn-info" role="button">Sign Up</a></p>
                </td>
            </tr>       
          </table>
        </form>

    </div>  
</body>
</html>

und dies ist mein Zeichen code:

 <script>
             angular.module('myApp', [])
             .controller('userCtrl', function($scope) {
                $scope.userName ="";
                $scope.userPassword="";

                $scope.myData = new Firebase( "https://myfirebaseapp.firebaseio.com/")

                $scope.saveUser = function() {
                    $scope.myData.push({userName: $scope.userName});
                };

                });





    </script> 

Meine login-Formular würde dann ungefähr so Aussehen:

<html ng-app="myApp">
<body ng-controller="userCtrl">
    <div class="centerForm">

        <form>
          <div class="form-group">
            <label for="exampleInputUser1">Username</label>
            <input type="username" ng-model="userName" class="form-control" id="exampleInputUser1" placeholder="username">
          </div>
          <div class="form-group">
            <label for="exampleInputPassword1">Password</label>
            <input type="password" ng-model="userPassword" class="form-control" id="exampleInputPassword1" placeholder="Password">
          </div>
          <table class="nav" align="center">
            <tr>
                <td>
                    <p><button type="submit" class="btn btn-primary" ng-click="loginUser()">Submit</button>
                    <a href="#" class="btn btn-info" role="button">Sign Up</a></p>
                </td>
            </tr>       
          </table>
        </form>

    </div>  
</body>
</html>
  • Ihr code ist nur indem der Benutzername in der Feuerstellung, es ist nicht wirklich ein Konto erstellen, so dass Sie beheben sollten, bevor Sie tatsächlich anmelden.
InformationsquelleAutor Alex Hughes | 2016-03-04
Schreibe einen Kommentar