public String admin_add_do() { System.out.print( "即将进入管理员添加:户名" + a_username + " 真实名字" + a_name + " 权限" + a_super + " 密码" + a_password + "\n"); h.setA_name(a_name); h.setA_username(a_username); h.setA_super(a_super); h.setA_password(a_password); adminservice.add(h); return "add_success"; }
public String admin_login() { System.out.print("即将进入登陆验证:" + a_username + "\n"); // AdminService adminservice=new AdminService(); h = adminservice.findFromName(a_username); if (h == null) { user_check = "您输入的用户不存在!"; return "login_false"; } else { if (a_password.equals(h.getA_password())) { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); session.setAttribute("a_username", a_username); session.setAttribute("a_super", h.getA_super()); session.setAttribute("a_name", h.getA_name()); return "login_success"; } else { user_check = "您输入的密码错误!"; return "login_false"; } } }
/** A supposed existent user tries to login to our system. */ private void logIn() { boolean check; boolean exists = false; int tries = 0; String user, pass; Person pers = null; /** Trying to select the person by its username. Maximum number of tries: 3. */ while (!exists && tries < 3) { int i; Consola.escriu("Insert username: "******"Invalid username, please try again."); tries += 1; } } /** * If we reached the end, we wither have a person or we have more than 3 tries. More than 3 * tries means that exists = false. Let's ask for the password in the case that exists is true. */ if (exists) { exists = false; tries = 0; // You can try 3 times for your password. while (!exists && tries < 3) { Consola.escriu("Insert password: "******"Correct password"); } else { Consola.escriu("Incorrect password."); tries += 1; } } } /** * We can have two situations: either we have a correct person (with correct user and password) * or we have exceeded the maximum tries permited. If we have a correct person, we show the * pertinent menu. If we reach here with more than 3 tries, then you can't log in. */ if (pers instanceof Client && tries < 3) { // Given the client, we have to check if he can logIn // id est, if he has less than 3 admonishes. if (((Client) pers).canLogIn()) { // Succeed, the client can log in and is now in use of our application. current = pers; selectOptionMenuClient(); } else { // Our client can log in =( Inform him/her. Consola.escriu("You have 3 admonishes, you can't log in, sorry."); } } else if (pers instanceof Manager && tries < 3) { current = pers; selectOptionMenuManager(); } else if (pers instanceof Admin && tries < 3) { current = pers; selectOptionMenuAdmin(); } else { Consola.escriu("You've exceeded the maximum permited tries"); } }