LoginController.java
1.42 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
package etunicorn;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 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(@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;
}
}