[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 ...
随机推荐
- 【记录】Mysql 5.7 解压版的安装
1.解压 2.打开my_default.ini 将basedir修改为MySQL的解压目录 将datadir修改为MySQL的解压目录\data 3.更改环境变量 系统变量里面添加MYSQL_HOME ...
- iOS 9音频应用播放音频之第一个ios9音频实例
iOS 9音频应用播放音频之第一个ios9音频实例 第一个ios9音频实例 为了让开发者可以对上面的内容有更加深入的了解,本节将实现播放音频的第一个实例.在此实例中会涉及到项目的创建.界面设计.关联以 ...
- 分割视图控制器(UISplitViewController)
这种控制器只能用于iPad,它可以在iPad屏幕中显示两个不同的场景:在横向模式下,左边显示一个表,供用户选择:用户选择表中的元素后,详细视图将显示该元素的详细信息.如果iPad被旋转到纵向模式,表将 ...
- RxSwift 系列(五)
前言 本篇文章将要学习RxSwift中过滤和条件操作符,在RxSwift中包括了: filter distinctUntilChanged elementAt single take takeLast ...
- 【BZOJ 3958】 3958: [WF2011]Mummy Madness (二分+扫描线、线段树)
3958: [WF2011]Mummy Madness Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 96 Solved: 41 Descripti ...
- JAVA中关于大数问题
这里只是java速成,只限于java语法,包括输入输出,运算处理,字符串和高精度的处理,进制之间的转换等,能解决OJ上的一些高精度题目. 一.样例:java中的输出a+b import java.io ...
- BZOJ 4566 JZYZOJ 1547 [haoi2016T5]找相同子串 后缀数组 并查集
http://172.20.6.3/Problem_Show.asp?id=1547 http://www.lydsy.com/JudgeOnline/problem.php?id=4566 单纯后缀 ...
- 【并查集】BZOJ4668-冷战
[题目大意] 给出N个军工厂和M 个操作,操作分为两类: • 0 u v,这次操作苏联会修建一条连接 u 号军工厂及 v 号军工厂的铁路,注意铁路都是双向的; • 1 u v, Reddington ...
- [CC-CHEFGRPH]Time to Study Graphs with Chef
[CC-CHEFGRPH]Time to Study Graphs with Chef 题目大意: 一个有向图可以分成\(n+2(n\le10^{12})\)层,第\(0\)层和第\(n+1\)层有\ ...
- bzoj 1010 斜率优化DP
我的第二道斜率DP. 收获: 1.假设两个位置:p<q<i,然后让某一位置优,看其满足什么性质,所谓斜率优化就是满足: (g[q]-g[p])/(f[q]-f[p]) op h[i] 要 ...