modificamos el controladora para verificar si un usuario estaba registrado y confirmado
This commit is contained in:
@@ -3,6 +3,7 @@ package com.example.fercoganbackend.controller;
|
|||||||
import com.example.fercoganbackend.component.ContadorWebSocketHandler;
|
import com.example.fercoganbackend.component.ContadorWebSocketHandler;
|
||||||
import com.example.fercoganbackend.entity.Rol;
|
import com.example.fercoganbackend.entity.Rol;
|
||||||
import com.example.fercoganbackend.entity.Usuario;
|
import com.example.fercoganbackend.entity.Usuario;
|
||||||
|
import com.example.fercoganbackend.otros.ConfirmadoTF;
|
||||||
import com.example.fercoganbackend.service.ContadorService;
|
import com.example.fercoganbackend.service.ContadorService;
|
||||||
import com.example.fercoganbackend.service.UsuarioService;
|
import com.example.fercoganbackend.service.UsuarioService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -33,9 +34,9 @@ public class AppController {
|
|||||||
|
|
||||||
// Verificar si aprobado
|
// Verificar si aprobado
|
||||||
@GetMapping("/auth/verificar/{username}")
|
@GetMapping("/auth/verificar/{username}")
|
||||||
public String verificar(@PathVariable String username) {
|
public ConfirmadoTF verificar(@PathVariable String username) {
|
||||||
boolean aprobado = usuarioService.estaAprobado(username);
|
ConfirmadoTF aprobado = usuarioService.registradoYAprobado(username);
|
||||||
return aprobado ? "Usuario aprobado ✅" : "Usuario pendiente ❌";
|
return aprobado;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listar pendientes (solo admin/super)
|
// Listar pendientes (solo admin/super)
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.example.fercoganbackend.otros;
|
||||||
|
|
||||||
|
public class ConfirmadoTF {
|
||||||
|
private boolean authenticated;
|
||||||
|
private boolean confirmed;
|
||||||
|
|
||||||
|
public ConfirmadoTF(){
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAuthenticated() {
|
||||||
|
return authenticated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthenticated(boolean authenticated) {
|
||||||
|
this.authenticated = authenticated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConfirmed() {
|
||||||
|
return confirmed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfirmed(boolean confirmed) {
|
||||||
|
this.confirmed = confirmed;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.fercoganbackend.service;
|
package com.example.fercoganbackend.service;
|
||||||
import com.example.fercoganbackend.entity.Rol;
|
import com.example.fercoganbackend.entity.Rol;
|
||||||
import com.example.fercoganbackend.entity.Usuario;
|
import com.example.fercoganbackend.entity.Usuario;
|
||||||
|
import com.example.fercoganbackend.otros.ConfirmadoTF;
|
||||||
import com.example.fercoganbackend.repository.UsuarioRepository;
|
import com.example.fercoganbackend.repository.UsuarioRepository;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -39,4 +40,16 @@ public class UsuarioService {
|
|||||||
public boolean estaAprobado(String username) {
|
public boolean estaAprobado(String username) {
|
||||||
return repo.findByUsername(username).map(Usuario::isAprobado).orElse(false);
|
return repo.findByUsername(username).map(Usuario::isAprobado).orElse(false);
|
||||||
}
|
}
|
||||||
|
public boolean estaRegistrado(String username) {
|
||||||
|
return repo.findByUsername(username).isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfirmadoTF registradoYAprobado(String username){
|
||||||
|
ConfirmadoTF confirmadotf = new ConfirmadoTF();
|
||||||
|
confirmadotf.setAuthenticated(estaRegistrado(username));
|
||||||
|
confirmadotf.setConfirmed(estaAprobado(username));
|
||||||
|
return confirmadotf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user