-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #393 from aXenDeveloper/improve_auth
refactor(backend): Authorization middleware for AdminCP
- Loading branch information
Showing
26 changed files
with
274 additions
and
123 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
packages/backend/src/core/members/sign_up/functions/generate-avatar-color.ts
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
packages/backend/src/core/members/sign_up/sign_up.resolver.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/backend/src/core/sessions/sign_up/helpers/avatar-color.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { convertColor } from 'vitnode-shared'; | ||
|
||
@Injectable() | ||
export class AvatarColorService { | ||
private readonly hRange = [0, 360]; | ||
private readonly sRange = [50, 75]; | ||
private readonly lRange = [25, 60]; | ||
|
||
private readonly getHashOfString = (str: string) => { | ||
let hash = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
hash = str.charCodeAt(i) + ((hash << 5) - hash); | ||
} | ||
hash = Math.abs(hash); | ||
|
||
return hash; | ||
}; | ||
|
||
private readonly normalizeHash = (hash: number, min: number, max: number) => { | ||
return Math.floor((hash % (max - min)) + min); | ||
}; | ||
|
||
private readonly generateHSLFromName = (name: string) => { | ||
const hash = this.getHashOfString(name); | ||
const h = this.normalizeHash(hash, this.hRange[0], this.hRange[1]); | ||
const s = this.normalizeHash(hash, this.sRange[0], this.sRange[1]); | ||
const l = this.normalizeHash(hash, this.lRange[0], this.lRange[1]); | ||
|
||
return [h, s, l]; | ||
}; | ||
|
||
generateAvatarColor = (name: string) => { | ||
const hslName = this.generateHSLFromName(name); | ||
|
||
return convertColor.hslToRgb(hslName[0], hslName[1], hslName[2]); | ||
}; | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/backend/src/core/sessions/sign_up/sign_up.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Args, Context, Mutation, Resolver } from '@nestjs/graphql'; | ||
|
||
import { SignUpCoreSessionsObj } from './dto/sign_up.obj'; | ||
import { SignUpCoreSessionsService } from './sign_up.service'; | ||
import { SignUpCoreSessionsArgs } from './dto/sign_up.args'; | ||
|
||
import { Ctx } from '../../../utils'; | ||
|
||
@Resolver() | ||
export class SignUpCoreSessionsResolver { | ||
constructor(private readonly service: SignUpCoreSessionsService) {} | ||
|
||
@Mutation(() => SignUpCoreSessionsObj) | ||
async core_sessions__sign_up( | ||
@Args() args: SignUpCoreSessionsArgs, | ||
@Context() ctx: Ctx, | ||
): Promise<SignUpCoreSessionsObj> { | ||
return this.service.signUp(args, ctx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.