Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/server/src/IdentityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ export class IdentityManager {
return await this.stripeManager.getCustomerWithDefaultSource(customerId)
}

public async updateStripeCustomerEmail(customerId: string, email: string) {
if (!this.stripeManager) throw new Error('Stripe manager is not initialized')
await this.stripeManager.updateCustomerEmail(customerId, email)
}

public async getAdditionalSeatsProration(subscriptionId: string, newQuantity: number) {
if (!subscriptionId) return {}
if (!this.stripeManager) {
Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/StripeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ export class StripeManager {
}
}

public async updateCustomerEmail(customerId: string, email: string) {
if (!this.stripe) throw new Error('Stripe is not initialized')
await this.stripe.customers.update(customerId, { email })
}

public async getAdditionalSeatsProration(subscriptionId: string, quantity: number) {
if (!this.stripe) {
throw new Error('Stripe is not initialized')
Expand Down
10 changes: 10 additions & 0 deletions packages/server/src/enterprise/controllers/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ export class AccountController {
}
}

public async confirmEmailChange(req: Request, res: Response, next: NextFunction) {
try {
const accountService = new AccountService()
const data = await accountService.confirmEmailChange(req.body)
return res.status(StatusCodes.OK).json(data)
} catch (error) {
next(error)
}
}

public async forgotPassword(req: Request, res: Response, next: NextFunction) {
try {
const accountService = new AccountService()
Expand Down
9 changes: 6 additions & 3 deletions packages/server/src/enterprise/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { GeneralErrorMessage } from '../../utils/constants'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
import { User } from '../database/entities/user.entity'
import { AccountService } from '../services/account.service'
import { UserErrorMessage, UserService } from '../services/user.service'

export class UserController {
Expand Down Expand Up @@ -51,7 +52,6 @@ export class UserController {

public async update(req: Request, res: Response, next: NextFunction) {
try {
const userService = new UserService()
const currentUser = req.user
if (!currentUser) {
throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, UserErrorMessage.USER_NOT_FOUND)
Expand All @@ -60,8 +60,11 @@ export class UserController {
if (currentUser.id !== id) {
throw new InternalFlowiseError(StatusCodes.FORBIDDEN, UserErrorMessage.USER_NOT_FOUND)
}
const user = await userService.updateUser(req.body)
return res.status(StatusCodes.OK).json(user)
const accountService = new AccountService()
const result = await accountService.updateAuthenticatedUserProfile(currentUser.id, req.body, (userId, newEmail) =>
accountService.syncStripeCustomerEmailAfterUserEmailChange(userId, newEmail)
)
return res.status(StatusCodes.OK).json(result)
} catch (error) {
next(error)
}
Expand Down
877 changes: 877 additions & 0 deletions packages/server/src/enterprise/emails/confirm_email_change.hbs

Large diffs are not rendered by default.

1,282 changes: 1,282 additions & 0 deletions packages/server/src/enterprise/emails/confirm_email_change.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/server/src/enterprise/routes/account.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ router.post('/logout', accountController.logout)

router.post('/verify', accountController.verify)

router.post('/confirm-email-change', accountController.confirmEmailChange)

router.post('/resend-verification', accountController.resendVerificationEmail)

router.post('/forgot-password', accountController.forgotPassword)
Expand Down
Loading
Loading