我想实现这个功能,而使用paga的管理员可以创建用户。 为了实现这一点,我使用.signUp函数,除了使用回调成功之外,在创建用户Parse注销当前用户时,一切正常。
代码如下
// Create a new announcement with specified title and body.
exports.create = function(req, res) {
var user = new Parse.User();
res.locals.path = req.path;
// Explicitly specify which fields to save to prevent bad input data
userData = req.body;
if(userData.email != "undefined"){
user.set("username", userData.email);
}
if(userData.name != "undefined"){
user.set("name", userData.name);
}
if(userData.surname != "undefined"){
user.set("surname", userData.surname);
}
if(userData.password != "undefined"){
user.set("password", userData.password);
}
if(userData.courses){
if(userData.courses != "undefined"){
var courses = new Array();
courses = userData.courses.split(",");
user.set("courses", courses);
}
}
if(userData.date != "undefined"){
user.set("birthday", userData.date);
}
if(userData.email != "undefined"){
user.set("email", userData.email);
}
if(userData.admin != "undefined"){
if(userData.admin == "on"){
user.set("admin", true);
}else{
user.set("admin", false);
}
}
if(userData.contact != "undefined"){
user.set("contact", userData.contact);
}
user.signUp(null, {
success: function(user) {
res.redirect('/users');
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
res.send(500, "Error: " + error.code + " " + error.message);
}
});
};
// Create a new tender with specified title and body.
// Update a post based on specified id, title and body.
exports.update = function(req, res) {
var user = new User();
res.locals.path = req.path;
if(req.params.id){
user.id = req.params.id;
}
userData = req.body;
if(userData.name != "undefined"){
user.set("name", userData.name);
}
if(userData.surname != "undefined"){
user.set("surname", userData.surname);
}
if(userData.password != "undefined"){
user.set("password", userData.password);
}
if(userData.courses != "undefined"){
user.set("courses", userData.courses);
}
if(userData.date != "undefined"){
user.set("birthday", userData.date);
}
if(userData.email != "undefined"){
user.set("email", userData.email);
}
if(userData.email != "undefined"){
user.set("username", userData.email);
}
if(userData.admin != "undefined"){
if(userData.admin == "on"){
user.set("admin", true);
}else{
user.set("admin", false);
}
}
if(userData.contact != "undefined"){
user.set("contact", userData.contact);
}
Parse.Cloud.useMasterKey();
user.save().then(function() {
res.redirect('/users');
},
function(err) {
res.send(500, 'Failed saving user');
});
};

这是Parse的功能吗?有没有办法避免退出当前用户?
答案 0 :(得分:1)
signUP方法将替换您当前的用户并以新用户身份登录。为避免您的管理员用户被注销,您需要将其移至自定义云功能。