[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 ...
随机推荐
- 洛谷P3402 【模板】可持久化并查集 [主席树,并查集]
题目传送门 可持久化并查集 n个集合 m个操作 操作: 1 a b 合并a,b所在集合 2 k 回到第k次操作之后的状态(查询算作操作) 3 a b 询问a,b是否属于同一集合,是则输出1否则输出0 ...
- Linux中磁盘还有空间,但创建文件时提示空间不足
首先需要知道创建文件时,需要满足两个条件:1.磁盘上还有空间:2.inode号还有剩余. 这两个条件可以分别使用"df -h"以及"df -i"查看使用情况 [ ...
- 为什么我喜欢Java
我现在的老板使用一个在线测试系统来筛选在线申请职位的求职者.测试的第一个问题很浅显,仅仅是为了让求职者熟悉一下这个系统的提交和测试代码的流程.问题是这样的,写一个将标准输入拷贝到标准输出的流程.求职者 ...
- centos7 更改时区
Linux 系统(我特指发行版, 没说内核) 下大部分软件的风格就是不会仔细去考虑向后 的兼容性, 比如你上个版本能用这种程序配置, 没准到了下一个版本, 该程序已经不见了. 比如 sysvinit ...
- android 同一个service启动之后 能不能被绑定bind
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 可以 startService 启动了一个服务,这个服务可以再调用 bindServic ...
- 20162304 实验一《Java开发环境的熟悉》实验报告
Linux基础与Java开发环境 实验内容 1.熟悉Linux基础操作: 2.使用JDK编译.运行简单的Java程序: 实验要求 1.学习<Linux基础入门(新版)> 2.完成实验.撰写 ...
- luoguoj 1598 垂直柱状图 模拟
P1598 垂直柱状图 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.luogu.org/problem/show?pid=1598 ...
- mySql---logback日志写入数据库(mysql)配置
如题 建议将日志级别设置为ERROR.这样可以避免存储过多的数据到数据中. 1 logback 配置文件(如下) <?xml version="1.0" encoding ...
- 简单破解 Sencha Architect 2.2 (ExtJs Designer)
Sencha Architect 2是ExtJS和Sencha Touch的官方可视化IDE工具.最新版本是2.2,说是破解,其实是修改License来实现无限试用而已. 1.先下载安装官方软件,大约 ...
- Java解读内存,优化编程
1.别用new Boolean 在很多场景中Boolean类型是必须的,比如JDBC中boolean类型的set与get都是通过Boolean封装传递的,大部分ORM也是用Boolean来封装bool ...