๐ Open source, privacy-first web analytics โ a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Mailing; email & password change support in CE
Blue Mouse17564a453499
diff --git a/backend/apps/cloud/src/user/user.service.ts b/backend/apps/cloud/src/user/user.service.tsindex bfb49909b..16bbcbaf4 100644--- a/backend/apps/cloud/src/user/user.service.ts+++ b/backend/apps/cloud/src/user/user.service.ts@@ -196,13 +196,6 @@ export class UserService {err.push('at least 8 characters')}- // if(!/[a-z]/.test(pass))- // err.push('should contain at least one lower case')- // if(!/[A-Z]/.test(pass))- // err.push('should contain at least one upper case')- // if(!(/[!@#$%^&*(),.?":{}|<>]/g.test(pass)))- // err.push('should contain at least one symbol')-if (!_isEmpty(err)) {throw new BadRequestException(err)}diff --git a/backend/apps/community/src/app.module.ts b/backend/apps/community/src/app.module.tsindex 7c9b37a67..2a35a979d 100644--- a/backend/apps/community/src/app.module.ts+++ b/backend/apps/community/src/app.module.ts@@ -2,6 +2,7 @@ import { Module } from '@nestjs/common'import { ConfigModule } from '@nestjs/config'import { ScheduleModule } from '@nestjs/schedule'import { NestjsFormDataModule } from 'nestjs-form-data'+import { MailerModule as NodeMailerModule } from '@nestjs-modules/mailer'import { I18nModule } from 'nestjs-i18n'import { UserModule } from './user/user.module'@@ -13,6 +14,7 @@ import { getI18nConfig } from './configs'import { AuthModule } from './auth/auth.module'import { AppController } from './app.controller'import { isPrimaryNode } from './common/utils'+import { MailerModule } from './mailer/mailer.module'const modules = [ConfigModule.forRoot({@@ -21,10 +23,27 @@ const modules = [expandVariables: true,isGlobal: true,}),+ NodeMailerModule.forRoot({+ transport: {+ sendingRate: 14,+ // pool: true, // if true - set up pooled connections against a SMTP server+ host: process.env.SMTP_HOST,+ port: Number(process.env.SMTP_PORT),+ secure: true, // if false - upgrade later with STARTTLS+ auth: {+ user: process.env.SMTP_USER,+ pass: process.env.SMTP_PASSWORD,+ },+ },+ defaults: {+ from: `"Swetrix Community Edition" <${process.env.FROM_EMAIL || '[email protected]'}>`, // outgoing email ID+ },+ }),I18nModule.forRootAsync(getI18nConfig()),ScheduleModule.forRoot(),NestjsFormDataModule.config({ isGlobal: true }),UserModule,+ MailerModule,ProjectModule,AnalyticsModule,PingModule,diff --git a/backend/apps/community/src/auth/auth.controller.ts b/backend/apps/community/src/auth/auth.controller.tsindex 18ecc4914..4d28ca61e 100644--- a/backend/apps/community/src/auth/auth.controller.ts+++ b/backend/apps/community/src/auth/auth.controller.ts@@ -14,19 +14,22 @@ import {Headers,Res,BadRequestException,+ Get,+ Param,} from '@nestjs/common'import {ApiTags,ApiOperation,ApiOkResponse,ApiCreatedResponse,+ ApiBearerAuth,} from '@nestjs/swagger'import { I18nValidationExceptionFilter, I18n, I18nContext } from 'nestjs-i18n'import { Response } from 'express'import { checkRateLimit, getIPFromHeaders } from '../common/utils'import { AuthService } from './auth.service'-import { Public, CurrentUserId, CurrentUser } from './decorators'+import { Public, CurrentUserId, CurrentUser, Roles } from './decorators'import {LoginResponseDto,LoginRequestDto,@@ -35,8 +38,15 @@ import {OIDCGetJWTByHashDto,RegisterRequestDto,RegisterResponseDto,+ RequestChangeEmailDto,+ ConfirmChangeEmailDto,} from './dtos'-import { JwtAccessTokenGuard, JwtRefreshTokenGuard } from './guards'+import { JwtAccessTokenGuard, JwtRefreshTokenGuard, RolesGuard } from './guards'+import { UserType } from '../user/entities/user.entity'+import { LetterTemplate } from '../mailer/letter'+import { MailerService } from '../mailer/mailer.service'+import { redis } from '../common/constants'+import { v4 as uuidv4 } from 'uuid'import { OIDC_ENABLED, OIDC_ONLY_AUTH } from '../common/constants'import { UserService } from '../user/user.service'@@ -56,6 +66,7 @@ export class AuthController {constructor(private readonly authService: AuthService,private readonly userService: UserService,+ private readonly mailerService: MailerService,) {}@ApiOperation({ summary: 'Register a new user' })@@ -149,6 +160,89 @@ export class AuthController {}}+ @ApiBearerAuth()+ @ApiOperation({ summary: 'Request a change of email (CE)' })+ @ApiOkResponse({+ description: 'Change email requested',+ })+ @UseGuards(RolesGuard)+ @Roles(UserType.CUSTOMER, UserType.ADMIN)+ @Post('change-email')+ public async requestChangeEmail(+ @Body() body: RequestChangeEmailDto,+ @CurrentUserId() userId: string,+ @I18n() i18n: I18nContext,+ ): Promise<void> {+ const user = await this.userService.findOne({ id: userId })++ if (!user) {+ throw new UnauthorizedException()+ }++ const isPasswordValid = await this.authService.getBasicUser(+ user.email,+ body.password,+ )++ if (!isPasswordValid) {+ throw new ConflictException(i18n.t('auth.invalidPassword'))+ }++ const userWithByEmail = await this.userService.findOne({+ email: body.newEmail,+ })++ if (userWithByEmail) {+ throw new ConflictException(i18n.t('user.emailAlreadyUsed'))+ }++ const token = uuidv4()+ await redis.set(+ `email_change:${token}`,+ JSON.stringify({ id: user.id, newEmail: body.newEmail }),+ 'EX',+ 3600,+ )++ const url = `${process.env.CLIENT_URL || ''}/change-email/${token}`+ await this.mailerService.sendEmail(+ user.email,+ LetterTemplate.MailAddressChangeConfirmation,+ { url },+ )+ }++ @ApiOperation({ summary: 'Confirm a user email change (CE)' })+ @ApiOkResponse({+ description: 'User email confirmed',+ })+ @Public()+ @Get('change-email/confirm/:token')+ public async confirmChangeEmail(+ @Param() params: ConfirmChangeEmailDto,+ @I18n() i18n: I18nContext,+ ): Promise<void> {+ const data = await redis.get(`email_change:${params.token}`)++ if (!data) {+ throw new ConflictException(i18n.t('auth.invalidChangeEmailToken'))+ }++ let payload: { id: string; newEmail: string }+ try {+ payload = JSON.parse(data)+ } catch {+ throw new ConflictException(i18n.t('auth.invalidChangeEmailToken'))+ }++ await this.userService.update(payload.id, { email: payload.newEmail })+ await redis.del(`email_change:${params.token}`)+ await this.mailerService.sendEmail(+ payload.newEmail,+ LetterTemplate.MailAddressHadChanged,+ )+ }+@ApiOperation({ summary: 'Refresh a token' })@ApiOkResponse({description: 'Token refreshed',diff --git a/backend/apps/community/src/auth/auth.service.ts b/backend/apps/community/src/auth/auth.service.tsindex b543111ac..2bb8b7ae2 100644--- a/backend/apps/community/src/auth/auth.service.ts+++ b/backend/apps/community/src/auth/auth.service.ts@@ -19,6 +19,7 @@ import {findRefreshTokenClickhouse,deleteRefreshTokenClickhouse,assignUnassignedProjectsToUserClickhouse,+ deleteAllRefreshTokensClickhouse,} from '../common/utils'import {JWT_ACCESS_TOKEN_SECRET,@@ -228,6 +229,10 @@ export class AuthService {await deleteRefreshTokenClickhouse(userId, refreshToken)}+ async logoutAll(userId: string) {+ await deleteAllRefreshTokensClickhouse(userId)+ }+getOidcConfig() {return {discoveryURL: this.configService.get('OIDC_DISCOVERY_URL'),diff --git a/backend/apps/community/src/auth/dtos/confirm-change-email.dto.ts b/backend/apps/community/src/auth/dtos/confirm-change-email.dto.tsnew file mode 100644index 000000000..978d62050--- /dev/null+++ b/backend/apps/community/src/auth/dtos/confirm-change-email.dto.ts@@ -0,0 +1,11 @@+import { ApiProperty } from '@nestjs/swagger'+import { IsUUID } from 'class-validator'++export class ConfirmChangeEmailDto {+ @ApiProperty({+ description: 'The token to confirm the change email',+ example: 'a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',+ })+ @IsUUID('4', { message: 'Please enter the valid UUID.' })+ public readonly token: string+}diff --git a/backend/apps/community/src/auth/dtos/index.ts b/backend/apps/community/src/auth/dtos/index.tsindex a49558cd1..25722d00a 100644--- a/backend/apps/community/src/auth/dtos/index.ts+++ b/backend/apps/community/src/auth/dtos/index.ts@@ -1,3 +1,5 @@export * from './login.dto'export * from './oidc-auth.dto'export * from './register.dto'+export * from './request-change-email.dto'+export * from './confirm-change-email.dto'diff --git a/backend/apps/community/src/auth/dtos/request-change-email.dto.ts b/backend/apps/community/src/auth/dtos/request-change-email.dto.tsnew file mode 100644index 000000000..dc7e3ebd7--- /dev/null+++ b/backend/apps/community/src/auth/dtos/request-change-email.dto.ts@@ -0,0 +1,23 @@+import { ApiProperty } from '@nestjs/swagger'+import { IsEmail, MaxLength, MinLength } from 'class-validator'++export class RequestChangeEmailDto {+ @ApiProperty({+ description: 'New email address',+ example: '[email protected]',+ maxLength: 254,+ minLength: 6,+ })+ @IsEmail({}, { message: 'Please enter the valid email.' })+ public readonly newEmail: string++ @ApiProperty({+ description: 'Current user password (for verification)',+ example: '%d7*c4W45p',+ maxLength: 72,+ minLength: 8,+ })+ @MaxLength(50, { message: 'Max length is $constraint1 characters' })+ @MinLength(8, { message: 'Min length is $constraint1 characters' })+ public readonly password: string+}diff --git a/backend/apps/community/src/common/templates/en/customer_project-invitation.html b/backend/apps/community/src/common/templates/en/customer_project-invitation.htmlnew file mode 100644index 000000000..6b78b7d5d--- /dev/null+++ b/backend/apps/community/src/common/templates/en/customer_project-invitation.html@@ -0,0 +1,11 @@+<a href="mailto:{{email}}">{{email}}</a> has invited you to the {{name}} website analytics dashboard with the role {{role}} on Swetrix.+<br/>+Click the button below to accept the invitation or ignore this email if you do not want to join the project.+<br/>+The invitation will expire in {{expiration}} hours.+<br/>+<a href="{{url}}" target="_blank">Accept invitation</a>+<br/>+If you are having trouble with the button above, copy and paste the URL below directly into your web browser:+<br/>+{{url}}diff --git a/backend/apps/community/src/common/templates/en/mailaddress-change_confirmation.html b/backend/apps/community/src/common/templates/en/mailaddress-change_confirmation.htmlnew file mode 100644index 000000000..34e116129--- /dev/null+++ b/backend/apps/community/src/common/templates/en/mailaddress-change_confirmation.html@@ -0,0 +1,9 @@+You have changed your email address at swetrix.com+<br/>+The new email will only be applied after you have confirmed this action by clicking the link below.+<br/>+<br/>+<a href="{{url}}" target="_blank">Confirm email update.</a>+<br/>+<br/>+If you have not changed your email, please ignore this email or reply to it so we could assist you in securing your account.diff --git a/backend/apps/community/src/common/templates/en/mailaddress-change_information.html b/backend/apps/community/src/common/templates/en/mailaddress-change_information.htmlnew file mode 100644index 000000000..821075dad--- /dev/null+++ b/backend/apps/community/src/common/templates/en/mailaddress-change_information.html@@ -0,0 +1,4 @@+Your email address at swetrix.com has been updated.+<br/>+<br/>+If you have not done so, please reply to this email so we could assist you in securing your account.diff --git a/backend/apps/community/src/common/templates/en/password-change_confirmation.html b/backend/apps/community/src/common/templates/en/password-change_confirmation.htmlnew file mode 100644index 000000000..ed7a440e3--- /dev/null+++ b/backend/apps/community/src/common/templates/en/password-change_confirmation.html@@ -0,0 +1,7 @@+You have changed your password at swetrix.com+<br/>+The new password will only be applied after you have confirmed this action by clicking the link below.+<a href="{{url}}" target="_blank">Confirm password change</a>+<br/>+<br/>+If you have not changed your password, please ignore this email or reply to it so we could assist you in securing your account.diff --git a/backend/apps/community/src/common/templates/en/password-change_information.html b/backend/apps/community/src/common/templates/en/password-change_information.htmlnew file mode 100644index 000000000..c1a62d489--- /dev/null+++ b/backend/apps/community/src/common/templates/en/password-change_information.html@@ -0,0 +1,4 @@+Your password at swetrix.com has been changed.+<br/>+<br/>+If you have not done so, please reply to this email so we could assist you in securing your account.diff --git a/backend/apps/community/src/common/templates/en/project-transfer.html b/backend/apps/community/src/common/templates/en/project-transfer.htmlnew file mode 100644index 000000000..e451c151c--- /dev/null+++ b/backend/apps/community/src/common/templates/en/project-transfer.html@@ -0,0 +1,13 @@+A Swetrix user wants to transfer of the {{name}} project to your account.+<br/>+If you accept the invitation, this project well be transferred to your account and the previous owner will be added as an administator (you will be able to edit project admins and viewers in the project settings).+<br />+<a href="{{confirmUrl}}" target="_blank">Accept transfer</a> | <a href="{{cancelUrl}}" target="_blank">Decline transfer</a>+<br /><br />+If you are having trouble with the button above, copy and paste the URL below directly into your web browser to accept transfer:+<br />+{{confirmUrl}}+<br /><br />+Or copy and paste the URL below directly into your web browser to decline transfer:+<br/>+{{cancelUrl}}diff --git a/backend/apps/community/src/common/utils.ts b/backend/apps/community/src/common/utils.tsindex 591944871..37814e0ce 100644--- a/backend/apps/community/src/common/utils.ts+++ b/backend/apps/community/src/common/utils.ts@@ -189,6 +189,17 @@ const getFunnelsClickhouse = async (return data}+const deleteAllRefreshTokensClickhouse = async (userId: string) => {+ const query = `ALTER TABLE refresh_token DELETE WHERE userId = {userId:String}`++ await clickhouse.command({+ query,+ query_params: {+ userId,+ },+ })+}+const updateFunnelClickhouse = async (funnel: any) => {const filtered = _reduce(_filter(_keys(funnel), key => ALLOWED_FUNNEL_KEYS.includes(key)),@@ -1010,6 +1021,7 @@ export {saveRefreshTokenClickhouse,findRefreshTokenClickhouse,deleteRefreshTokenClickhouse,+ deleteAllRefreshTokensClickhouse,getGeoDetails,getIPFromHeaders,sumArrays,diff --git a/backend/apps/community/src/mailer/letter.ts b/backend/apps/community/src/mailer/letter.tsnew file mode 100644index 000000000..58f309f42--- /dev/null+++ b/backend/apps/community/src/mailer/letter.ts@@ -0,0 +1,8 @@+export enum LetterTemplate {+ ConfirmPasswordChange = 'password-change_confirmation',+ PasswordChanged = 'password-change_information',+ MailAddressChangeConfirmation = 'mailaddress-change_confirmation',+ MailAddressHadChanged = 'mailaddress-change_information',+ ProjectInvitation = 'customer_project-invitation',+ ProjectTransfer = 'project-transfer',+}diff --git a/backend/apps/community/src/mailer/mailer.module.ts b/backend/apps/community/src/mailer/mailer.module.tsnew file mode 100644index 000000000..606610607--- /dev/null+++ b/backend/apps/community/src/mailer/mailer.module.ts@@ -0,0 +1,10 @@+import { Module } from '@nestjs/common'+import { AppLoggerModule } from '../logger/logger.module'+import { MailerService } from './mailer.service'++@Module({+ providers: [MailerService],+ exports: [MailerService],+ imports: [AppLoggerModule],+})+export class MailerModule {}diff --git a/backend/apps/community/src/mailer/mailer.service.ts b/backend/apps/community/src/mailer/mailer.service.tsnew file mode 100644index 000000000..dc4156331--- /dev/null+++ b/backend/apps/community/src/mailer/mailer.service.ts@@ -0,0 +1,108 @@+import fs from 'fs'+import path from 'path'+import { MailerService as NodeMailerService } from '@nestjs-modules/mailer'+import { Injectable } from '@nestjs/common'+import handlebars from 'handlebars'+import { LetterTemplate } from './letter'+import { AppLoggerService } from '../logger/logger.service'++const TEMPLATES_PATH = path.join(__dirname, '..', 'common', 'templates')+const metaInfoJson = {+ [LetterTemplate.ConfirmPasswordChange]: {+ subject: {+ en: () => 'Please confirm the password change',+ },+ },+ [LetterTemplate.MailAddressChangeConfirmation]: {+ subject: {+ en: () => 'Please confirm the new e-mail address',+ },+ },+ [LetterTemplate.MailAddressHadChanged]: {+ subject: {+ en: () => 'A new e-mail-address has been saved',+ },+ },+ [LetterTemplate.PasswordChanged]: {+ subject: {+ en: () => 'Your password was successfully changed',+ },+ },+ [LetterTemplate.ProjectInvitation]: {+ subject: {+ en: () => 'You have been invited to join the project',+ },+ },+ [LetterTemplate.ProjectTransfer]: {+ subject: {+ en: (p: Params) =>+ `A Swetrix user offers to transfer ${p.name} project to your account`,+ },+ },+}++interface Params {+ [name: string]: any+}++handlebars.registerHelper('ifEquals', function ifEquals(arg1, arg2, options) {+ return arg1 == arg2 ? options.fn(this) : options.inverse(this)+})++handlebars.registerHelper(+ 'ifNotEquals',+ function ifNotEquals(arg1, arg2, options) {+ return arg1 != arg2 ? options.fn(this) : options.inverse(this)+ },+)++handlebars.registerHelper('greater', function greater(v1, v2, options) {+ if (v1 > v2) {+ return options.fn(this)+ }+ return options.inverse(this)+})++@Injectable()+export class MailerService {+ constructor(+ private readonly logger: AppLoggerService,+ private readonly nodeMailerService: NodeMailerService,+ ) {}++ async sendEmail(+ email: string,+ templateName: LetterTemplate,+ params: Params = null,+ ): Promise<void> {+ try {+ const templatePath = `${TEMPLATES_PATH}/en/${templateName}.html`+ const letter = fs.readFileSync(templatePath, { encoding: 'utf-8' })+ const subject = metaInfoJson[templateName].subject.en(params)+ const template = handlebars.compile(letter)+ const html = template(params)++ const message = {+ from: process.env.FROM_EMAIL || '[email protected]',+ to: email,+ subject,+ html,+ }++ if (process.env.SMTP_MOCK) {+ this.logger.log(+ {+ ...message,+ params,+ },+ 'sendEmail',+ true,+ )+ } else {+ await this.nodeMailerService.sendMail(message)+ }+ } catch (reason) {+ this.logger.error(reason, 'sendEmail', true)+ }+ }+}diff --git a/backend/apps/community/src/user/dto/update-user.dto.ts b/backend/apps/community/src/user/dto/update-user.dto.tsindex edee5c092..5154965f0 100644--- a/backend/apps/community/src/user/dto/update-user.dto.ts+++ b/backend/apps/community/src/user/dto/update-user.dto.ts@@ -7,4 +7,10 @@ export class UpdateUserProfileDTO {@ApiProperty({ example: '24-hour', enum: TimeFormat })timeFormat: string++ @ApiProperty({ example: '[email protected]', required: false })+ email?: string++ @ApiProperty({ example: 'newStrongPassword123', required: false })+ password?: string}diff --git a/backend/apps/community/src/user/user.controller.ts b/backend/apps/community/src/user/user.controller.tsindex 7f3b161a6..3af19a672 100644--- a/backend/apps/community/src/user/user.controller.ts+++ b/backend/apps/community/src/user/user.controller.ts@@ -34,6 +34,13 @@ import {updateProjectShareClickhouse,deleteProjectShareClickhouse,} from '../common/utils'+import { MailerService } from '../mailer/mailer.service'+import { AuthService } from '../auth/auth.service'+import { LetterTemplate } from '../mailer/letter'+//+import { Request } from 'express'+import { Req } from '@nestjs/common'+import { redis } from '../common/constants'@ApiTags('User')@Controller('user')@@ -42,6 +49,8 @@ export class UserController {constructor(private readonly logger: AppLoggerService,private readonly userService: UserService,+ private readonly mailerService: MailerService,+ private readonly authService: AuthService,) {}@ApiBearerAuth()@@ -278,6 +287,7 @@ export class UserController {async updateCurrentUser(@Body() userDTO: UpdateUserProfileDTO,@CurrentUserId() id: string,+ @Req() request: Request,) {this.logger.log({ userDTO, id }, 'PUT /user')@@ -288,13 +298,53 @@ export class UserController {}try {- const user = await this.userService.update(id, {+ if (userDTO.password && typeof userDTO.password === 'string') {+ this.userService.validatePassword(userDTO.password)++ const hashed = await this.authService.hashPassword(userDTO.password)+ await this.userService.update(id, { password: hashed })++ await this.mailerService.sendEmail(+ originalUser.email,+ LetterTemplate.PasswordChanged,+ )+ await this.authService.logoutAll(id)+ }++ if (userDTO.email && userDTO.email !== originalUser.email) {+ const userWithByEmail = await this.userService.findOne({+ email: userDTO.email,+ })++ if (userWithByEmail) {+ throw new BadRequestException('User with this email already exists')+ }++ await checkRateLimit(id, 'change-email', 5, 3600)++ // TODO: Change this if we introduce CLIENT_URL in CE as .env variable+ const urlBase = request.headers.origin || ''++ const token = uuidv4()+ const url = `${urlBase}/change-email/${token}`++ await this.mailerService.sendEmail(+ originalUser.email,+ LetterTemplate.MailAddressChangeConfirmation,+ { url },+ )++ await redis.set(`email_change:${token}`, userDTO.email, 'EX', 60 * 60)+ }++ await this.userService.update(id, {timeFormat: userDTO.timeFormat,timezone: userDTO.timezone,})+ const updated = await this.userService.findOne({ id })return {- ...this.userService.omitSensitiveData(user),+ ...this.userService.omitSensitiveData(updated),}} catch (reason) {console.error(diff --git a/backend/apps/community/src/user/user.module.ts b/backend/apps/community/src/user/user.module.tsindex a45a8a8ca..ecbff4f39 100644--- a/backend/apps/community/src/user/user.module.ts+++ b/backend/apps/community/src/user/user.module.ts@@ -3,9 +3,11 @@ import { Module } from '@nestjs/common'import { UserController } from './user.controller'import { UserService } from './user.service'import { AppLoggerModule } from '../logger/logger.module'+import { MailerModule } from '../mailer/mailer.module'+import { AuthModule } from '../auth/auth.module'@Module({- imports: [AppLoggerModule],+ imports: [AppLoggerModule, MailerModule, AuthModule],providers: [UserService],exports: [UserService],controllers: [UserController],diff --git a/backend/apps/community/src/user/user.service.ts b/backend/apps/community/src/user/user.service.tsindex fc829b09b..ba742ec3a 100644--- a/backend/apps/community/src/user/user.service.ts+++ b/backend/apps/community/src/user/user.service.ts@@ -1,6 +1,8 @@-import { Injectable } from '@nestjs/common'+import { BadRequestException, Injectable } from '@nestjs/common'import { v4 as uuidv4 } from 'uuid'import _omit from 'lodash/omit'+import _isEmpty from 'lodash/isEmpty'+import _size from 'lodash/size'import { clickhouse } from '../common/integrations/clickhouse'import { User, type ClickhouseInputUser } from '../common/types'import {@@ -157,6 +159,25 @@ export class UserService {return _omit(user, ['password'])}+ validatePassword(pass: string): void {+ const err = []+ if (_isEmpty(pass)) {+ err.push('Password cannot be empty')+ }++ if (_size(pass) > 50) {+ err.push('Maximum password length is 50 letters')+ }++ if (_size(pass) < 8) {+ err.push('at least 8 characters')+ }++ if (!_isEmpty(err)) {+ throw new BadRequestException(err)+ }+ }+formatUser(user?: ClickhouseInputUser): User {if (!user) {return undefineddiff --git a/backend/blog-posts b/backend/blog-postsindex 21fe3d475..31caa123f 160000--- a/backend/blog-posts+++ b/backend/blog-posts@@ -1 +1 @@-Subproject commit 21fe3d4752d7528f51157df1aee39286e297d94c+Subproject commit 31caa123ff9bb641c1c38a1111e0ceb7e6c7d4c0diff --git a/web/app/components/Footer/index.tsx b/web/app/components/Footer/index.tsxindex cd73f4d60..94f81dc2a 100644--- a/web/app/components/Footer/index.tsx+++ b/web/app/components/Footer/index.tsx@@ -298,13 +298,15 @@ const Footer = ({ showDBIPMessage }: FooterProps) => {t('footer.description'))}</p>- <div className='flex text-white'>- <Trans t={t} i18nKey='footer.madeInHostedIn'>- <Flag className='mx-[1ch]' country='GB' size={18} alt='GB' aria-hidden='true' />- <Flag className='mx-[1ch]' country='UA' size={18} alt='UA' aria-hidden='true' />- <Flag className='mx-[1ch]' country='EU' size={18} alt='EU' aria-hidden='true' />- </Trans>- </div>+ {isSelfhosted ? null : (+ <div className='flex text-white'>+ <Trans t={t} i18nKey='footer.madeInHostedIn'>+ <Flag className='mx-[1ch]' country='GB' size={18} alt='GB' aria-hidden='true' />+ <Flag className='mx-[1ch]' country='UA' size={18} alt='UA' aria-hidden='true' />+ <Flag className='mx-[1ch]' country='EU' size={18} alt='EU' aria-hidden='true' />+ </Trans>+ </div>+ )}<div className='flex space-x-4'>{_map(navigation.social, (item) => (<a@@ -354,13 +356,13 @@ const Footer = ({ showDBIPMessage }: FooterProps) => {return (<li key={displayValue}>{internal ? (- <Link to={href} className='text-base text-white hover:text-gray-200'>+ <Link to={href} className='text-base text-white hover:underline'>{displayValue}</Link>) : (<ahref={href}- className='text-base text-white hover:text-gray-200'+ className='text-base text-white hover:underline'target='_blank'rel='noopener noreferrer'aria-label={`${displayValue} (opens in a new tab)`}@@ -379,13 +381,13 @@ const Footer = ({ showDBIPMessage }: FooterProps) => {{_map(navigation.company, ({ key, href, internal }) => (<li key={key}>{internal ? (- <Link to={href} className='text-base text-white hover:text-gray-200'>+ <Link to={href} className='text-base text-white hover:underline'>{t(`footer.${key}`)}</Link>) : (<ahref={href}- className='text-base text-white hover:text-gray-200'+ className='text-base text-white hover:underline'target='_blank'rel='noopener noreferrer'aria-label={`${t(`footer.${key}`)} (opens in a new tab)`}@@ -406,13 +408,13 @@ const Footer = ({ showDBIPMessage }: FooterProps) => {return (<li key={key}>{internal ? (- <Link to={href} className='text-base text-white hover:text-gray-200'>+ <Link to={href} className='text-base text-white hover:underline'>{t(`footer.${key}`)}</Link>) : (<ahref={href}- className='text-base text-white hover:text-gray-200'+ className='text-base text-white hover:underline'target='_blank'rel='noopener noreferrer'aria-label={`${t(`footer.${key}`)} (opens in a new tab)`}@@ -427,7 +429,7 @@ const Footer = ({ showDBIPMessage }: FooterProps) => {{showDBIPMessage ? (<li><a- className='text-base text-white hover:text-gray-200'+ className='text-base text-white hover:underline'target='_blank'rel='noopener noreferrer'href='https://db-ip.com'diff --git a/web/app/pages/UserSettings/UserSettings.tsx b/web/app/pages/UserSettings/UserSettings.tsxindex 37be76408..f88ee7b0d 100644--- a/web/app/pages/UserSettings/UserSettings.tsx+++ b/web/app/pages/UserSettings/UserSettings.tsx@@ -534,9 +534,6 @@ const UserSettings = () => {if (activeTab === TAB_MAPPING.ACCOUNT) {return (<>- <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>- {t('profileSettings.general')}- </h3><Inputname='email'type='email'@@ -546,126 +543,89 @@ const UserSettings = () => {className='mt-4'onChange={handleInput}error={beenSubmitted ? errors.email : null}- disabled={isSelfhosted}/>- {isSelfhosted ? (- <>- <hr className='mt-5 border-gray-200 dark:border-gray-600' />+ <span+ onClick={toggleShowPasswordFields}+ className='mt-2 flex max-w-max cursor-pointer items-center text-sm text-gray-900 hover:underline dark:text-gray-50'+ >+ {t('auth.common.changePassword')}+ <ChevronDownIcon+ className={cx('ml-2 size-3', {+ 'rotate-180': showPasswordFields,+ })}+ />+ </span>+ {showPasswordFields ? (+ <div className='mt-4 grid grid-cols-1 gap-x-4 gap-y-6 sm:grid-cols-6'>+ <Input+ name='password'+ type='password'+ label={t('auth.common.password')}+ hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}+ value={form.password}+ placeholder={t('auth.common.password')}+ className='sm:col-span-3'+ onChange={handleInput}+ error={beenSubmitted ? errors.password : null}+ />+ <Input+ name='repeat'+ type='password'+ label={t('auth.common.repeat')}+ value={form.repeat}+ placeholder={t('auth.common.repeat')}+ className='sm:col-span-3'+ onChange={handleInput}+ error={beenSubmitted ? errors.repeat : null}+ />+ </div>+ ) : null}+ <Button className='mt-4' type='submit' primary large>+ {t('profileSettings.update')}+ </Button>- <h3 className='mt-2 flex items-center text-lg font-bold text-gray-900 dark:text-gray-50'>- {t('profileSettings.apiKey')}- </h3>- {user?.apiKey ? (- <>- <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>- {t('profileSettings.apiKeyWarning')}- </p>- <div className='grid grid-cols-1 gap-x-4 gap-y-6 lg:grid-cols-2'>- <Input- label={t('profileSettings.apiKey')}- name='apiKey'- className='mt-4'- value={user.apiKey}- disabled- />- </div>- </>- ) : (- <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>- {t('profileSettings.noApiKey')}- </p>- )}- {user?.apiKey ? (- <Button className='mt-4' onClick={() => setShowAPIDeleteModal(true)} danger large>- {t('profileSettings.deleteApiKeyBtn')}- </Button>- ) : (- <Button className='mt-4' onClick={onApiKeyGenerate} primary large>- {t('profileSettings.addApiKeyBtn')}- </Button>- )}+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />++ <h3 className='mt-2 flex items-center text-lg font-bold text-gray-900 dark:text-gray-50'>+ {t('profileSettings.apiKey')}+ </h3>+ {user?.apiKey ? (+ <>+ <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>+ {t('profileSettings.apiKeyWarning')}+ </p>+ <div className='grid grid-cols-1 gap-x-4 gap-y-6 lg:grid-cols-2'>+ <Input+ label={t('profileSettings.apiKey')}+ name='apiKey'+ className='mt-4'+ value={user.apiKey}+ disabled+ />+ </div>+ </>+ ) : (+ <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>+ {t('profileSettings.noApiKey')}+ </p>+ )}+ {user?.apiKey ? (+ <Button className='mt-4' onClick={() => setShowAPIDeleteModal(true)} danger large>+ {t('profileSettings.deleteApiKeyBtn')}+ </Button>+ ) : (+ <Button className='mt-4' onClick={onApiKeyGenerate} primary large>+ {t('profileSettings.addApiKeyBtn')}+ </Button>+ )}+ {isSelfhosted ? (+ <>{/* Shared projects setting */}<SharedProjects /></>) : (<>- <span- onClick={toggleShowPasswordFields}- className='mt-2 flex max-w-max cursor-pointer items-center text-sm text-gray-900 hover:underline dark:text-gray-50'- >- {t('auth.common.changePassword')}- <ChevronDownIcon- className={cx('ml-2 size-3', {- 'rotate-180': showPasswordFields,- })}- />- </span>- {showPasswordFields ? (- <div className='mt-4 grid grid-cols-1 gap-x-4 gap-y-6 sm:grid-cols-6'>- <Input- name='password'- type='password'- label={t('auth.common.password')}- hint={t('auth.common.hint', { amount: MIN_PASSWORD_CHARS })}- value={form.password}- placeholder={t('auth.common.password')}- className='sm:col-span-3'- onChange={handleInput}- error={beenSubmitted ? errors.password : null}- />- <Input- name='repeat'- type='password'- label={t('auth.common.repeat')}- value={form.repeat}- placeholder={t('auth.common.repeat')}- className='sm:col-span-3'- onChange={handleInput}- error={beenSubmitted ? errors.repeat : null}- />- </div>- ) : null}- <Button className='mt-4' type='submit' primary large>- {t('profileSettings.update')}- </Button>-- <hr className='mt-5 border-gray-200 dark:border-gray-600' />-- {/* API access setup */}- <h3 className='mt-2 flex items-center text-lg font-bold text-gray-900 dark:text-gray-50'>- {t('profileSettings.apiKey')}- </h3>- {user?.apiKey ? (- <>- <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>- {t('profileSettings.apiKeyWarning')}- </p>- <div className='grid grid-cols-1 gap-x-4 gap-y-6 lg:grid-cols-2'>- <Input- label={t('profileSettings.apiKey')}- name='apiKey'- className='mt-4'- value={user.apiKey}- disabled- />- </div>- </>- ) : (- <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>- {t('profileSettings.noApiKey')}- </p>- )}- {user?.apiKey ? (- <Button className='mt-4' onClick={() => setShowAPIDeleteModal(true)} danger large>- {t('profileSettings.deleteApiKeyBtn')}- </Button>- ) : (- <Button className='mt-4' onClick={onApiKeyGenerate} primary large>- {t('profileSettings.addApiKeyBtn')}- </Button>- )}-{/* 2FA setting */}<hr className='mt-5 border-gray-200 dark:border-gray-600' /><h3 className='mt-2 flex items-center text-lg font-bold text-gray-900 dark:text-gray-50'>diff --git a/web/public/locales/en.json b/web/public/locales/en.jsonindex 320995e0a..992a9632f 100644--- a/web/public/locales/en.json+++ b/web/public/locales/en.json@@ -1193,7 +1193,6 @@},"captcha": {"settings": {- "general": "General settings","inheritance": "Inheritance","name": "CAPTCHA project name","pid": "CAPTCHA project ID",