Skip to content

Commit

Permalink
Merge pull request #1402 from innovationacademy-kr/challenge
Browse files Browse the repository at this point in the history
Challenge to DEV!
  • Loading branch information
seong-hui authored Oct 27, 2023
2 parents df882cb + 93a49bf commit 4514790
Show file tree
Hide file tree
Showing 113 changed files with 5,028 additions and 1,651 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

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

1 change: 1 addition & 0 deletions backend/database/cabi_local.sql
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ CREATE TABLE `user` (
`email` varchar(255) DEFAULT NULL,
`name` varchar(32) NOT NULL,
`role` varchar(32) NOT NULL,
`is_extensible` tinyint(1) DEFAULT 0 NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `UK_gj2fy3dcix7ph7k8684gka40c` (`name`),
UNIQUE KEY `UK_ob8kqyqqgmefl0aco34akdtpe` (`email`)
Expand Down
12 changes: 9 additions & 3 deletions backend/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

services:
mariadb:
Expand All @@ -12,13 +12,19 @@ services:
MARIADB_PASSWORD: YourPassword
MARIADB_ROOT_PASSWORD: YourPassword
ports:
- '3307:3306'
- "3307:3306"
tty: true
# redis:
# container_name: redis
# image: redis:latest
# ports:
# - '6379:6379'
# tty: true
gateway:
container_name: nginx_gateway
image: nginx:latest
ports:
- '80:80'
- "80:80"
volumes:
- ../dev/:/etc/nginx/conf.d/
redis:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package org.ftclub.cabinet.auth.controller;

import java.io.IOException;
import java.time.LocalDateTime;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.auth.domain.CookieManager;
import org.ftclub.cabinet.auth.domain.TokenProvider;
import org.ftclub.cabinet.auth.service.AuthFacadeService;
import org.ftclub.cabinet.auth.service.AuthService;
import org.ftclub.cabinet.config.DomainProperties;
import org.ftclub.cabinet.config.FtApiProperties;
import org.ftclub.cabinet.user.repository.UserRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/v4/auth")
@RequiredArgsConstructor
Expand All @@ -23,6 +26,11 @@ public class AuthController {
private final DomainProperties DomainProperties;
private final FtApiProperties ftApiProperties;

private final AuthService authService;
private final TokenProvider tokenProvider;
private final CookieManager cookieManager;
private final UserRepository userRepository;

/**
* 42 API 로그인 페이지로 리다이렉트합니다.
*
Expand Down Expand Up @@ -52,7 +60,7 @@ public void login(HttpServletResponse response) throws IOException {
*/
@GetMapping("/login/callback")
public void loginCallback(@RequestParam String code, HttpServletRequest req,
HttpServletResponse res) throws IOException {
HttpServletResponse res) throws IOException {
authFacadeService.handleLogin(code, req, res, ftApiProperties, LocalDateTime.now());
res.sendRedirect(DomainProperties.getFeHost() + "/home");
}
Expand All @@ -66,4 +74,21 @@ public void loginCallback(@RequestParam String code, HttpServletRequest req,
public void logout(HttpServletResponse res) {
authFacadeService.logout(res, ftApiProperties);
}

@GetMapping("/challenge")
public void challengeLogin(HttpServletRequest req, HttpServletResponse res) throws IOException {
// 유저 랜덤생성 && 유저 역할은 일반 유저
// 토큰 생성 및 response에 쿠키만들어서 심어주기
authFacadeService.handleTestLogin(req, ftApiProperties, res, LocalDateTime.now());
System.out.println("??????????????here??????????????????/");
res.sendRedirect(DomainProperties.getFeHost() + "/home");
// Map<String, Object> claims = tokenProvider
// String accessToken = tokenProvider.createTokenForTestUser(testUser, LocalDateTime.now());
// Cookie cookie = cookieManager.cookieOf("access_token",
// accessToken);
// cookieManager.setCookieToClient(res, cookie, "/", req.getServerName());
// System.out.println("?????????????????????? cookie domain = ");
// res.sendRedirect(DomainProperties.getLocal() + "/main");
// res.sendRedirect(DomainProperties.getFeHost() + "/home");
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.ftclub.cabinet.auth.domain;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.config.DomainProperties;
import org.ftclub.cabinet.config.JwtProperties;
import org.springframework.stereotype.Component;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* 클라이언트의 쿠키를 관리하는 클래스입니다.
*/
Expand Down Expand Up @@ -48,14 +47,15 @@ public String getCookieValue(HttpServletRequest req, String name) {
* @param serverName 쿠키 도메인
*/
public void setCookieToClient(HttpServletResponse res, Cookie cookie, String path,
String serverName) {
String serverName) {
cookie.setMaxAge(60 * 60 * 24 * jwtProperties.getExpiryDays());
cookie.setPath(path);
if (serverName.equals(domainProperties.getLocal())) {
cookie.setDomain(domainProperties.getLocal());
} else {
cookie.setDomain(domainProperties.getCookieDomain());
}
System.out.println("?????????????????????? cookie domain = " + cookie.getDomain());
res.addCookie(cookie);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package org.ftclub.cabinet.auth.domain;

import static org.ftclub.cabinet.exception.ExceptionStatus.INVALID_ARGUMENT;
import static org.ftclub.cabinet.exception.ExceptionStatus.UNAUTHORIZED_USER;

import com.fasterxml.jackson.databind.JsonNode;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.config.FtApiProperties;
import org.ftclub.cabinet.config.GoogleApiProperties;
Expand All @@ -13,14 +20,6 @@
import org.ftclub.cabinet.user.domain.UserRole;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import static org.ftclub.cabinet.exception.ExceptionStatus.INVALID_ARGUMENT;
import static org.ftclub.cabinet.exception.ExceptionStatus.UNAUTHORIZED_USER;

/**
* API 제공자에 따라 JWT 토큰을 생성하는 클래스입니다.
*/
Expand Down
Loading

0 comments on commit 4514790

Please sign in to comment.