Pārlūkot izejas kodu

User authentication working but role not being set upon signup

JaseG256 6 gadus atpakaļ
vecāks
revīzija
f67ba31b24

+ 0
- 4
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/DateAudit.java Parādīt failu

@@ -1,4 +0,0 @@
1
-package ZipTeamOrange.model;
2
-
3
-public class DateAudit {
4
-}

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/User.java Parādīt failu

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

+ 0
- 11
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/SignUpRequest.java Parādīt failu

@@ -5,9 +5,6 @@ import javax.validation.constraints.NotBlank;
5 5
 import javax.validation.constraints.Size;
6 6
 
7 7
 public class SignUpRequest {
8
-    @NotBlank
9
-    @Size(min = 4, max = 40)
10
-    private String name;
11 8
 
12 9
     @NotBlank
13 10
     @Size(min = 3, max = 15)
@@ -22,14 +19,6 @@ public class SignUpRequest {
22 19
     @Size(min = 6, max = 20)
23 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 22
     public String getUsername() {
34 23
         return username;
35 24
     }

+ 19
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/config/WebMvcConfig.java Parādīt failu

@@ -0,0 +1,19 @@
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 Parādīt failu

@@ -82,10 +82,10 @@ public class AuthController {
82 82
 
83 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 90
         User result = userRepository.save(user);
91 91
 

+ 2
- 2
ZipTeamOrange-server/src/main/resources/data.sql Parādīt failu

@@ -1,2 +1,2 @@
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');