Added registration client/server
This commit is contained in:
parent
dd799f6d99
commit
546e341433
18 changed files with 817 additions and 418 deletions
|
|
@ -16,37 +16,59 @@ public class TTAuth extends UnicastRemoteObject implements ITTAuth {
|
|||
|
||||
private SecureRandom random = new SecureRandom();
|
||||
|
||||
public String nextSessionId() {
|
||||
return new BigInteger(130, random).toString(32);
|
||||
}
|
||||
|
||||
public TTAuth() throws RemoteException{
|
||||
}
|
||||
|
||||
@Override
|
||||
public TTResponse register(String userName, String password) throws RemoteException {
|
||||
TTLogger.write("LOGGER: Invoked register with username=" + userName + " AND " + " password=" + password);
|
||||
if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) {
|
||||
boolean res = true;//TODO Inserisci nel db e verifica se c'è un utente con lo stesso nome
|
||||
|
||||
if(userName.equals("ciro")){ //TODO rimuovere
|
||||
res = false;
|
||||
}
|
||||
if(res) {
|
||||
TTLogger.write("LOGGER: Registration successfull");
|
||||
return new TTResponse("Registration successfull", 200, null);
|
||||
} else {
|
||||
TTLogger.write("LOGGER: Registration unsuccessfull");
|
||||
return new TTResponse("Registration unsuccessfull: Username exist!", 400, null);
|
||||
}
|
||||
}
|
||||
return new TTResponse("Registration unsuccessfull! All fields are mandatories", 400, null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TTResponse login(String userName, String password) throws RemoteException {
|
||||
TTLogger.write("LOGGER: Invoked login with username=" + userName + " AND " + " password=" + password);
|
||||
if ((userName != null && !userName.isEmpty())
|
||||
&& (password != null && !password.equals(""))) {
|
||||
if ((userName != null && !userName.isEmpty()) && (password != null && !password.equals(""))) {
|
||||
|
||||
if((userName.equalsIgnoreCase("admin"))
|
||||
&& (password.equals("admin"))) {
|
||||
JsonObject data = new JsonObject();
|
||||
data.put("token", nextSessionId());
|
||||
System.out.println("LOGGER: Login successfull");
|
||||
TTLogger.write("LOGGER: Login successfull");
|
||||
return new TTResponse("Login successfull", 200, data);
|
||||
}
|
||||
}
|
||||
System.out.println("LOGGER: Login unsuccessfull");
|
||||
return new TTResponse("Login unsuccessfull", 400, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TTResponse logout(String userName, String token) throws RemoteException {
|
||||
System.out.println("LOGGER: Invoked logout with username=" + userName + " AND " + " token=" + token);
|
||||
if ((userName != null && !userName.isEmpty())
|
||||
&& (token != null && !token.isEmpty())) {
|
||||
TTLogger.write("LOGGER: Invoked logout with username=" + userName + " AND " + " token=" + token);
|
||||
if ((userName != null && !userName.isEmpty()) && (token != null && !token.isEmpty())) {
|
||||
return new TTResponse("Logout successfull", 200, null);
|
||||
}
|
||||
return new TTResponse("Logout successfull (but something go wrong)", 200, null);
|
||||
return new TTResponse("Logout successfull (but something gone wrong)", 200, null);
|
||||
}
|
||||
|
||||
public String nextSessionId() {
|
||||
return new BigInteger(130, random).toString(32);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue