public static void authenticate(String username, String password) { Logger.info("Attempting to authenticate with " + username + ":" + password); Admin admin = Admin.findByUsername(username); if ((admin != null) && (admin.checkPassword(password) == true)) { Logger.info("Successfull authentication of " + admin.username); /** * wanted to put an extra value in session - logged_in_adminid to distinguish an admin, as a * user could be logged in and type the route for admin URLs and get into the restricted * access areas. By putting a new value in session, it can only be set if an admin is logged * in. */ session.put("logged_in_adminid", admin.id); /** * if login successful, communicate back to AJAX call in adminlogin.js and that will handle * the next screen */ JSONObject obj = new JSONObject(); String value = "correct"; obj.put("inputdata", value); renderJSON(obj); } else { /** * if login unsuccessful, communicate back to AJAX call in adminlogin.js and that will * redisplay login.html with error */ Logger.info("Authentication failed"); JSONObject obj = new JSONObject(); String value = "Error: Incorrect Email/Password entered."; obj.put("inputdata", value); renderJSON(obj); } }
public static Admin getCurrentAdmin() { /** * get currently logged in admin for Candidate (CandidateController.java) + Office * (OfficeController.java) constructors via new logged_in_adminid written to session on admin * login */ String adminId = session.get("logged_in_adminid"); if (adminId == null) { return null; } Admin logged_in_admin = Admin.findById(Long.parseLong(adminId)); Logger.info("In Admin controller: Logged in admin is " + logged_in_admin.username); return logged_in_admin; }
public static void yearQuarterGeneralAverage(String value) { Admin.reports(value, 3); }
public static void subjectsGradePerQuarter(String subject) { Admin.reports(subject, 2); }
public static void generalAveragePerQuarter(int studentId) { Admin.reports(String.valueOf(studentId), 1); }
public static void uploadFile(String filename, File file) { User user = User.find("byEmail", Security.connected()).first(); Upload uploadObj = new Upload(); uploadObj.UploadFile(filename, user, file); Admin.upload(); }