Finishing invite send email.
This commit is contained in:
parent
7bc3514fc1
commit
b4beb4d8da
|
@ -47,7 +47,7 @@ exports.reset = async ctx => {
|
|||
const { email } = ctx.request.body
|
||||
const configured = await isEmailConfigured()
|
||||
if (!configured) {
|
||||
throw "Please contact your platform administrator, SMTP is not configured."
|
||||
ctx.throw(400, "Please contact your platform administrator, SMTP is not configured.")
|
||||
}
|
||||
try {
|
||||
const user = await getGlobalUserByEmail(email)
|
||||
|
@ -65,10 +65,8 @@ exports.reset = async ctx => {
|
|||
*/
|
||||
exports.resetUpdate = async ctx => {
|
||||
const { resetCode, password } = ctx.request.body
|
||||
try {
|
||||
const userId = await checkResetPasswordCode(resetCode)
|
||||
if (!userId) {
|
||||
throw "Cannot reset password."
|
||||
}
|
||||
const db = new CouchDB(GLOBAL_DB)
|
||||
const user = await db.get(userId)
|
||||
user.password = await hash(password)
|
||||
|
@ -76,6 +74,9 @@ exports.resetUpdate = async ctx => {
|
|||
ctx.body = {
|
||||
message: "password reset successfully.",
|
||||
}
|
||||
} catch (err) {
|
||||
ctx.throw(400, "Cannot reset password.")
|
||||
}
|
||||
}
|
||||
|
||||
exports.logout = async ctx => {
|
||||
|
|
|
@ -5,8 +5,9 @@ const {
|
|||
StaticDatabases,
|
||||
} = require("@budibase/auth").db
|
||||
const { hash, getGlobalUserByEmail } = require("@budibase/auth").utils
|
||||
const { UserStatus } = require("../../../constants")
|
||||
const { checkResetPasswordCode, checkInviteCode } = require("../../../utilities/redis")
|
||||
const { UserStatus, EmailTemplatePurpose } = require("../../../constants")
|
||||
const { checkInviteCode } = require("../../../utilities/redis")
|
||||
const { sendEmail } = require("../../../utilities/email")
|
||||
|
||||
const FIRST_USER_EMAIL = "test@test.com"
|
||||
const FIRST_USER_PASSWORD = "test"
|
||||
|
@ -124,18 +125,27 @@ exports.find = async ctx => {
|
|||
}
|
||||
|
||||
exports.invite = async ctx => {
|
||||
|
||||
const { email } = ctx.request.body
|
||||
const existing = await getGlobalUserByEmail(FIRST_USER_EMAIL)
|
||||
if (existing) {
|
||||
ctx.throw(400, "Email address already in use.")
|
||||
}
|
||||
await sendEmail(email, EmailTemplatePurpose.INVITATION)
|
||||
ctx.body = {
|
||||
message: "Invitation has been sent."
|
||||
}
|
||||
}
|
||||
|
||||
exports.inviteAccept = async ctx => {
|
||||
const { inviteCode } = ctx.request.body
|
||||
try {
|
||||
const email = await checkInviteCode(inviteCode)
|
||||
if (!email) {
|
||||
throw "Unable to create new user, invitation invalid."
|
||||
}
|
||||
// redirect the request
|
||||
delete ctx.request.body.inviteCode
|
||||
ctx.request.body.email = email
|
||||
// this will flesh out the body response
|
||||
await exports.save(ctx)
|
||||
} catch (err) {
|
||||
ctx.throw(400, "Unable to create new user, invitation invalid.")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ exports.isEmailConfigured = async (groupId = null) => {
|
|||
* @return {Promise<object>} returns details about the attempt to send email, e.g. if it is successful; based on
|
||||
* nodemailer response.
|
||||
*/
|
||||
exports.sendEmail = async (email, purpose, { groupId, user }) => {
|
||||
exports.sendEmail = async (email, purpose, { groupId, user } = {}) => {
|
||||
const db = new CouchDB(GLOBAL_DB)
|
||||
const config = await getSmtpConfiguration(db, groupId)
|
||||
if (!config) {
|
||||
|
|
Loading…
Reference in New Issue