File tree Expand file tree Collapse file tree 9 files changed +152
-31
lines changed
java/cmf/commitField/domain/user Expand file tree Collapse file tree 9 files changed +152
-31
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ repositories {
26
26
dependencies {
27
27
implementation(" org.springframework.boot:spring-boot-starter-data-jpa" )
28
28
implementation(" org.springframework.boot:spring-boot-starter-security" )
29
+ implementation(" org.springframework.boot:spring-boot-starter-oauth2-client" )
29
30
implementation(" org.springframework.boot:spring-boot-starter-web" )
30
31
implementation(" org.springframework.boot:spring-boot-starter-websocket" )
31
32
compileOnly(" org.projectlombok:lombok" )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ name : commitfield
2
+ services :
3
+ mysql :
4
+ image : mysql:9.2.0
5
+ container_name : mysql-cmf
6
+ environment :
7
+ MYSQL_ROOT_PASSWORD : cmfgogo!!1236
8
+ MYSQL_DATABASE : cmf_db
9
+ ports :
10
+ - " 3306:3306"
11
+ volumes :
12
+ - ./db/:/var/lib/mysql
13
+
14
+ # mongodb:
15
+ # image: mongo
16
+ # restart: always
17
+ # container_name: mongodb
18
+ # # 접근 포트 설정 (컨테이너 외부:컨테이너 내부)
19
+ # ports:
20
+ # - "27017:27017"
21
+ # # 환경 변수 설정
22
+ # environment:
23
+ # # MongoDB 계정 및 패스워드 설정 옵션
24
+ # MONGO_INITDB_ROOT_USERNAME:
25
+ # MONGO_INITDB_ROOT_PASSWORD:
26
+ # # 볼륨 설정
27
+ # volumes:
28
+ # - ./data/mongodb:/data/db
Original file line number Diff line number Diff line change
1
+ package cmf .commitField .domain .user .controller ;
2
+
3
+ import org .springframework .security .core .annotation .AuthenticationPrincipal ;
4
+ import org .springframework .security .oauth2 .core .user .OAuth2User ;
5
+ import org .springframework .web .bind .annotation .GetMapping ;
6
+ import org .springframework .web .bind .annotation .RestController ;
7
+
8
+ import java .util .Map ;
9
+
10
+ @ RestController
11
+ public class AuthController {
12
+ @ GetMapping ("/user" )
13
+ public Map <String , Object > user (@ AuthenticationPrincipal OAuth2User principal ) {
14
+ return principal .getAttributes (); // 사용자 정보 반환
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ package cmf .commitField .domain .user .controller ;
2
+
3
+ import jakarta .servlet .http .HttpServletRequest ;
4
+ import jakarta .servlet .http .HttpServletResponse ;
5
+ import org .springframework .stereotype .Controller ;
6
+ import org .springframework .web .bind .annotation .GetMapping ;
7
+
8
+ import java .io .IOException ;
9
+
10
+ @ Controller
11
+ public class LogoutController {
12
+
13
+ @ GetMapping ("/logout" )
14
+ public void logout (HttpServletRequest request , HttpServletResponse response ) throws IOException {
15
+ request .getSession ().invalidate ();
16
+ response .sendRedirect ("/" );
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ package cmf .commitField .domain .user .entity ;
2
+
3
+ import cmf .commitField .global .jpa .BaseEntity ;
4
+ import jakarta .persistence .Entity ;
5
+ import jakarta .persistence .Id ;
6
+ import lombok .Builder ;
7
+
8
+ @ Entity
9
+ @ Builder
10
+ public class User extends BaseEntity {
11
+ @ Id
12
+ private long id ;
13
+ private String email ;
14
+ private String nickname ;
15
+ private String password ;
16
+ }
Original file line number Diff line number Diff line change
1
+ spring :
2
+ datasource :
3
+ url : jdbc:mysql://localhost:3306/cmf_db
4
+ username : root
5
+ password : cmfgogo!!1236
6
+ driver-class-name : com.mysql.cj.jdbc.Driver
7
+ jpa :
8
+ open-in-view : false
9
+ hibernate :
10
+ ddl-auto : create
Original file line number Diff line number Diff line change 1
- # server:
2
- # port: 8090
3
- # timezone: Asia/Seoul
4
- # spring:
5
- # config:
6
- # import: application-secret.yml
7
- # output:
8
- # ansi:
9
- # enabled: ALWAYS
10
- # profiles:
11
- # active: dev
12
- # include: secret
13
- # datasource:
14
- # url: jdbc:mysql://localhost:3306/cmf_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Seoul
15
- # username: root
16
- # password: cmfgogo!!1236
17
- # driver-class-name: com.mysql.cj.jdbc.Driver
18
- # jpa:
19
- # open-in-view: false
20
- # hibernate:
21
- # ddl-auto: update
1
+ server :
2
+ port : 8090
3
+ timezone : Asia/Seoul
4
+ spring :
5
+ config :
6
+ import : application-secret.yml
7
+ output :
8
+ ansi :
9
+ enabled : ALWAYS
10
+ profiles :
11
+ active : dev
12
+ include : secret
13
+ datasource :
14
+ url : jdbc:mysql://localhost:3306/cmf_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Seoul
15
+ username : root
16
+ password : cmfgogo!!1236
17
+ driver-class-name : com.mysql.cj.jdbc.Driver
18
+ jpa :
19
+ open-in-view : false
20
+ hibernate :
21
+ ddl-auto : update
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="ko ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > GitHub OAuth2 로그인 테스트</ title >
7
+ </ head >
8
+ < body >
9
+ < h1 > GitHub OAuth2 로그인 테스트</ h1 >
10
+
11
+ < a href ="/oauth2/authorization/github ">
12
+ < button > GitHub 로그인</ button >
13
+ </ a >
14
+
15
+ < button id ="logoutBtn " style ="display: none; "> 로그아웃</ button >
16
+
17
+ < h2 > 사용자 정보</ h2 >
18
+ < pre id ="userInfo "> 로그인 후 정보를 불러옵니다...</ pre >
19
+
20
+ < script >
21
+ async function fetchUser ( ) {
22
+ try {
23
+ const response = await fetch ( '/user' ) ;
24
+ if ( ! response . ok ) throw new Error ( "Not logged in" ) ;
25
+
26
+ const data = await response . json ( ) ;
27
+ document . getElementById ( "userInfo" ) . textContent = JSON . stringify ( data , null , 2 ) ;
28
+ document . getElementById ( "logoutBtn" ) . style . display = "block" ;
29
+ } catch ( error ) {
30
+ document . getElementById ( "userInfo" ) . textContent = "로그인이 필요합니다." ;
31
+ }
32
+ }
33
+
34
+ document . getElementById ( "logoutBtn" ) . addEventListener ( "click" , async ( ) => {
35
+ await fetch ( '/logout' , { method : 'GET' } ) ;
36
+ location . reload ( ) ;
37
+ } ) ;
38
+
39
+ fetchUser ( ) ;
40
+ </ script >
41
+ </ body >
42
+ </ html >
You can’t perform that action at this time.
0 commit comments