diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index 8a0722d..e43f0a1 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -9,7 +9,7 @@ import ovh.herisson.Clyde.Services.AuthenticatorService; import java.util.Date; @RestController -@CrossOrigin(origins = "http://localhost:5173") +@CrossOrigin(originPatterns = "*", allowCredentials = "true") public class LoginController { private final AuthenticatorService authServ; diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 79e482d..b140057 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -52,10 +52,6 @@ public class MockController { mockUsers = new ArrayList(Arrays.asList(herobrine,joe,meh,joke)); userRepo.saveAll(mockUsers); - - for (User user: mockUsers){ - tokenService.saveToken(new Token(user,user.getPassword(), new Date())); - } } @DeleteMapping("/mock") diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/TokenController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/TokenController.java new file mode 100644 index 0000000..793e61b --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/TokenController.java @@ -0,0 +1,26 @@ +package ovh.herisson.Clyde.EndPoints; + + + +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import ovh.herisson.Clyde.Services.TokenService; +import ovh.herisson.Clyde.Tables.Token; + +@RestController +@CrossOrigin(origins = "http://localhost:5173") +public class TokenController { + + private final TokenService tokenServ; + + public TokenController(TokenService tokenServ){ + this.tokenServ = tokenServ; + } + + + @GetMapping("/tokens") + public Iterable getTokens(){ + return tokenServ.getAllTokens(); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java index ba54926..8de166e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -23,18 +23,18 @@ public class UserController { } @GetMapping("/user") - public ResponseEntity getUser(@RequestHeader("Authorization") String token){ - User user = authServ.getUserFromToken(token); - if (user == null) { - return new UnauthorizedResponse<>(null); - } + public ResponseEntity getUser(@RequestHeader("Cookie") String authorization){ + + if (authorization == null) return new UnauthorizedResponse<>(null); + User user = authServ.getUserFromToken(authorization); + if (user == null) return new UnauthorizedResponse<>(null); return new ResponseEntity<>(user, HttpStatus.OK); } @PostMapping("/user") public ResponseEntity postUser(@RequestBody User user){ userService.save(user); - return new ResponseEntity(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED); + return new ResponseEntity<>(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED); } @GetMapping("/users") diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java index 6e73d34..50ddcbf 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java @@ -20,12 +20,19 @@ public class TokenService { this.tokenRepo = tokenRepo; } + public Iterable getAllTokens() { + return tokenRepo.findAll(); + } + public String generateNewToken(){ byte[] bytes = new byte[64]; new SecureRandom().nextBytes(bytes); for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) (((bytes[i]+256)%256 %95+ 32)); + while ((char)bytes[i] == ';'){ + bytes[i] = new SecureRandom().generateSeed(1)[0]; + } } // will never end up in the catch because of the way that SecureRandom.nextBytes is implemented try { @@ -35,8 +42,10 @@ public class TokenService { } } - public User getUserFromToken(String token){ - return tokenRepo.getByToken(token).getUser(); + public User getUserFromToken(String token) { + Token tokenRep = tokenRepo.getByToken(token); + if (tokenRep == null) return null; + return tokenRep.getUser(); } public void saveToken(Token token){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java index 00d7ea0..8aa4c0e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Token.java @@ -12,7 +12,7 @@ public class Token { @Id private int id; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name ="Users") private User user; private String token; diff --git a/frontend/src/components/HelloWorld.vue b/frontend/src/components/HelloWorld.vue deleted file mode 100644 index 5fb372c..0000000 --- a/frontend/src/components/HelloWorld.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - - - diff --git a/frontend/src/components/TheWelcome.vue b/frontend/src/components/TheWelcome.vue deleted file mode 100644 index dab9536..0000000 --- a/frontend/src/components/TheWelcome.vue +++ /dev/null @@ -1,88 +0,0 @@ - - - diff --git a/frontend/src/components/WelcomeItem.vue b/frontend/src/components/WelcomeItem.vue deleted file mode 100644 index 6d7086a..0000000 --- a/frontend/src/components/WelcomeItem.vue +++ /dev/null @@ -1,87 +0,0 @@ - - - diff --git a/frontend/src/components/__tests__/HelloWorld.spec.js b/frontend/src/components/__tests__/HelloWorld.spec.js deleted file mode 100644 index 2533202..0000000 --- a/frontend/src/components/__tests__/HelloWorld.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -import { describe, it, expect } from 'vitest' - -import { mount } from '@vue/test-utils' -import HelloWorld from '../HelloWorld.vue' - -describe('HelloWorld', () => { - it('renders properly', () => { - const wrapper = mount(HelloWorld, { props: { msg: 'Hello Vitest' } }) - expect(wrapper.text()).toContain('Hello Vitest') - }) -}) diff --git a/frontend/src/components/icons/IconCommunity.vue b/frontend/src/components/icons/IconCommunity.vue deleted file mode 100644 index 2dc8b05..0000000 --- a/frontend/src/components/icons/IconCommunity.vue +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/frontend/src/components/icons/IconDocumentation.vue b/frontend/src/components/icons/IconDocumentation.vue deleted file mode 100644 index 6d4791c..0000000 --- a/frontend/src/components/icons/IconDocumentation.vue +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/frontend/src/components/icons/IconEcosystem.vue b/frontend/src/components/icons/IconEcosystem.vue deleted file mode 100644 index c3a4f07..0000000 --- a/frontend/src/components/icons/IconEcosystem.vue +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/frontend/src/components/icons/IconSupport.vue b/frontend/src/components/icons/IconSupport.vue deleted file mode 100644 index 7452834..0000000 --- a/frontend/src/components/icons/IconSupport.vue +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/frontend/src/components/icons/IconTooling.vue b/frontend/src/components/icons/IconTooling.vue deleted file mode 100644 index 660598d..0000000 --- a/frontend/src/components/icons/IconTooling.vue +++ /dev/null @@ -1,19 +0,0 @@ - - diff --git a/frontend/src/i18n.js b/frontend/src/i18n.js index d8909f1..8c39fb4 100644 --- a/frontend/src/i18n.js +++ b/frontend/src/i18n.js @@ -10,9 +10,10 @@ */ import { getCookie, setCookie } from './utils.js'; +import { reactive } from 'vue'; const default_lang = "EN"; -let langs; +const langs = reactive({}); /** @@ -27,8 +28,8 @@ let langs; export default function i18n(key, options) { let ret = langs[key]; if(options != null){ - for (let key in options) { - ret = ret.replaceAll("$" + key, options[key]); + for (let option in options) { + ret = ret.replaceAll("$" + option, options[option]); } } return ret; @@ -47,14 +48,12 @@ export async function loadLangs(lang){ const content = await (await fetch(filename)).text(); const lines = content.split("\n"); - let filteredLines = {}; for (let line of lines) { if(!line.trim().startsWith("#") && line.trim() != ""){ let split = line.indexOf("=") - filteredLines[line.substr(0, split)] = line.substr(split+1, line.length); + langs[line.substr(0, split)] = line.substr(split+1, line.length); }; } - langs = filteredLines; } await loadLangs(); diff --git a/frontend/src/rest/Users.js b/frontend/src/rest/Users.js index e34d611..cca662d 100644 --- a/frontend/src/rest/Users.js +++ b/frontend/src/rest/Users.js @@ -1,7 +1,7 @@ import { restGet, restPost } from './restConsumer.js' export async function login(user, pass, exp){ - return restPost("/login", {login: user, password: pass, expiration: exp}); + return restPost("/login", {identifier: user, password: pass, expirationDate: exp}); } export async function register(user, pass, mail){ diff --git a/frontend/src/rest/restConsumer.js b/frontend/src/rest/restConsumer.js index 25729bd..b2d1546 100644 --- a/frontend/src/rest/restConsumer.js +++ b/frontend/src/rest/restConsumer.js @@ -8,15 +8,15 @@ export async function restGet(endPoint) { } export async function restPost(endPoint, data) { - return await _rest(endPoint, {method: "POST", body: data}); + return await _rest(endPoint, {method: "POST", credentials: 'include', body: JSON.stringify(data)}); } export async function restDelete(endPoint, data) { - return await _rest(endPoint, {method: "DELETE", body: data}); + return await _rest(endPoint, {method: "DELETE", credentials: 'include', body: JSON.stringify(data)}); } export async function restPatch(endPoint, data) { - return await _rest(endPoint, {method: "PATCH", body: data}); + return await _rest(endPoint, {method: "PATCH", credentials: 'include', body: JSON.stringify(data)}); } /** @@ -31,7 +31,10 @@ export async function restPatch(endPoint, data) { async function _rest(endPoint, config){ endPoint.at(0) != "/" ? console.error("Carefull, you certainly should put a / at the begenning of your endPoint ") : true; let session_token = getCookie("session_token"); - let headers = new Headers({'Authorization': session_token}); + let headers = new Headers({ + 'Authorization': session_token, + 'Content-Type': 'application/json', + }); config['headers'] = headers; return toast.promise(fetch(restURL + endPoint, config), {