[Firebase] 3. Firebase Simple Login Form
Using $firebaseSimpleLogin 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
<div class="container" ng-controller="LoginCtrl">
<h2>Login From</h2>
<form class="form-signin">
<h3 class="for-signin-heading" ng-if="currentUser">{{currentUser.email}}</h3>
<input ng-model="newUser.email" type="email" class="form-control" placeholder="Email address"/>
<input type="password" placeholder="Password" ng-model="newUser.password" class="form-control" />
<button class="btn btn-lg btn-primary btn-block" ng-click="login(newUser.email, newUser.password)">Login</button>
<button class="btn btn-lg btn-success btn-block" ng-click="register(newUser.email, newUser.password)">Register</button>
<button class="btn btn-lg btn-danger btn-block" ng-click="logout()">Logout</button>
</form>
</div>
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
<!DOCTYPE html>
<html ng-app="app">
<head lang="en">
<meta charset="UTF-8">
<title>Angular Firebase</title>
<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="bower_components/angular-material/angular-material.min.css" rel="stylesheet" />
</head>
<body ng-controller="MainCtrl">
<ui-view>
<div class="alert-info well">{{items | json}}</div>
<button class="btn-info" ui-sref="login()">Login</button> <table class="table edit">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Count</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(id, item) in items">
<td><input type="text" ng-model="item.name" ng-blur="updateItem(id)"/></td>
<td><input type="text" ng-model="item.description" ng-blur="updateItem(id)"/></td>
<td><input type="text" ng-model="item.count" ng-blur="updateItem(id)"/></td>
<td>
<a href="#" ng-click="removeItem(id)" class="navbar-link">Remove</a>
</td>
</tr>
</tbody>
</table> <div class="well">
<h4>Add Item</h4> <form class="form-inline" role="form" novalidate ng-submit="addItem()">
<div class="form-group">
<input type="text" class="form-control" ng-model="newItem.name" placeholder="Name">
</div>
<div class="form-group">
<input type="text" class="form-control" ng-model="newItem.description" placeholder="Description">
</div>
<div class="form-group">
<input type="text" class="form-control" ng-model="newItem.count" placeholder="Count">
</div>
<button type="submit" class="btn btn-default">Add</button>
</form>
</div> </ui-view> <script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-material/angular-material.js"></script>
<script src="bower_components/firebase/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/0.6.0/angularfire.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="bower_components/oclazyload/dist/ocLazyLoad.min.js"></script>
<script src="public/js/app.js"></script>
</body>
</html>
[Firebase] 3. Firebase Simple Login Form的更多相关文章
- WordPress Simple Login Registration插件’username‘参数跨站脚本漏洞
漏洞名称: WordPress Simple Login Registration插件’username‘参数跨站脚本漏洞 CNNVD编号: CNNVD-201308-519 发布时间: 2013-0 ...
- pwnable.kr simple login writeup
这道题是pwnable.kr Rookiss部分的simple login,需要我们去覆盖程序的ebp,eip,esp去改变程序的执行流程 主要逻辑是输入一个字符串,base64解码后看是否与题目 ...
- how can I make the login form transparent?
This is how you can make the Login Form transparent: 1. Add this css to Server Module-> Custom cs ...
- Vue Login Form Component
Vue Login Form Component Account Login <template> <div> <slot></slot> <el ...
- pwnable.kr之simple Login
pwnable.kr之simple Login 懒了几天,一边看malloc.c的源码,一边看华庭的PDF.今天佛系做题,到pwnable.kr上打开了simple Login这道题,但是这道题个人觉 ...
- [Firebase] 4. Firebase Object related Database
The idea: This post we are going to learn how to build a Firebase Forage with object related databas ...
- Firebase Chat (firebase 实现web聊天室)
基于firebase + cloud Function 实现web聊天(demo版) 知识点: 使用Firebase SDK创建Google Cloud功能. 触发云功能基于Auth,云存储和Clou ...
- [Firebase] 2. Firebase Event Handling
/** * Created by Answer1215 on 11/9/2014. */ var app = angular.module('app', ['firebase']); app.cons ...
- [Flutter + Firebase] Enable Firebase for Flutter
Anroid Firebase Project setup: 1. In firebase console, cerate a Android app setup you can find in co ...
随机推荐
- 洛谷P1558 色板游戏 [线段树]
题目传送门 色板游戏 题目背景 阿宝上学了,今天老师拿来了一块很长的涂色板. 题目描述 色板长度为L,L是一个正整数,所以我们可以均匀地将它划分成L块1厘米长的小方格.并从左到右标记为1, 2, .. ...
- Java多线程编程——生产者-消费者模式(1)
生产者-消费者模式在生活中非常常见.就拿我们去餐馆吃饭为例.我们会遇到以下两种情况: 1.厨师-客人 如下图所示,生产者.消费者直接进行交互. 生产者生产出产品后,通知消费者:消费者消费后,通知生产者 ...
- Dfs【P2052】 [NOI2011]道路修建
Description 在 W 星球上有 n 个国家.为了各自国家的经济发展,他们决定在各个国家 之间建设双向道路使得国家之间连通.但是每个国家的国王都很吝啬,他们只愿 意修建恰好 n – 1条双向道 ...
- redis和mySql的数据同步的解析
1.同步MySQL数据到Redis (1) 在redis数据库设置缓存时间,当该条数据缓存时间过期之后自动释放,去数据库进行重新查询,但这样的话,我们放在缓存中的数据对数据的一致性要求不是很高才能放入 ...
- 八皇后--python代码
迭代和递归方法的运用 import random def prettyprint(solution): #图形化处理数据 def line(pos,length=len(solution)): #单行 ...
- RabbitMQ (十六) 消息队列的应用场景 (转)
原贴 : http://blog.csdn.net/cws1214/article/details/52922267 消息队列中间件是分布式系统中重要的组件,主要解决应用耦合,异步消息,流量削锋等问题 ...
- [UOJ50]链式反应
这个题意说人话就是:一棵带标号的有根树,编号满足堆性质,根节点有$x$个儿子是叶子($x\in A$),另外的$2$个儿子也是这样的一棵树,求不同的树的个数 设$f_n$为答案,枚举那两棵子树的大小$ ...
- 区间DP POJ 1141 Brackets Sequence
Brackets Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29520 Accepted: 840 ...
- BZOJ 3571 画框 KM算法 最小乘积最大权匹配
题意 有n个画框和n幅画.若第i幅画和第j个画框配对,则有平凡度Aij和违和度Bij,一种配对方案的总体不和谐度为∑Aij*∑Bij.求通过搭配能得到的最小不和谐度是多少. n <= 70. 分 ...
- MS SQL语句优化
MS SQL Server查询优化方法查询速度慢的原因很多,常见如下几种 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计 ...