如何使用 AngularFir 将用户数据存储到我的用户节点?
How can I store User data to my User node using AngularFir?
我已经创建了我的登录名,现在可以允许用户注册了。但是我想将用户数据存储到我的节点。我添加了我认为应该在 addUser 函数中运行的代码。我已经为此工作了很长时间,但找不到解决方案。有人可以指出我做错了什么的正确方向吗?
我写的代码如下。提前致谢。
'use strict';
var theBigWeddingBook = angular.module('theBigWeddingBook');
theBigWeddingBook.controller('RegCtrl', function ($scope, $firebaseAuth, $firebaseObject)
{
var ref = new Firebase("https://the-big-wedding-book.firebaseio.com");
var reg = $firebaseAuth(ref);
$scope.user = {};
$scope.addUser = function() {
var username = $scope.user.email;
var password = $scope.user.password;
var uid = $scope.user.uid;
reg.$createUser({
email: username,
password: password
}).then(function(user) {
console.log('User has been successfully created!');
}).catch(function(error) {
console.log(error);
})
ref.child('user').child(user.uid).set(user).then(function(user) {
console.log('Data Saved Successfully!');
}).catch(function(error) {
console.log(error);
})
};
})
$scope.addUser = function() {
var uid = $scope.user.uid;
reg.$createUser({
email: $scope.user.email,
password: $scope.user.password
}).then(function(user) {
console.log('User has been successfully created!');
}).catch(function(error) {
console.log(error);
})
})
或
$scope.addUser = function() {
var username = $scope.user.email;
var password = $scope.user.password;
var uid = $scope.user.uid;
reg.$createUser({
email: this.username,
password: this.password
}).bind(this)
.then(function(user) {
console.log('User has been successfully created!');
}).catch(function(error) {
console.log(error);
})
我成功了。我基本上改变了它,以便当有人注册时,他们会自动登录,然后在身份验证时将数据保存到用户节点,如下所示。
var theBigWeddingBook = angular.module('theBigWeddingBook');
theBigWeddingBook.controller('RegCtrl', function ($scope, $firebaseAuth, $firebaseObject) {
var ref = new Firebase("https://the-big-wedding-book.firebaseio.com");
var reg = $firebaseAuth(ref);
ref.onAuth(function(authData) {
if (authData) {
console.log("Authenticated with uid:", authData.uid);
} else {
console.log("Client unauthenticated.")
}
});
$scope.user = {};
$scope.addUser = function() {
var username = $scope.user.email;
var password = $scope.user.password;
var uid = $scope.user.uid;
reg.$createUser({
email: username,
password: password
}).then(function(user) {
console.log('User has been successfully created!');
return reg.$authWithPassword({ email: username, password: password });
}).catch(function(error) {
console.log(error);
})
};
ref.onAuth(function(authData) {
ref.child('user').child(authData.uid).set(authData).then(function(auth) {
console.log('Data Saved Successfully!');
}).catch(function(error) {
console.log(error);
})
})
})
我已经创建了我的登录名,现在可以允许用户注册了。但是我想将用户数据存储到我的节点。我添加了我认为应该在 addUser 函数中运行的代码。我已经为此工作了很长时间,但找不到解决方案。有人可以指出我做错了什么的正确方向吗?
我写的代码如下。提前致谢。
'use strict';
var theBigWeddingBook = angular.module('theBigWeddingBook');
theBigWeddingBook.controller('RegCtrl', function ($scope, $firebaseAuth, $firebaseObject)
{
var ref = new Firebase("https://the-big-wedding-book.firebaseio.com");
var reg = $firebaseAuth(ref);
$scope.user = {};
$scope.addUser = function() {
var username = $scope.user.email;
var password = $scope.user.password;
var uid = $scope.user.uid;
reg.$createUser({
email: username,
password: password
}).then(function(user) {
console.log('User has been successfully created!');
}).catch(function(error) {
console.log(error);
})
ref.child('user').child(user.uid).set(user).then(function(user) {
console.log('Data Saved Successfully!');
}).catch(function(error) {
console.log(error);
})
};
})
$scope.addUser = function() {
var uid = $scope.user.uid;
reg.$createUser({
email: $scope.user.email,
password: $scope.user.password
}).then(function(user) {
console.log('User has been successfully created!');
}).catch(function(error) {
console.log(error);
})
})
或
$scope.addUser = function() {
var username = $scope.user.email;
var password = $scope.user.password;
var uid = $scope.user.uid;
reg.$createUser({
email: this.username,
password: this.password
}).bind(this)
.then(function(user) {
console.log('User has been successfully created!');
}).catch(function(error) {
console.log(error);
})
我成功了。我基本上改变了它,以便当有人注册时,他们会自动登录,然后在身份验证时将数据保存到用户节点,如下所示。
var theBigWeddingBook = angular.module('theBigWeddingBook');
theBigWeddingBook.controller('RegCtrl', function ($scope, $firebaseAuth, $firebaseObject) {
var ref = new Firebase("https://the-big-wedding-book.firebaseio.com");
var reg = $firebaseAuth(ref);
ref.onAuth(function(authData) {
if (authData) {
console.log("Authenticated with uid:", authData.uid);
} else {
console.log("Client unauthenticated.")
}
});
$scope.user = {};
$scope.addUser = function() {
var username = $scope.user.email;
var password = $scope.user.password;
var uid = $scope.user.uid;
reg.$createUser({
email: username,
password: password
}).then(function(user) {
console.log('User has been successfully created!');
return reg.$authWithPassword({ email: username, password: password });
}).catch(function(error) {
console.log(error);
})
};
ref.onAuth(function(authData) {
ref.child('user').child(authData.uid).set(authData).then(function(auth) {
console.log('Data Saved Successfully!');
}).catch(function(error) {
console.log(error);
})
})
})