Skip to content

Commit

Permalink
Merge pull request #119 from DevKor-github/feature/auth
Browse files Browse the repository at this point in the history
feat:: 회원가입 시 디스코드 연동
  • Loading branch information
Devheun authored Jan 14, 2025
2 parents a46ad05 + 397d142 commit 483aa7c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
echo "REDIS_HOST=${{ secrets.REDIS_HOST }}" >> .env.test
echo "REDIS_PORT=${{ secrets.REDIS_PORT }}" >> .env.test
echo "REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}" >> .env.test
echo "DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK_URL }}" >> .env.test
cat .env.test
Expand Down Expand Up @@ -112,6 +113,7 @@ jobs:
echo "REDIS_HOST=${{ secrets.REDIS_HOST }}" >> .env.prod
echo "REDIS_PORT=${{ secrets.REDIS_PORT }}" >> .env.prod
echo "REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}" >> .env.prod
echo "DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK_URL }}" >> .env.prod
cat .env.prod
Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"class-validator": "^0.14.1",
"cross-env": "^7.0.3",
"deepl-node": "^1.13.0",
"discord-webhook-node": "^1.1.8",
"express-basic-auth": "^1.2.1",
"multer": "^1.4.5-lts.1",
"multer-s3": "^3.0.1",
Expand Down
16 changes: 16 additions & 0 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ChangePasswordResponseDto } from './dto/change-password-response.dto';
import { SendTempPasswordResponseDto } from './dto/send-temporary-password.dto';
import { EntityManager } from 'typeorm';
import { throwKukeyException } from 'src/utils/exception.util';
import { Webhook } from 'discord-webhook-node';

@Injectable()
export class AuthService {
Expand Down Expand Up @@ -254,6 +255,21 @@ export class AuthService {
user,
);

const discordUrl = await this.configService.get('DISCORD_WEBHOOK_URL');
const hook = new Webhook(discordUrl);
const totalUsers = await this.userService.getTotalUsersCount();

await hook
.send(
'The ' +
totalUsers +
'th user has signed up for KU-KEY! (' +
studentNumber +
')',
)
.then(() => console.log('Sent new user request to discord'))
.catch((err) => console.log(err.message));

return new SignUpResponseDto(true, studentNumber);
}

Expand Down
4 changes: 4 additions & 0 deletions src/user/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ export class UserRepository extends Repository<UserEntity> {

return updateResult.affected ? true : false;
}

async getTotalUsersCount(): Promise<number> {
return await this.count();
}
}
4 changes: 4 additions & 0 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,8 @@ export class UserService {

return new SelectCharacterLevelResponseDto(selectedLevel);
}

async getTotalUsersCount(): Promise<number> {
return await this.userRepository.getTotalUsersCount();
}
}

0 comments on commit 483aa7c

Please sign in to comment.