Browse Source

User authentication working but role not being set upon signup

JaseG256 6 years ago
parent
commit
f67ba31b24

+ 0
- 4
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/DateAudit.java View File

1
-package ZipTeamOrange.model;
2
-
3
-public class DateAudit {
4
-}

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/User.java View File

18
                 "email"
18
                 "email"
19
         })
19
         })
20
 })
20
 })
21
-public class User extends DateAudit{
21
+public class User {
22
 
22
 
23
     @Id
23
     @Id
24
     @GeneratedValue(strategy = GenerationType.IDENTITY)
24
     @GeneratedValue(strategy = GenerationType.IDENTITY)

+ 0
- 11
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/SignUpRequest.java View File

5
 import javax.validation.constraints.Size;
5
 import javax.validation.constraints.Size;
6
 
6
 
7
 public class SignUpRequest {
7
 public class SignUpRequest {
8
-    @NotBlank
9
-    @Size(min = 4, max = 40)
10
-    private String name;
11
 
8
 
12
     @NotBlank
9
     @NotBlank
13
     @Size(min = 3, max = 15)
10
     @Size(min = 3, max = 15)
22
     @Size(min = 6, max = 20)
19
     @Size(min = 6, max = 20)
23
     private String password;
20
     private String password;
24
 
21
 
25
-    public String getName() {
26
-        return name;
27
-    }
28
-
29
-    public void setName(String name) {
30
-        this.name = name;
31
-    }
32
-
33
     public String getUsername() {
22
     public String getUsername() {
34
         return username;
23
         return username;
35
     }
24
     }

+ 19
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/config/WebMvcConfig.java View File

1
+package ZipTeamOrange.config;
2
+
3
+import org.springframework.context.annotation.Configuration;
4
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
5
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
+
7
+@Configuration
8
+public class WebMvcConfig implements WebMvcConfigurer {
9
+
10
+    private final long MAX_AGE_SECS = 3600;
11
+
12
+    @Override
13
+    public void addCorsMappings(CorsRegistry registry) {
14
+        registry.addMapping("/**")
15
+                .allowedOrigins("*")
16
+                .allowedMethods("HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE")
17
+                .maxAge(MAX_AGE_SECS);
18
+    }
19
+}

+ 4
- 4
ZipTeamOrange-server/src/main/java/ZipTeamOrange/controller/AuthController.java View File

82
 
82
 
83
         user.setPassword(passwordEncoder.encode(user.getPassword()));
83
         user.setPassword(passwordEncoder.encode(user.getPassword()));
84
 
84
 
85
-        Role userRole = roleRepository.findByName(RoleName.ROLE_USER)
86
-                .orElseThrow(() -> new AppException("User Role not set."));
87
-
88
-        user.setRoles(Collections.singleton(userRole));
85
+//        Role userRole = roleRepository.findByName(RoleName.ROLE_USER)
86
+//                .orElseThrow(() -> new AppException("User Role not set."));
87
+//
88
+//        user.setRoles(Collections.singleton(userRole));
89
 
89
 
90
         User result = userRepository.save(user);
90
         User result = userRepository.save(user);
91
 
91
 

+ 2
- 2
ZipTeamOrange-server/src/main/resources/data.sql View File

1
-insert into roles(name) values ('Role_Admin');
2
-insert into roles(name) values ('Role_User');
1
+insert into roles(name) values ('ROLE_ADMIN');
2
+insert into roles(name) values ('ROLE_USER');