LoginController.java
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package etunicorn.controller;
import etunicorn.RestrictedTo;
import etunicorn.entity.Personne;
import etunicorn.entity.Session;
import etunicorn.generated.model.UpdateLoginRequest;
import etunicorn.repository.PersonneRepository;
import etunicorn.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
/**
* etunicorn-server
* Copyright © 2017 Le Club Info Polytech Lille
* Tous droits réservés
*/
@RestController
public class LoginController implements etunicorn.generated.LoginController {
@Autowired
private PersonneRepository personneRepository;
@Autowired
private SessionService sessionService;
@Override
@RestrictedTo(authentifie = false)
public ResponseEntity<?> updateLogin(@Valid @RequestBody UpdateLoginRequest updateLoginRequest) {
return null;
}
public ResponseEntity<?> updateLogin(@RequestParam String login, @RequestParam String password) {
Personne personne = personneRepository.findByLogin(login);
if (personne == null) {
return new ResponseEntity<Object>(HttpStatus.UNAUTHORIZED);
}
// TODO Vraie vérification du mot de passe
if (!password.equals("test")) {
return new ResponseEntity<Object>(HttpStatus.UNAUTHORIZED);
}
Session session = sessionService.createSession(personne);
return new ResponseEntity<Object>(session, HttpStatus.OK);
}
@Override
public ResponseEntity<?> deleteLoginByToken(@PathVariable String token) {
return null;
}
}