use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method doDeleteFile.
/**
* Deletes a file from the user's file space.
*
* @param m
* Map. The command parameters.
* @return String. The JSON formatted string of the return.
* @throws Exception
* on Cache or JSON errors.
*/
public String doDeleteFile(Map m) throws Exception {
Map response = new HashMap();
String who = (String) m.get("username");
String filename = (String) m.get("file");
User u = db.getUser(who);
if (u == null) {
response.put("message", "No user " + who);
return getString(response);
}
String fname = u.directory + "/" + filename;
File f = new File(fname);
f.delete();
Controller.getInstance().sendLog(3, "WebAccess-New-Campaign", who + " deleted a file " + fname);
response.put("images", getFiles(u));
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method makeUsersResponseList.
/**
* Returns a list of users.
*
* @return List. A String list of user names.
* @throws Exception
* in aerospike/cache errors.
*/
private List makeUsersResponseList() throws Exception {
List<User> users = new ArrayList();
List<String> userList = db.getUserList();
for (String s : userList) {
User u = db.getUser(s);
users.add(u);
}
return users;
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method updateUser.
/**
* Update a user's information.
*
* @param m
* Map. The command parameters.
* @return JSON encoded string of the command return values.
* @throws Exception
* on JSON or cache errors.
*/
private String updateUser(Map m) throws Exception {
Map response = new HashMap();
String name = (String) m.get("name");
String pass = (String) m.get("pass");
String directory = (String) m.get("dir");
String phone = (String) m.get("phone");
String email = (String) m.get("email");
String creditcard = (String) m.get("credit");
User u = db.getUser(name);
if (u == null) {
response.put("error", true);
response.put("message", "user does not exist");
} else {
u.creditcard = creditcard;
u.password = pass;
u.directory = directory;
u.phone = phone;
u.email = email;
db.addUser(u);
}
response.put("message", "User changed");
dumpFile(null);
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method doNewCampaign.
/**
* Adds a new campaign to the cache/aerospike.
*
* @param m
* Map. The command parameters.
* @return JSON. The results of the add.
* @throws Exception
* on JSON or cache errors.
*/
private String doNewCampaign(Map m) throws Exception {
Map response = new HashMap();
String who = (String) m.get("username");
User u = db.getUser(who);
if (u == null) {
response.put("message", "No user " + who);
return getString(response);
}
String name = (String) m.get("username");
String id = (String) m.get("campaign");
Controller.getInstance().sendLog(3, "WebAccess-New-Campaign", who + " added a new campaign: " + id);
try {
if (db.getCampaign(name, id) != null) {
response.put("error", true);
response.put("message", "Error, campaign by that name is already defined");
return getString(response);
}
Campaign c = db.createStub(name, id);
db.editCampaign(name, c);
response.put("campaign", c);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
response.put("error", true);
response.put("message", "Error creating campaign: " + e.toString());
}
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method doLogin.
/**
* Handle the login from a web page.
*
* @param request
* HttpServletRequest. The request object.
* @param m
* Map. The parameters of the login.
* @return String. A JSON formatted string of the response to the login.
* @throws Exception
* on JSON errors.
*/
private String doLogin(HttpServletRequest request, Map m) throws Exception {
Map response = new HashMap();
String message = null;
String who = (String) m.get("username");
String pass = (String) m.get("password");
String subcommand = (String) m.get("subcommand");
if (who.equals("root")) {
if (Configuration.getInstance().password != null && Configuration.getInstance().password.equals(pass) == false) {
response.put("error", true);
response.put("message", "No such login");
Controller.getInstance().sendLog(3, "WebAccess-Login", "Bad Campaign Admin root login attempted!");
return getString(response);
}
response.put("campaigns", db.getAllCampaigns());
response.put("running", Configuration.getInstance().getLoadedCampaignNames());
Controller.getInstance().sendLog(3, "WebAccess-Login", "root user has logged in");
return getString(response);
} else {
if (who.equalsIgnoreCase("demo") == true) {
who = "root";
}
}
User u = db.getUser(who);
if (u == null && who.equals("root")) {
response.put("campaigns", db.getAllCampaigns());
response.put("running", Configuration.getInstance().getLoadedCampaignNames());
Controller.getInstance().sendLog(3, "WebAccess-Login", "Demo user has logged in");
} else {
if (u == null) {
response.put("error", true);
response.put("message", "No such login");
Controller.getInstance().sendLog(3, "WebAccess-Login", "Bad Campaign Admin login attempted for : " + who + ", name doesn't exist");
return getString(response);
}
if (u.password.equals(pass) == false) {
response.put("error", true);
response.put("message", "No such login");
Controller.getInstance().sendLog(3, "WebAccess-Login", "Bad Campaign Admin login attempted for : " + who + "!");
return getString(response);
}
Controller.getInstance().sendLog(3, "WebAccess-Login", "User has logged in: " + who);
response = getCampaigns(who);
response.put("username", who);
response.put("running", Configuration.getInstance().getLoadedCampaignNames());
}
response.put("username", who);
response.put("running", Configuration.getInstance().getLoadedCampaignNames());
if (u != null)
response.put("userDir", u.directory);
if (u != null)
response.put("userPhone", u.phone);
if (u != null)
response.put("userEmail", u.email);
if (u != null)
response.put("userCredit", u.creditcard);
HttpSession session = request.getSession();
try {
File f = new File(u.directory);
File[] paths = f.listFiles();
List files = new ArrayList();
Map locator = null;
// for each pathname in pathname array
for (File path : paths) {
locator = new HashMap();
locator.put("uri", u.directory + "/" + path.getName());
locator.put("name", path.getName());
files.add(locator);
}
response.put("images", files);
} catch (Exception error) {
// error.printStackTrace();
Controller.getInstance().sendLog(3, "WebAccess-doLogin", "Error, initializing user data, problem: " + error.toString());
// response.put("error",true); // we are going to allow it, no local
// files.
}
try {
response.put("images", getFiles(u));
} catch (Exception error) {
Controller.getInstance().sendLog(3, "WebAccess-doLogin", "Error, initializing user files, problem: " + error.toString());
}
if (message != null)
response.put("message", message);
return getString(response);
}
Aggregations