gpt4 book ai didi

javascript - 在 parse.com js SDK 中使用 .signUp 注销当前用户

转载 作者:行者123 更新时间:2023-12-03 08:39:52 25 4
gpt4 key购买 nike

我想实现使用 paga 的管理员可以创建用户的功能。为了实现这一点,我使用 .signUp 函数,除了在创建用户时解析注销当前用户而不是使用回调成功之外,一切正常。

代码如下

// 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 的一个功能吗?有没有办法避免当前用户注销?

最佳答案

signUP 方法将替换您当前的用户并以新用户身份登录。为了避免您的管理员用户被注销,您需要将其移至自定义云功能。

关于javascript - 在 parse.com js SDK 中使用 .signUp 注销当前用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33079386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com