我想将 Back4App 与 angularjs 应用程序一起使用,用于简单的用户登录。
我可以这样做吗?怎么做?
是的,这可以完成并且已经完成。使用 parse.com http://docs.parseplatform.org/js/guide/上的 javascript 文档
还有一个 nodejs 工具。https://www.npmjs.com/package/angular-parse 你熟悉 Angularjs 吗?
加载 angularjs 并在 HTML 中解析
在您的控制器中,从您的登录表单中传递数据:
$scope.submitFormReg = function(newUser){
var user = new Parse.User();
user.set("username", newUser.user);
user.set("password", newUser.pass);
user.set("email", newUser.email);
user.signUp(null, {
success: function(user) {
// Hooray! Let them use the app now.
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
Parse.User.logOut().then(() => {
});
}
});
};
$scope.submitFormLogin = function(newUser){
Parse.User.logIn(newUser.user, newUser.pass, {
success: function(user) {
// Do stuff after successful login.
$location.path('/');
},
error: function(user, error) {
// The login failed. Check error to see why.
alert(newUser + " login failed: " + error);
}
});
};