Skip to content

Commit

Permalink
Add UserExistsMiddleware - ConcreteHandler (Filtering Access - Chain …
Browse files Browse the repository at this point in the history
…Of Responsibility)
  • Loading branch information
AlessandroFerrante committed Jul 24, 2024
1 parent 01a2f59 commit 2d694cc
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ChainOfResponsability/FilteringAccess/UserExistsMiddleware.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ConcreteHandler
public class UserExistsMiddleware extends BaseMiddleware{
private Server server;

//! Constructor replaced by link method
//public UserExistsMiddleware(BaseMiddleware m){
// this.next = m;
//}

public UserExistsMiddleware(Server s) {
this.server = s;
}

// handlerRequest method
@Override
public boolean check(String email, String password) {
if(!server.hasEmail(email)){
System.out.println("This email is not registered");
return false;
}
if (!server.isValidPassword(email, password)) {
System.out.println("Wrong password");
return false;
}

return checkNext(email, password);
}
}

0 comments on commit 2d694cc

Please sign in to comment.