Blame view

src/main/java/etunicorn/LoginController.java 1.46 KB
bae3c9f4   Geoffrey PREUD'HOMME   /login pour debug
1
2
  package etunicorn;
  
6ae819f3   badetitou   Go to JSON
3
  import net.minidev.json.JSONObject;
bae3c9f4   Geoffrey PREUD'HOMME   /login pour debug
4
5
6
7
8
9
10
  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;
  
bae3c9f4   Geoffrey PREUD'HOMME   /login pour debug
11
  /**
3064f583   Geoffrey PREUD'HOMME   Copyright
12
13
14
   * etunicorn-server
   * Copyright © 2017 Le Club Info Polytech Lille
   * Tous droits réservés
bae3c9f4   Geoffrey PREUD'HOMME   /login pour debug
15
16
17
18
   */
  @RestController
  public class LoginController implements etunicorn.generated.LoginController {
      @Autowired
8f35fffd   Geoffrey PREUD'HOMME   Ajout de la sécurité
19
20
21
22
      private PersonneRepository personneRepository;
  
      @Autowired
      private SessionService sessionService;
bae3c9f4   Geoffrey PREUD'HOMME   /login pour debug
23
24
  
      @Override
8f35fffd   Geoffrey PREUD'HOMME   Ajout de la sécurité
25
      @RestrictedTo(authentifie = false)
bae3c9f4   Geoffrey PREUD'HOMME   /login pour debug
26
      public ResponseEntity<?> updateLogin(@RequestParam String login, @RequestParam String password) {
8f35fffd   Geoffrey PREUD'HOMME   Ajout de la sécurité
27
28
29
          Personne personne = personneRepository.findByLogin(login);
          if (personne == null) {
              return new ResponseEntity<Object>(HttpStatus.UNAUTHORIZED);
bae3c9f4   Geoffrey PREUD'HOMME   /login pour debug
30
          }
8f35fffd   Geoffrey PREUD'HOMME   Ajout de la sécurité
31
32
33
34
35
36
37
38
39
  
          // 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);
bae3c9f4   Geoffrey PREUD'HOMME   /login pour debug
40
41
42
43
44
45
46
      }
  
      @Override
      public ResponseEntity<?> deleteLoginByToken(@PathVariable String token) {
          return null;
      }
  }