some cleanups to mailer and user deletion

This commit is contained in:
mntmn 2020-04-09 15:22:06 +02:00
parent d6f93051ef
commit 92cf6c4397
2 changed files with 29 additions and 54 deletions

View File

@ -61,33 +61,6 @@ module.exports = {
} }
}); });
} else if (config.get('mail_provider') === 'aws') {
/*
AWS.config.update({region: 'eu-west-1'});
var ses = new AWS.SES();
ses.sendEmail( {
Source: from,
Destination: { ToAddresses: [to_email] },
ReplyToAddresses: reply_to,
Message: {
Subject: {
Data: subject
},
Body: {
Text: {
Data: plaintext,
},
Html: {
Data: htmlText
}
}
}
}, function(err, data) {
if (err) console.error("Error sending email:", err);
else console.log("Email sent.");
});
*/
} }
} }
}; };

View File

@ -89,28 +89,31 @@ router.post('/', function(req, res) {
res.sendStatus(400); res.sendStatus(400);
}) })
.then(u => { .then(u => {
var homeSpace = { var homeFolder = {
_id: uuidv4(), _id: uuidv4(),
name: req.i18n.__("home"), name: req.i18n.__("home"),
space_type: "folder", space_type: "folder",
creator_id: u._id creator_id: u._id
}; };
db.Space.create(homeSpace) db.Space.create(homeFolder)
.error(err => { .error(err => {
res.sendStatus(400); res.sendStatus(400);
}) })
.then(homeSpace => { .then(homeFolder => {
u.home_folder_id = homeSpace._id; u.home_folder_id = homeFolder._id;
u.save() u.save()
.then(() => { .then(() => {
res.status(201).json({}); // home folder created,
// auto accept pending invites
mailer.sendMail(u.email, req.i18n.__("confirm_subject"), req.i18n.__("confirm_body"), { db.Membership.update({
action: { "state": "active"
link: config.endpoint + "/confirm/" + u.confirmation_token, }, {
name: req.i18n.__("confirm_action") where: {
"email_invited": u.email,
"state": pending
} }
}); });
res.status(201).json({});
}) })
.error(err => { .error(err => {
res.status(400).json(err); res.status(400).json(err);
@ -174,36 +177,35 @@ router.post('/:id/password', function(req, res, next) {
}); });
}); });
} else { } else {
res.status(403).json({"error": "old password wrong"}); res.status(403).json({"error": "Please enter the correct current password."});
} }
} else { } else {
res.status(403).json({"error": "wrong user"}); res.status(403).json({"error": "Access denied."});
} }
} else { } else {
res.status(400).json({"error": "password_to_short"}); res.status(400).json({"error": "Please choose a new password with at least 6 characters."});
} }
}); });
router.delete('/:id', (req, res, next) => { router.delete('/:id', (req, res, next) => {
const user = req.user; const user = req.user;
if(user._id == req.params.id) { if (user._id == req.params.id) {
if (user.account_type == 'email') {
if (bcrypt.compareSync(req.query.password, user.password_hash)) { if (bcrypt.compareSync(req.query.password, user.password_hash)) {
user.remove((err) => {
// TODO: this doesn't currently work.
// all objects (indirectly) belonging to the user have
// to be walked and deleted first.
user.destroy().then(err => {
if(err)res.status(400).json(err); if(err)res.status(400).json(err);
else res.sendStatus(204); else res.sendStatus(204);
}); });
} else { } else {
res.bad_request("password_incorrect"); res.bad_request("Please enter the correct current password.");
} }
} else { } else {
user.remove((err) => { res.status(403).json({error: "Access denied."});
if (err) res.status(400).json(err);
else res.sendStatus(204);
});
} }
}
else res.status(403).json({error: ""});
}); });
router.put('/:user_id/confirm', (req, res) => { router.put('/:user_id/confirm', (req, res) => {