Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.8 kB
2
Indexable
Never
    @PostMapping(path = "/VaildateUser")
    public  String VaildateUser(@RequestBody LoginDTO loginDTO) throws Exception{
        try {
            String username = loginDTO.getUsername();
            String password = loginDTO.getPassword();

            String Result = Service.VaildateUserCred(username, password);

            if (Objects.equals(Result, "Admin Login")) {
                return String.valueOf(new ResponseEntity<>("Admin Login Successfully", HttpStatus.OK));
            } else if (Objects.equals(Result, "User Login")) {
                return String.valueOf(new ResponseEntity<>("User Login Successfully", HttpStatus.OK));
            } else if (Objects.equals(Result, "Not a User")) {
                return String.valueOf(new ResponseEntity<>("Incorrect Password or Username", HttpStatus.OK));
            } else {
                return String.valueOf(new ResponseEntity<>("Enter Username or Password", HttpStatus.OK));
            }
        }
        catch (Exception error){
            throw new Exception(error);
        }
    }



//service
    @ExceptionHandler
    public  String VaildateUserCred(String Username, String Password) throws Exception {
        try {
            Login Signin = Repo.findByUsername(Username);
            if (Signin != null) {
                boolean temp = Objects.equals(Signin.getPassword(), Password);
                if (temp && Signin.isAccess()) {
                    return "Admin Login";
                } else if (temp && !Signin.isAccess()) {
                    return "User Login";
                }
            } else {
                return "Not a User";
            }
        }
        catch (Exception error){
            throw new Exception(error);
        }
        return "";
    }
Leave a Comment