当我按下确认按钮时,我会更新数据库中的用户信息。然后我需要做一个SOAP请求,并调用一个发送邮件功能。
router.put('/users/:id', function (req, res) {
var passwordHash = null;
if(req.body.password !== undefined && req.body.password.length > 3){
passwordHash = bcrypt.hashSync(req.body.password, bcryptSalt);
}
db.one('update "TUsers" ' +
'set "username"=$1, "firstname"=$2, "lastname"=$3, "updatedAt"=now(), "pin"=$4, "rayon_id"=$5, "status"=$7' + ((passwordHash)?', "password"=$8 ':'') +
'where id=$6 returning id, username, firstname, lastname, pin, rayon_id, status',
[req.body.username, req.body.firstname, req.body.lastname, req.body.pin, req.body.rayon_id, req.params.id, req.body.status, passwordHash])
.then(function (data) {
console.log(req.body.isConfirm);
if(req.body.isConfirm != false){
putUser(res, req.body.username, req.body.mail, passwordHash, req.body.firstname, req.body.lastname);
sendMail(req.body.username, req.body.password, req.body.system, req.body.mail);
}
res.json(data);
})
.catch(function (error) {
console.log(error);
res.status(400).json({error: error});
});
});

sendMail()
和putUser()
下方。 putUser()
创建对JasperServer API的SOAP请求,并在更新本地数据库上的用户信息时添加新记录。
//SendMail Function
function sendMail(username, password, systemID, emailTo) {
// setup e-mail data with unicode symbols
var mailOptions = {
from: '"Администрация" <admindrts@infocom.kg>', // sender address
to: '"'+emailTo+'"', // list of receivers
subject: 'Регистрация подтверждена.', // Subject line
text: 'Ваша учетная запись подтверждена в системе "'+systemID+'" под логином "'+username+'", пароль для доступа к системе: "'+password+'"' // plaintext body
//html: '<b>Hello world ?</b>' // html body
};
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
}
function putUser(res, username, emailTo, password, firstname, lastname) {
var methodName_j = "putUser";
var fullName = firstname + " " + lastname;
var param_j ={'user':{
'username': username,
'fullName': fullName,
'password': password,
'emailAddress': emailTo,
'externallyDefined': false,
'enabled': true
}};
return soap.createClient(soap_url_j, { wsdl_headers: {Authorization: auth} }, function (err, client) {
if (err) {
console.log(err);
return;
}
client.addHttpHeader('Authorization',auth);
client[methodName_j](param_j, function (err, result) {
console.log(result);
if (err) {
return res.json(err);
}
return res.json(result);
});
});
}
&#13;