New view-only mode for client
This commit is contained in:
@ -2,11 +2,6 @@ package es.mesacarlos.webconsole.auth;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import es.mesacarlos.webconsole.WebConsole;
|
||||
|
||||
public class LoginManager {
|
||||
private ArrayList<User> loggedInUsers = new ArrayList<User>();
|
||||
@ -38,6 +33,11 @@ public class LoginManager {
|
||||
loggedInUsers.remove(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user object by socket
|
||||
* @param address socket of the user
|
||||
* @return User object, null if no user logged in from that address
|
||||
*/
|
||||
public User getUser(InetSocketAddress address) {
|
||||
for(User user : loggedInUsers)
|
||||
if(user.getSocketAddress().equals(address))
|
||||
@ -65,52 +65,4 @@ public class LoginManager {
|
||||
return loggedInUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided password corresponds to any admin
|
||||
* @param password Provided password
|
||||
* @return Name of the user if password corresponds to a valid admin, null if is a viewer or an invalid password
|
||||
*/
|
||||
public String isValidAdminPassword(String password) {
|
||||
WebConsole plugin = (WebConsole)Bukkit.getPluginManager().getPlugin("WebConsole");
|
||||
Map<String, Object> passwords = plugin.getConfig().getConfigurationSection("passwords").getConfigurationSection("admin").getValues(false);
|
||||
|
||||
for(Map.Entry<String, Object> entry : passwords.entrySet()) {
|
||||
String pwd = (String)entry.getValue();
|
||||
if(pwd.equals(password))
|
||||
return entry.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided password corresponds to any viewer
|
||||
* @param password Provided password
|
||||
* @return Name of the user if password corresponds to a valid viewer, null if is a admin or invalid password
|
||||
*/
|
||||
public String isValidViewerPassword(String password) {
|
||||
WebConsole plugin = (WebConsole)Bukkit.getPluginManager().getPlugin("WebConsole");
|
||||
Map<String, Object> passwords = plugin.getConfig().getConfigurationSection("passwords").getConfigurationSection("viewer").getValues(false);
|
||||
|
||||
for(Map.Entry<String, Object> entry : passwords.entrySet()) {
|
||||
String pwd = (String)entry.getValue();
|
||||
if(pwd.equals(password))
|
||||
return entry.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserType isValidUser(String password) {
|
||||
//Check if is an admin
|
||||
String username = isValidAdminPassword(password);
|
||||
if(username != null)
|
||||
return UserType.ADMIN;
|
||||
|
||||
//Check if is a viewer
|
||||
username = isValidViewerPassword(password);
|
||||
if(username != null)
|
||||
return UserType.VIEWER;
|
||||
|
||||
//He is nothing
|
||||
return UserType.UNKNOWN;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user