Commit b169e05c authored by Abdul R. Wahid's avatar Abdul R. Wahid
Browse files

Merge branch 'develop' into 'master'

Fix Migration, Register Controls, Check OTP

See merge request riset/onest!28
parents d4572090 a84ad3a4
......@@ -611,6 +611,12 @@ const schema = {
env: 'MINIO_SECRETKEY'
}
},
minio_public_url: {
docs: 'MINIO PUBLIC URL',
type: String,
default: '',
env: 'MINIO_PUBLIC_URL'
},
sms: {
msg_tpl: {
doc: 'SMS Template',
......
......@@ -11,8 +11,8 @@ import { AdminService } from '@module/admin/admin.service'
import { AuthProfileDto, UserProfile } from '@module/auth/dto/authprofile.dto'
import { UserService } from '@module/user/user.service'
import { AuthRegisterDto } from '@module/auth/dto/authregister.dto'
import { AuthRegisterResultDto, AuthVerificationResultDto, AuthJwksResultDto, AuthLoginResultDto, AuthLogoutResultDto } from '@module/auth/dto/authresult.dto'
import { AuthVerificationRequestDto, AuthVerificationCheckDto, AuthVerificationPasswordDto } from '@module/auth/dto/authverification.dto'
import { AuthRegisterResultDto, AuthVerificationResultDto, AuthJwksResultDto, AuthLoginResultDto, AuthLogoutResultDto, AuthLoginTokenDto } from '@module/auth/dto/authresult.dto'
import { AuthVerificationRequestDto, AuthVerificationCheckDto, AuthVerificationPasswordDto, AuthVerificationPasswordQueryDto } from '@module/auth/dto/authverification.dto'
import { VerificationService } from '@module/verification/verification.service'
import { JwtAuth } from '@utils/jwt/decorator/jwt-auth.decorator'
import { User } from '@core/user/user'
......@@ -55,6 +55,10 @@ export class AuthController {
@Post('google/:entity')
@UseGuards(AuthGuard('google'))
@ApiBadRequestResponse({
description: 'Register for current entity disabled \n\n Errors: FAILED.',
type: JsonErrorResponse,
})
@ApiUnauthorizedResponse({
description: 'Login failed.',
type: JsonErrorResponse,
......@@ -68,6 +72,9 @@ export class AuthController {
console.log(e.toString())
throw new UnauthorizedException()
})
if (!syncedUser) {
throw new BadRequestException('FAILED')
}
return this.authService.login(syncedUser, req.params.entity, {
platform: body.platform,
deviceid: body.deviceid
......@@ -76,6 +83,10 @@ export class AuthController {
@Post('facebook/:entity')
@UseGuards(AuthGuard('facebook'))
@ApiBadRequestResponse({
description: 'Register for current entity disabled \n\n Errors: FAILED.',
type: JsonErrorResponse,
})
@ApiUnauthorizedResponse({
description: 'Login failed.',
type: JsonErrorResponse,
......@@ -89,6 +100,9 @@ export class AuthController {
console.log(e.toString())
throw new UnauthorizedException()
})
if (!syncedUser) {
throw new BadRequestException('FAILED')
}
return this.authService.login(syncedUser, req.params.entity, {
platform: body.platform,
deviceid: body.deviceid
......@@ -97,6 +111,10 @@ export class AuthController {
@Post('apple/:entity')
@UseGuards(AuthGuard('apple'))
@ApiBadRequestResponse({
description: 'Register for current entity disabled \n\n Errors: FAILED.',
type: JsonErrorResponse,
})
@ApiUnauthorizedResponse({
description: 'Login failed.',
type: JsonErrorResponse,
......@@ -110,6 +128,9 @@ export class AuthController {
console.log(e.toString())
throw new UnauthorizedException()
})
if (!syncedUser) {
throw new BadRequestException('FAILED')
}
return this.authService.login(syncedUser, req.params.entity, {
platform: body.platform,
deviceid: body.deviceid
......@@ -836,20 +857,52 @@ export class AuthController {
}
@Post('/password/reset/:entity')
@ApiNotFoundResponse({
description: 'Public Token Wrong or Expired \n\n Errors: TOKEN_WRONG_OR_EXPIRED',
type: JsonErrorResponse
})
@ApiBadRequestResponse({
description: 'Password Reset Failed. \n\n Errors: PASSWORD_RESET_FAILED',
type: JsonErrorResponse,
})
@ApiOkResponse({
description: 'Only Verify Token Match. \n\n Messages: TOKEN_MATCH',
type: AuthLoginResultDto
})
@ApiCreatedResponse({
description: 'Password Reset Success.',
type: AuthLoginResultDto
})
async doPasswordReset (@Request() req, @Param() param: AuthEntityDto, @Body() body: AuthVerificationPasswordDto) {
async doPasswordReset (@Request() req, @Param() param: AuthEntityDto, @Body() body: AuthVerificationPasswordDto, @Query() query: AuthVerificationPasswordQueryDto) {
let verification = await this.verificationService.findActiveByToken(body.token_public)
if (!verification) {
throw new NotFoundException('TOKEN_WRONG_OR_EXPIRED')
}
if (
!verification ||
verification.verify_entity !== param.entity ||
verification.verify_token_private !== body.token_private ||
verification.verify_token_private !== body.token_private
) {
throw new BadRequestException('PASSWORD_RESET_FAILED')
}
if (String(query.onlyVerifyToken) === 'true') {
throw new HttpException({ message: 'TOKEN_MATCH', data: new AuthLoginTokenDto({
access_token: '',
device_token: '',
has_password: false,
has_phone: false,
has_email: false,
user_fullname: '',
user_email: '',
user_phone: null,
user_photo: ''
}) }, HttpStatus.OK)
}
if (
!body.password ||
!body.confirm_password ||
body.password !== body.confirm_password
) {
throw new BadRequestException('PASSWORD_RESET_FAILED')
......
......@@ -149,6 +149,12 @@ export class AuthService implements ILocalAuthableService {
if (userWithProvider) {
return userWithProvider
}
if (!config.get('auth.register.admin') && entity === 'admin') {
return null
}
if (!config.get('auth.register.user') && entity === 'user') {
return null
}
const savedUser = await this.findUser(userProvider.email, entity)
if (savedUser) {
......
import { ApiProperty } from "@nestjs/swagger"
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger"
import { IsNotEmpty } from "class-validator"
export class AuthVerificationRequestDto {
......@@ -35,10 +35,13 @@ export class AuthVerificationCheckDto {
export class AuthVerificationPasswordDto extends AuthVerificationCheckDto {
@ApiProperty()
@IsNotEmpty()
password: string
@ApiProperty()
@IsNotEmpty()
confirm_password: string
}
export class AuthVerificationPasswordQueryDto {
@ApiPropertyOptional()
onlyVerifyToken: boolean
}
......@@ -19,6 +19,7 @@ export const knexConf = (env = config.get('env'), name = '', number = 0, options
client: configVal.type || configName.replace('db_', ''),
connection: {
host: configVal.host,
port: configVal.port,
user: configVal.user,
password: configVal.pass,
database: configVal.name
......
import {
AuthVerificationRequestDto as CoreAuthVerificationRequestDto,
AuthVerificationCheckDto as CoreAuthVerificationCheckDto
AuthVerificationCheckDto as CoreAuthVerificationCheckDto,
AuthVerificationPasswordQueryDto as CoreAuthVerificationPasswordQueryDto
} from '@core/auth/dto/authverification.dto'
import { ApiProperty } from '@nestjs/swagger'
import { IsNotEmpty } from 'class-validator'
......@@ -11,10 +12,10 @@ export class AuthVerificationCheckDto extends CoreAuthVerificationCheckDto {}
export class AuthVerificationPasswordDto extends AuthVerificationCheckDto {
@ApiProperty()
@IsNotEmpty()
password: string
@ApiProperty()
@IsNotEmpty()
confirm_password: string
}
export class AuthVerificationPasswordQueryDto extends CoreAuthVerificationPasswordQueryDto {}
......@@ -22,8 +22,9 @@ export class MinioService {
secretKey: config.get('extras.minio.secretKey')
})
this.reloadListBucket()
} else {
Logger.log('Minio Not Configured!', 'Minio')
}
Logger.log('Minio Not Configured!', 'Minio')
}
private loadListBucket() {
......@@ -31,10 +32,12 @@ export class MinioService {
this.minio.listBuckets((err, buckets) => {
if (err) {
Logger.log('Load Bucket List Failed', 'Minio')
console.log(err)
resolve(null)
} else {
Logger.log('Load Bucket List Success', 'Minio')
resolve(buckets)
}
Logger.log('Load Bucket List Success', 'Minio')
resolve(buckets)
})
})
}
......@@ -69,10 +72,11 @@ export class MinioService {
}
async prepareBucket(name: string, publicAccess: boolean = false) {
if (!this.buckets[name]) {
if (!this.buckets || this.buckets && !this.buckets[name]) {
await this.createBucket(name, publicAccess)
} else {
Logger.log(`Bucket "${name}" Available`, 'Minio')
}
Logger.log(`Bucket "${name}" Available`, 'Minio')
}
buildUrl(bucket: string, folder: string, name: string) {
......@@ -80,7 +84,11 @@ export class MinioService {
const domain = config.get('extras.minio.endPoint')
const port = ['80','443',''].includes(String(config.get('extras.minio.port'))) ? '' : config.get('extras.minio.port')
const objectName = join(folder, name)
return `${protocol}${domain}${port}/${bucket}/${objectName}`
let baseUrl = config.get('minio_public_url')
if (isEmpty(baseUrl)) {
baseUrl = `${protocol}${domain}${port}`
}
return `${baseUrl}/${bucket}/${objectName}`
}
async uploadFile(file: any, bucket: string = 'public', folder: string = '') {
......@@ -90,14 +98,16 @@ export class MinioService {
this.minio.fPutObject(bucket, objectName, file.path, {}, (err, res) => {
if (err) {
Logger.log(`Object "${file.originalname}" Failed to Upload`, 'Minio')
console.log(err)
resolve(null)
} else {
Logger.log(`Object "${file.originalname}" Success to Upload: ${res}`, 'Minio')
unlinkSync(file.path)
resolve({
url: this.buildUrl(bucket, folder, name),
res
})
}
Logger.log(`Object "${file.originalname}" Success to Upload: ${res}`, 'Minio')
unlinkSync(file.path)
resolve({
url: this.buildUrl(bucket, folder, name),
res
})
})
})
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment