1 25 package org.ofbiz.pos.event; 26 27 import java.util.Locale ; 28 29 import org.ofbiz.pos.screen.PosScreen; 30 import org.ofbiz.pos.component.Input; 31 import org.ofbiz.pos.component.Output; 32 import org.ofbiz.pos.PosTransaction; 33 import org.ofbiz.base.util.UtilProperties; 34 import org.ofbiz.base.util.UtilValidate; 35 import org.ofbiz.base.util.Debug; 36 import org.ofbiz.guiapp.xui.XuiSession; 37 import org.ofbiz.entity.GenericValue; 38 39 45 public class SecurityEvents { 46 47 public static final String module = SecurityEvents.class.getName(); 48 49 public static void login(PosScreen pos) { 50 String [] func = pos.getInput().getFunction("LOGIN"); 51 if (func == null) { 52 pos.getInput().setFunction("LOGIN", ""); 53 } 54 baseLogin(pos, false); 55 } 56 57 public static void logout(PosScreen pos) { 58 PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession()); 59 XuiSession session = pos.getSession(); 60 trans.closeTx(); 61 session.logout(); 62 pos.showPage("pospanel"); 63 PosScreen.currentScreen.setLock(true); 64 } 65 66 public static void mgrLogin(PosScreen pos) { 67 XuiSession session = pos.getSession(); 68 if (session.hasRole(session.getUserLogin(), "MANAGER")) { 69 ManagerEvents.mgrLoggedIn = true; 70 pos.showPage("mgrpanel"); 71 PosScreen.currentScreen.getInput().clear(); 72 } else { 73 String [] func = pos.getInput().getFunction("MGRLOGIN"); 74 if (func == null) { 75 pos.getInput().setFunction("MGRLOGIN", ""); 76 } 77 baseLogin(pos, true); 78 } 79 } 80 81 public static void lock(PosScreen pos) { 82 pos.setLock(true); 83 } 84 85 private static void baseLogin(PosScreen pos, boolean mgr) { 86 XuiSession session = pos.getSession(); 87 Output output = pos.getOutput(); 88 Input input = pos.getInput(); 89 90 String loginFunc = mgr ? "MGRLOGIN" : "LOGIN"; 91 String [] func = input.getLastFunction(); 92 String text = input.value(); 93 if (func != null && func[0].equals(loginFunc)) { 94 if (UtilValidate.isEmpty(func[1]) && UtilValidate.isEmpty(text)) { 95 output.print(UtilProperties.getMessage("pos","ULOGIN",Locale.getDefault())); 96 input.setFunction(loginFunc); 97 } else if (UtilValidate.isEmpty(func[1])) { 98 output.print(UtilProperties.getMessage("pos","UPASSW",Locale.getDefault())); 99 input.setFunction(loginFunc); 100 } else { 101 String username = func[1]; 102 String password = text; 103 if (!mgr) { 104 boolean passed = false; 105 try { 106 session.login(username, password); 107 passed = true; 108 } catch (XuiSession.UserLoginFailure e) { 109 output.print(e.getMessage()); 110 input.clear(); 111 } 112 if (passed) { 113 input.clear(); 114 pos.setLock(false); 115 pos.refresh(); 116 return; 117 } 118 } else { 119 GenericValue mgrUl = null; 120 try { 121 mgrUl = session.checkLogin(username, password); 122 } catch (XuiSession.UserLoginFailure e) { 123 output.print(e.getMessage()); 124 input.clear(); 125 } 126 if (mgrUl != null) { 127 boolean isMgr = session.hasRole(mgrUl, "MANAGER"); 128 if (!isMgr) { 129 output.print(UtilProperties.getMessage("pos","UserNotmanager",Locale.getDefault())); 130 input.clear(); 131 } else { 132 ManagerEvents.mgrLoggedIn = true; 133 pos.showPage("mgrpanel"); 134 } 135 } 136 } 137 } 138 } else { 139 Debug.log("Login function called but not prepared as a function!", module); 140 } 141 } 142 } | Popular Tags |