Commit bae3c9f44e4a0762bfbc116a6672ffe77032163c

Authored by Geoffrey PREUD'HOMME
1 parent 5e2f0025

/login pour debug

.gitignore
... ... @@ -7,3 +7,4 @@
7 7 target/
8 8 demo*/
9 9 .idea/dictionaries/
  10 +etunicorn.db
... ...
api.raml
... ... @@ -40,7 +40,7 @@ securitySchemes:
40 40 password:
41 41 displayName: Mot de passe Polytech
42 42 type: string
43   - required: false
  43 + required: true
44 44 responses:
45 45 200:
46 46 description: Authentification réussie
... ...
src/main/java/etunicorn/Application.java
... ... @@ -4,14 +4,10 @@ import org.springframework.boot.CommandLineRunner;
4 4 import org.springframework.boot.SpringApplication;
5 5 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
6 6 import org.springframework.boot.autoconfigure.SpringBootApplication;
7   -<<<<<<< HEAD
8   -import org.springframework.context.annotation.Bean;
9   -=======
10 7 import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
11 8 import org.springframework.context.annotation.Bean;
12 9  
13 10 import javax.sql.DataSource;
14   ->>>>>>> 8cbe108cd842b37e3fe6c969ad942e5651d557b3
15 11  
16 12 /**
17 13 * Created by geoffrey on 28/01/17.
... ... @@ -34,6 +30,7 @@ public class Application {
34 30 };
35 31 }
36 32  
  33 + @Bean
37 34 public DataSource dataSource(){
38 35 DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
39 36 dataSourceBuilder.driverClassName("org.sqlite.JDBC");
... ...
src/main/java/etunicorn/LoginController.java 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +package etunicorn;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.http.HttpStatus;
  5 +import org.springframework.http.ResponseEntity;
  6 +import org.springframework.web.bind.annotation.PathVariable;
  7 +import org.springframework.web.bind.annotation.RequestParam;
  8 +import org.springframework.web.bind.annotation.RestController;
  9 +
  10 +import java.util.Date;
  11 +
  12 +/**
  13 + * Created by geoffrey on 04/02/17.
  14 + */
  15 +@RestController
  16 +public class LoginController implements etunicorn.generated.LoginController {
  17 + @Autowired
  18 + private PermissionRepository permissionRepository;
  19 +
  20 + @Override
  21 + public ResponseEntity<?> updateLogin(@RequestParam String login, @RequestParam String password) {
  22 + // TODO C'est du debug !
  23 + Role role = new Role();
  24 + role.setNom("superman");
  25 + for (Permission permission : permissionRepository.findAll()) {
  26 + role.addPermission(permission);
  27 + }
  28 + Personne personne = new Personne();
  29 + personne.setLogin("gbontoux");
  30 + personne.setCarte("39cdd9ed0b191d");
  31 + personne.setNaissance(new Date("14-Feb-1997"));
  32 + personne.setRole(role);
  33 + return new ResponseEntity<Object>(personne, HttpStatus.OK);
  34 + }
  35 +
  36 + @Override
  37 + public ResponseEntity<?> deleteLoginByToken(@PathVariable String token) {
  38 + return null;
  39 + }
  40 +}
... ...
src/main/java/etunicorn/Role.java
... ... @@ -4,6 +4,7 @@ import javax.persistence.Column;
4 4 import javax.persistence.Entity;
5 5 import javax.persistence.Id;
6 6 import javax.persistence.OneToMany;
  7 +import java.util.ArrayList;
7 8 import java.util.Collection;
8 9 import java.util.List;
9 10  
... ... @@ -17,7 +18,7 @@ public class Role {
17 18 private String nom = "etudiant";
18 19  
19 20 @OneToMany
20   - private List<Permission> permissions;
  21 + private List<Permission> permissions = new ArrayList<>();
21 22  
22 23 public Role() {
23 24 }
... ...
src/main/java/etunicorn/Session.java deleted
... ... @@ -1,60 +0,0 @@
1   -package etunicorn;
2   -
3   -import javax.persistence.Entity;
4   -import javax.persistence.Id;
5   -import javax.persistence.ManyToOne;
6   -import java.math.BigInteger;
7   -import java.security.SecureRandom;
8   -import java.util.Date;
9   -
10   -/**
11   - * Created by geoffrey on 04/02/17.
12   - */
13   -@Entity
14   -public class Session {
15   -
16   - // Durée par défaut d'une session en secondes
17   - private static final int SESSION_DURATION = 10 * 60;
18   - private static SecureRandom random = new SecureRandom();
19   - @ManyToOne
20   - private Personne personne;
21   - @Id
22   - private String token;
23   - // TODO Vérifier si c'est bien initialisé qu'une seule fois par éxecution car c'est lourd à initialiser
24   - private Date validity;
25   -
26   -
27   - public Session() {
28   - }
29   -
30   - public Session(Personne personne) {
31   - this.personne = personne;
32   - // From http://stackoverflow.com/a/41156
33   - this.token = new BigInteger(130, random).toString(32);
34   - this.validity = new Date(new Date().getTime() + SESSION_DURATION * 1000);
35   - }
36   -
37   - public Personne getPersonne() {
38   - return personne;
39   - }
40   -
41   - public void setPersonne(Personne personne) {
42   - this.personne = personne;
43   - }
44   -
45   - public String getToken() {
46   - return token;
47   - }
48   -
49   - public void setToken(String token) {
50   - this.token = token;
51   - }
52   -
53   - public Date getValidity() {
54   - return validity;
55   - }
56   -
57   - public void setValidity(Date validity) {
58   - this.validity = validity;
59   - }
60   -}
src/main/java/etunicorn/SessionRepository.java deleted
... ... @@ -1,10 +0,0 @@
1   -package etunicorn;
2   -
3   -import org.springframework.data.repository.CrudRepository;
4   -
5   -/**
6   - * Created by geoffrey on 04/02/17.
7   - */
8   -public interface SessionRepository extends CrudRepository<Session, Long> {
9   - Session findByToken(String token);
10   -}