2015年4月21日 星期二

Firebase - Email & Password Authentication

Firebase makes it easy to integrate email and password authentication into your app. Firebase automatically stores your users' credentials securely (using bcrypt) and redundantly (daily off-site backups).
This separates sensitive user credentials from your application data, and lets you focus on the user interface and experience for your app.
Firebase自動秘密地存放用戶的credential和冗餘(每日異地備份)。這樣可以把敏感的用戶credential與應用資料分離開來,讓你專注於應用的用戶介面與體驗

create user account

Firebase exposes a number of JavaScript convenience methods for account creation and management, letting you have full control over the interface for your application. Create new user accounts with the following snippet:

創建用戶帳號

Firebase暴露了一些JavaScript的便捷方法用於帳戶創建和管理,讓你可以完全控制你的應用程序接口。用以下片斷創建新的用戶帳戶:
Creating User Accounts


var ref = new Firebase("https://.firebaseio.com");
ref.createUser({
  email    : "bobtony@firebase.com",
  password : "correcthorsebatterystaple"
}, function(error, userData) {
  if (error) {
    console.log("Error creating user:", error);
  } else {
    console.log("Successfully created user account with uid:", userData.uid);
  }
});

翻譯到這裏告一段落,接下來要實作一下,首先在EZoApp,參考範例寫下程式碼

$(document).on('pageinit', '#home', function () {
    loadJS('https://cdn.firebase.com/js/client/2.2.1/firebase.js', function () {
      var myDataRef = new Firebase('https://scorching-torch-4707.firebaseio.com/');
      
      myDataRef.createUser({
  email    : "bobtony2@firebase.com",
  password : "correcthorsebatterystaple"
}, function(error, userData) {
  if (error) {
    alert('createUser error');
    console.log("Error creating user:", error);
  } else {
    alert('createUser ok');
    console.log("Successfully created user account with uid:", userData.uid);
  }
});

經過實作後,的確在Firebase的Login&Auth裡面創建了帳號及密碼,接下來要實作登入機制







沒有留言:

張貼留言