mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-23 08:10:32 +00:00
Merge pull request #980 from bigcapitalhq/fix-signup-verification
fix: signup confirmation
This commit is contained in:
@@ -65,7 +65,7 @@ export class AuthController {
|
|||||||
return this.authApp.signUp(signupDto);
|
return this.authApp.signUp(signupDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/signup/confirm')
|
@Post('/signup/verify')
|
||||||
@ApiOperation({ summary: 'Confirm user signup' })
|
@ApiOperation({ summary: 'Confirm user signup' })
|
||||||
@ApiBody({
|
@ApiBody({
|
||||||
schema: {
|
schema: {
|
||||||
|
|||||||
@@ -7,17 +7,13 @@ import {
|
|||||||
import { GetAuthenticatedAccount } from './queries/GetAuthedAccount.service';
|
import { GetAuthenticatedAccount } from './queries/GetAuthedAccount.service';
|
||||||
import { Controller, Get, Post } from '@nestjs/common';
|
import { Controller, Get, Post } from '@nestjs/common';
|
||||||
import { Throttle } from '@nestjs/throttler';
|
import { Throttle } from '@nestjs/throttler';
|
||||||
import { IgnoreTenantSeededRoute } from '../Tenancy/EnsureTenantIsSeeded.guards';
|
import { TenantAgnosticRoute } from '../Tenancy/TenancyGlobal.guard';
|
||||||
import { IgnoreTenantInitializedRoute } from '../Tenancy/EnsureTenantIsInitialized.guard';
|
|
||||||
import { AuthenticationApplication } from './AuthApplication.sevice';
|
import { AuthenticationApplication } from './AuthApplication.sevice';
|
||||||
import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
|
||||||
import { IgnoreUserVerifiedRoute } from './guards/EnsureUserVerified.guard';
|
import { IgnoreUserVerifiedRoute } from './guards/EnsureUserVerified.guard';
|
||||||
|
|
||||||
@Controller('/auth')
|
@Controller('/auth')
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@ApiExcludeController()
|
@TenantAgnosticRoute()
|
||||||
@IgnoreTenantSeededRoute()
|
|
||||||
@IgnoreTenantInitializedRoute()
|
|
||||||
@IgnoreUserVerifiedRoute()
|
@IgnoreUserVerifiedRoute()
|
||||||
@Throttle({ auth: {} })
|
@Throttle({ auth: {} })
|
||||||
export class AuthedController {
|
export class AuthedController {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
IAuthSignedUpEventPayload,
|
IAuthSignedUpEventPayload,
|
||||||
IAuthSigningUpEventPayload,
|
IAuthSigningUpEventPayload,
|
||||||
} from '../Auth.interfaces';
|
} from '../Auth.interfaces';
|
||||||
import { defaultTo } from 'ramda';
|
|
||||||
import { ERRORS } from '../Auth.constants';
|
import { ERRORS } from '../Auth.constants';
|
||||||
import { hashPassword } from '../Auth.utils';
|
import { hashPassword } from '../Auth.utils';
|
||||||
import { ClsService } from 'nestjs-cls';
|
import { ClsService } from 'nestjs-cls';
|
||||||
@@ -51,10 +50,10 @@ export class AuthSignupService {
|
|||||||
const signupConfirmation = this.configService.get('signupConfirmation');
|
const signupConfirmation = this.configService.get('signupConfirmation');
|
||||||
|
|
||||||
const verifyTokenCrypto = crypto.randomBytes(64).toString('hex');
|
const verifyTokenCrypto = crypto.randomBytes(64).toString('hex');
|
||||||
const verifiedEnabed = defaultTo(signupConfirmation.enabled, false);
|
const verifiedEnabed = signupConfirmation.enabled ?? false;
|
||||||
const verifyToken = verifiedEnabed ? verifyTokenCrypto : '';
|
const verifyToken = verifiedEnabed ? verifyTokenCrypto : '';
|
||||||
const verified = !verifiedEnabed;
|
const verified = !verifiedEnabed;
|
||||||
|
|
||||||
const inviteAcceptedAt = moment().format('YYYY-MM-DD');
|
const inviteAcceptedAt = moment().format('YYYY-MM-DD');
|
||||||
|
|
||||||
// Triggers signin up event.
|
// Triggers signin up event.
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { SystemUser } from '@/modules/System/models/SystemUser';
|
|||||||
import { ServiceError } from '@/modules/Items/ServiceError';
|
import { ServiceError } from '@/modules/Items/ServiceError';
|
||||||
import { ERRORS } from '../Auth.constants';
|
import { ERRORS } from '../Auth.constants';
|
||||||
import { events } from '@/common/events/events';
|
import { events } from '@/common/events/events';
|
||||||
import { ModelObject } from 'objection';
|
|
||||||
import { ISignUpConfigmResendedEventPayload } from '../Auth.interfaces';
|
import { ISignUpConfigmResendedEventPayload } from '../Auth.interfaces';
|
||||||
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { UpdateOrganizationService } from './commands/UpdateOrganization.service
|
|||||||
import { IgnoreTenantInitializedRoute } from '../Tenancy/EnsureTenantIsInitialized.guard';
|
import { IgnoreTenantInitializedRoute } from '../Tenancy/EnsureTenantIsInitialized.guard';
|
||||||
import { IgnoreTenantSeededRoute } from '../Tenancy/EnsureTenantIsSeeded.guards';
|
import { IgnoreTenantSeededRoute } from '../Tenancy/EnsureTenantIsSeeded.guards';
|
||||||
import { IgnoreTenantModelsInitialize } from '../Tenancy/TenancyInitializeModels.guard';
|
import { IgnoreTenantModelsInitialize } from '../Tenancy/TenancyInitializeModels.guard';
|
||||||
|
import { IgnoreUserVerifiedRoute } from '../Auth/guards/EnsureUserVerified.guard';
|
||||||
import { GetBuildOrganizationBuildJob } from './commands/GetBuildOrganizationJob.service';
|
import { GetBuildOrganizationBuildJob } from './commands/GetBuildOrganizationJob.service';
|
||||||
import { OrganizationBaseCurrencyLocking } from './Organization/OrganizationBaseCurrencyLocking.service';
|
import { OrganizationBaseCurrencyLocking } from './Organization/OrganizationBaseCurrencyLocking.service';
|
||||||
import {
|
import {
|
||||||
@@ -93,6 +94,7 @@ export class OrganizationController {
|
|||||||
|
|
||||||
@Get('current')
|
@Get('current')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
|
@IgnoreUserVerifiedRoute()
|
||||||
@ApiOperation({ summary: 'Get current organization' })
|
@ApiOperation({ summary: 'Get current organization' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
import { TenancyContext } from './TenancyContext.service';
|
import { TenancyContext } from './TenancyContext.service';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
import { IS_PUBLIC_ROUTE } from '../Auth/Auth.constants';
|
import { IS_PUBLIC_ROUTE } from '../Auth/Auth.constants';
|
||||||
|
import { IS_TENANT_AGNOSTIC } from './TenancyGlobal.guard';
|
||||||
|
|
||||||
export const IS_IGNORE_TENANT_INITIALIZED = 'IS_IGNORE_TENANT_INITIALIZED';
|
export const IS_IGNORE_TENANT_INITIALIZED = 'IS_IGNORE_TENANT_INITIALIZED';
|
||||||
export const IgnoreTenantInitializedRoute = () =>
|
export const IgnoreTenantInitializedRoute = () =>
|
||||||
@@ -35,8 +36,12 @@ export class EnsureTenantIsInitializedGuard implements CanActivate {
|
|||||||
IS_PUBLIC_ROUTE,
|
IS_PUBLIC_ROUTE,
|
||||||
[context.getHandler(), context.getClass()],
|
[context.getHandler(), context.getClass()],
|
||||||
);
|
);
|
||||||
|
const isTenantAgnostic = this.reflector.getAllAndOverride<boolean>(
|
||||||
|
IS_TENANT_AGNOSTIC,
|
||||||
|
[context.getHandler(), context.getClass()],
|
||||||
|
);
|
||||||
// Skip the guard early if the route marked as public or ignored.
|
// Skip the guard early if the route marked as public or ignored.
|
||||||
if (isPublic || isIgnoreEnsureTenantInitialized) {
|
if (isPublic || isIgnoreEnsureTenantInitialized || isTenantAgnostic) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const tenant = await this.tenancyContext.getTenant();
|
const tenant = await this.tenancyContext.getTenant();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
import { TenancyContext } from './TenancyContext.service';
|
import { TenancyContext } from './TenancyContext.service';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
import { IS_PUBLIC_ROUTE } from '../Auth/Auth.constants';
|
import { IS_PUBLIC_ROUTE } from '../Auth/Auth.constants';
|
||||||
|
import { IS_TENANT_AGNOSTIC } from './TenancyGlobal.guard';
|
||||||
|
|
||||||
export const IS_IGNORE_TENANT_SEEDED = 'IS_IGNORE_TENANT_SEEDED';
|
export const IS_IGNORE_TENANT_SEEDED = 'IS_IGNORE_TENANT_SEEDED';
|
||||||
export const IgnoreTenantSeededRoute = () =>
|
export const IgnoreTenantSeededRoute = () =>
|
||||||
@@ -36,7 +37,12 @@ export class EnsureTenantIsSeededGuard implements CanActivate {
|
|||||||
context.getHandler(),
|
context.getHandler(),
|
||||||
context.getClass(),
|
context.getClass(),
|
||||||
]);
|
]);
|
||||||
if (isPublic || isIgnoreEnsureTenantSeeded) {
|
const isTenantAgnostic = this.reflector.getAllAndOverride<boolean>(
|
||||||
|
IS_TENANT_AGNOSTIC,
|
||||||
|
[context.getHandler(), context.getClass()],
|
||||||
|
);
|
||||||
|
// Skip the guard early if the route marked as public, tenant agnostic or ignored.
|
||||||
|
if (isPublic || isIgnoreEnsureTenantSeeded || isTenantAgnostic) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const tenant = await this.tenancyContext.getTenant();
|
const tenant = await this.tenancyContext.getTenant();
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export const useAuthMetadata = (props = {}) => {
|
|||||||
* Resend the mail of signup verification.
|
* Resend the mail of signup verification.
|
||||||
*/
|
*/
|
||||||
export const useAuthSignUpVerifyResendMail = (props) => {
|
export const useAuthSignUpVerifyResendMail = (props) => {
|
||||||
const apiRequest = useAuthApiRequest();
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
return useMutation(
|
return useMutation(
|
||||||
() => apiRequest.post(AuthRoute.SignupVerifyResend),
|
() => apiRequest.post(AuthRoute.SignupVerifyResend),
|
||||||
|
|||||||
Reference in New Issue
Block a user