Skip to content

Commit 6d1c840

Browse files
committed
Registro usuario funciona (fix backend + servicio user)
1 parent 7735ca8 commit 6d1c840

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

backend/gamelink/src/main/java/urjc/gamelink/Configuration/Security/RestSecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected void configure(HttpSecurity http) throws Exception {
4949
http.antMatcher("/api/**");
5050

5151
// URLs that need authentication to access to it
52-
http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/users/").hasAnyRole("ADMIN");
52+
http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/users/").not().hasAnyRole("USERO");
5353
http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/users/**").hasAnyRole("USERO");
5454
http.authorizeRequests().antMatchers(HttpMethod.PUT, "/api/users/**").hasAnyRole("USERO");
5555
http.authorizeRequests().antMatchers(HttpMethod.DELETE, "/api/users/**").hasAnyRole("USERO");

backend/gamelink/src/main/java/urjc/gamelink/Controllers/UserRestController.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,18 @@ public ResponseEntity<Usero> getUser(@PathVariable long id) {
7272
// Creates a user
7373
@PostMapping("/")
7474
@ResponseStatus(HttpStatus.CREATED)
75-
public ResponseEntity<Usero> createUser(Usero user, @RequestParam String password) {
75+
public ResponseEntity<Usero> createUser(Usero user, @RequestParam String nick,
76+
@RequestParam String name, @RequestParam String lastName,
77+
@RequestParam String email, @RequestParam String password) {
7678

77-
user.setEncodedPassword(password);
79+
user.setEncodedPassword(passwordEncoder.encode(password));
7880
ArrayList<String> list = new ArrayList<>();
7981
list.add("USERO");
8082
user.setRoles(list);
83+
user.setNick(nick);
84+
user.setName(name);
85+
user.setLastName(lastName);
86+
user.setEmail(email);
8187
us.save(user);
8288
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(user.getId())
8389
.toUri();

backend/gamelink/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spring.mustache.suffix=.html
1010

1111
spring.datasource.url=jdbc:postgresql://localhost:5432/gamelink
1212
spring.datasource.username=postgres
13-
spring.datasource.password=Nekowa10
13+
spring.datasource.password=password
1414
spring.jpa.hibernate.ddl-auto=create-drop
1515

1616
logging.level.org.springframework.security=DEBUG

backend/gamelink/target/classes/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spring.mustache.suffix=.html
1010

1111
spring.datasource.url=jdbc:postgresql://localhost:5432/gamelink
1212
spring.datasource.username=postgres
13-
spring.datasource.password=Nekowa10
13+
spring.datasource.password=password
1414
spring.jpa.hibernate.ddl-auto=create-drop
1515

1616
logging.level.org.springframework.security=DEBUG

frontend/src/app/components/login/signUp.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ <h3 class="card-title text-center">Registro</h3>
3838
</div>
3939
<div class="form-group">
4040
<label for="exampleInputPassword1">Contraseña</label>
41-
<input #pass name="password" type="password" class="form-control form-control-sm"
41+
<input #password name="password" type="password" class="form-control form-control-sm"
4242
id="inputPassword1" required>
4343
</div>
4444
<div class="form-group">
4545
<label for="exampleInputPassword1">Confirmación contraseña</label>
46-
<input #pass type="password" class="form-control form-control-sm" id="inputPassword2"
46+
<input type="password" class="form-control form-control-sm" id="inputPassword2"
4747
required>
4848
<span id="passwordMessage"></span>
4949
</div>
5050
<a type="submit" (click)="createUser($event, nick.value, name.value, lastName.value, email.value,
51-
pass.value)" class="btn btn-primary btn-lg px-4 me-sm-3">registrarse</a>
51+
password.value)" class="btn btn-primary btn-lg px-4 me-sm-3">registrarse</a>
5252
</form>
5353
</div>
5454
</div>

frontend/src/app/components/login/signUp.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ import { Usero } from './../../models/usero.model';
88
})
99
export class SignUpComponent {
1010

11+
password!: string;
12+
1113
constructor(public useroService: UseroService) { }
1214

13-
createUser(event: any, nick: string, name: string, lastName: string, email: string, pass: String) {
15+
createUser(event: any, nick: string, name: string, lastName: string, email: string, password: string) {
1416

1517
event.preventDefault();
18+
const formData = new FormData();
1619
var user: Usero = { nick, name, lastName, email, creditCard: "",image: false, roles: ['USERO']}
17-
this.useroService.createUser(user, pass);
20+
formData.append('nick', nick);
21+
formData.append('name', name);
22+
formData.append('lastName', lastName);
23+
formData.append('email', email);
24+
formData.append('password', password);
25+
//this.useroService.createUser(user);
26+
this.useroService.createUser(formData);
1827

1928
if(user.id){
2029
alert("Usuario creado exitoso");

frontend/src/app/services/usero.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ export class UseroService {
5555
}
5656

5757
/*------------------CREATE METHODS------------------*/
58-
createUser(user: Usero, pass : String) {
59-
if (!user.id) {
60-
return this.http.post(BASE_URL, {user, pass}, {withCredentials: true}).subscribe(
58+
createUser(formData: FormData) {
59+
//if (!user.id) {
60+
return this.http.post(BASE_URL, formData).subscribe(
6161
(response) => this.router.navigate(['login']),
6262
(error) => alert('Usuario ya existe, inicie sesión')
6363
)
6464

65-
} else {
65+
/*} else {
6666
return this.http.put(BASE_URL + user.id, user).pipe(
6767
catchError((error: any) => this.handleError(error))
6868
);
69-
}
69+
}*/
7070
}
7171

7272
updateUser(user: Usero){

0 commit comments

Comments
 (0)