博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Firebase] 3. Firebase Simple Login Form
阅读量:4677 次
发布时间:2019-06-09

本文共 4890 字,大约阅读时间需要 16 分钟。

Using service. 

Here we use three methods for login, logout, register and getCurrentUser.

Be sure to open the Email and Password configuration on Forge:

 

login.tmpl.html

Login From

 login.js

/** * Created by Answer1215 on 11/10/2014. */var login = angular.module('login', ['firebase']);app.constant('FIREBASE_URI', 'https://zhentiw-angular-fire.firebaseio.com/');login.controller('LoginCtrl',  ['$scope', '$firebaseSimpleLogin', 'FIREBASE_URI', function($scope, $firebaseSimpleLogin, FIREBASE_URI){    $scope.loginService = $firebaseSimpleLogin(new Firebase(FIREBASE_URI));    $scope.newUser = {email: '', password: ''};    $scope.currentUser = null;    $scope.autoLogin = function(){        $scope.loginService.$getCurrentUser()            .then(function(user){                $scope.currentUser = user;            });    };    $scope.autoLogin();    $scope.login = function(email, password){        $scope.loginService.$login('password', {email: email, password: password})            .then(function(user){                $scope.currentUser = user;                $scope.resetForm();            })    };    $scope.register = function(email, password){        $scope.loginService.$createUser(email, password)            .then(function(user){                $scope.currentUser = user;                $scope.resetForm();            });    };    $scope.logout = function(){        $scope.loginService.$logout();        $scope.currentUser = null;    }    $scope.resetForm = function(){        $scope.newUser = {email: '', password: ''};    }}]);

 app.js

/** * Created by Answer1215 on 11/9/2014. */var app = angular.module('app', ['ui.router','firebase', 'oc.lazyLoad']);app.constant('FIREBASE_URI', 'https://zhentiw-angular-fire.firebaseio.com/');app.config(function($stateProvider){    $stateProvider        .state('login', {            url: '/login',            templateUrl: 'public/login.tmpl.html',            controller: 'LoginCtrl',            resolve: {                'login@': function($ocLazyLoad){                    return $ocLazyLoad.load(                        {                            name: "login",  //module name is "store"                            files: ["public/js/login.js",                            'bower_components/firebase-simple-login/firebase-simple-login.js']                        }                    )                }        }});});app.controller('LoginCtrl', function(){});app.controller('MainCtrl', ['$scope', 'ItemsService', function ($scope, ItemsService) {    $scope.newItem = { name: '', description: '', count: 0 };    $scope.currentItem = null;    $scope.isUpdated = false;    $scope.items = ItemsService.getItems();    $scope.items.$on('change', function(){        if(!$scope.isUpdated){
return;} console.log("ITEMS CHANGE"); }); $scope.items.$on('loaded', function(){ console.log("ITEMS LOADED"); }); //Deattach the change event from the items //$scope.items.$off('change'); $scope.addItem = function () { ItemsService.addItem(angular.copy($scope.newItem)); $scope.newItem = { name: '', description: '', count: 0 }; }; $scope.updateItem = function (id){ $scope.isUpdated = true; ItemsService.updateItem(id); }; $scope.removeItem = function (id) { ItemsService.removeItem(id); };}]);app.factory('ItemsService', ['$firebase', 'FIREBASE_URI', function ($firebase, FIREBASE_URI) { var ref = new Firebase(FIREBASE_URI); var items = $firebase(ref); var getItems = function () { return items; }; var addItem = function (item) { items.$add(item); }; var updateItem = function (id) { items.$save(id); }; var removeItem = function (id) { items.$remove(id); }; return { getItems: getItems, addItem: addItem, updateItem: updateItem, removeItem: removeItem }}]);

index.html

    
Angular Firebase
{
{items | json}}
Name Description Count
Remove

Add Item

 

转载于:https://www.cnblogs.com/Answer1215/p/4088619.html

你可能感兴趣的文章
2019 计蒜之道 初赛 第二场 B. 百度AI小课堂-上升子序列(简单) ( 实现)
查看>>
Python(2.7)-随机函数(random)
查看>>
Mybatis学习笔记(一) 之框架原理
查看>>
ABSTRACT的方法是否可同时是STATIC,是否可同时是NATIVE,是否可同时是SYNCHRONIZED?
查看>>
【SPL标准库专题(10)】SPL Exceptions
查看>>
《Python从入门基础到实践》
查看>>
【读入优化】
查看>>
python-网络编程urllib模块
查看>>
0029 Java学习笔记-面向对象-枚举类
查看>>
CGRectGet *** 获取控件坐标的方法
查看>>
SQL的主键和外键约束
查看>>
Bookmarklet
查看>>
c++primer 第l六章编程练习答案
查看>>
上海秋季HCC小记
查看>>
Illustrator 上色
查看>>
truncate表恢复
查看>>
this关键字的使用
查看>>
Console.Read()、Console.ReadLine()、Console.ReadKey()
查看>>
ecere 编译过程中遇到的问题
查看>>
Cyclone V 与 Avalon-MM资料整理——DE1-SOC学习笔记(1)
查看>>