Skip to content

Commit f77b123

Browse files
authored
Merge pull request #8 from CommitField/feat/#5-fix
feat: ๋„์ปค ์ปดํฌํŠธ mysql ์„ค์ •, ์ข…์†์„ฑ ์ถ”๊ฐ€
2 parents 816d311 + 9624509 commit f77b123

File tree

10 files changed

+136
-31
lines changed

10 files changed

+136
-31
lines changed

โ€Ž.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ override.tf.json
7171

7272
### ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ
7373
docker-compose.yml
74+
docker-compose.yaml
7475

7576
### dbํŒŒ์ผ
7677
db/

โ€Žbuild.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ repositories {
2626
dependencies {
2727
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
2828
implementation("org.springframework.boot:spring-boot-starter-security")
29+
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
2930
implementation("org.springframework.boot:spring-boot-starter-web")
3031
implementation("org.springframework.boot:spring-boot-starter-websocket")
3132
compileOnly("org.projectlombok:lombok")

โ€Žcompose.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
spring:
2+
datasource:
3+
url: jdbc:mysql://localhost:3306/cmf_db
4+
username: root
5+
password: root123414
6+
driver-class-name: com.mysql.cj.jdbc.Driver
7+
jpa:
8+
open-in-view: false
9+
hibernate:
10+
ddl-auto: create
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
security:
3+
oauth2:
4+
client:
5+
registration:
6+
github:
7+
client-id:
8+
client-secret:
9+
scope:
10+
- user:email
11+
- read:user
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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: root123414
17+
driver-class-name: com.mysql.cj.jdbc.Driver
18+
jpa:
19+
open-in-view: false
20+
hibernate:
21+
ddl-auto: update
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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>

0 commit comments

Comments
ย (0)