1 package org.itracker.web.forms; 2 3 import org.apache.struts.action.ActionErrors; 4 import org.apache.struts.action.ActionMapping; 5 import org.apache.struts.action.ActionMessage; 6 import org.apache.struts.action.ActionMessages; 7 import org.apache.struts.validator.ValidatorForm; 8 9 import javax.servlet.http.HttpServletRequest; 10 import java.util.HashMap; 11 import java.util.Map; 12 13 public class UserForm extends ValidatorForm { 14 15 private static final long serialVersionUID = 1L; 16 17 private String action = null; 18 private Integer id = -1; 19 private String login = null; 20 private String currPassword = null; 21 private String password = null; 22 private String confPassword = null; 23 private String firstName = null; 24 private String lastName = null; 25 private String email = null; 26 27 private boolean superUser = false; 28 29 private Map<String, Boolean> permissions = new HashMap<>(); 30 31 private String userLocale = null; 32 private String numItemsOnIndex = null; 33 private String numItemsOnIssueList = null; 34 private String showClosedOnIssueList = null; 35 private String sortColumnOnIssueList = null; 36 private Integer[] hiddenIndexSections = null; 37 private String rememberLastSearch = null; 38 private String useTextActions = null; 39 40 public String getAction() { 41 return action; 42 } 43 44 public void setAction(String value) { 45 action = value; 46 } 47 48 public Integer getId() { 49 return id; 50 } 51 52 public void setId(Integer value) { 53 id = value; 54 } 55 56 public String getLogin() { 57 return login; 58 } 59 60 public void setLogin(String value) { 61 login = value; 62 } 63 64 public String getCurrPassword() { 65 return currPassword; 66 } 67 68 public void setCurrPassword(String value) { 69 currPassword = value; 70 } 71 72 public String getPassword() { 73 return password; 74 } 75 76 public void setPassword(String value) { 77 password = value; 78 } 79 80 public String getConfPassword() { 81 return confPassword; 82 } 83 84 public void setConfPassword(String value) { 85 confPassword = value; 86 } 87 88 public String getFirstName() { 89 return firstName; 90 } 91 92 public void setFirstName(String value) { 93 firstName = value; 94 } 95 96 public String getLastName() { 97 return lastName; 98 } 99 100 public void setLastName(String value) { 101 lastName = value; 102 } 103 104 public String getEmail() { 105 return email; 106 } 107 108 public void setEmail(String value) { 109 email = value; 110 } 111 112 public boolean isSuperUser() { 113 return superUser; 114 } 115 116 public void setSuperUser(boolean value) { 117 superUser = value; 118 } 119 120 public Map<String, Boolean> getPermissions() { 121 return permissions; 122 } 123 124 public void setPermissions(Map<String, Boolean> value) { 125 permissions = value; 126 } 127 128 public String getUserLocale() { 129 return userLocale; 130 } 131 132 public void setUserLocale(String value) { 133 userLocale = value; 134 } 135 136 137 public String getNumItemsOnIndex() { 138 return numItemsOnIndex; 139 } 140 141 public void setNumItemsOnIndex(String value) { 142 numItemsOnIndex = value; 143 } 144 145 public String getNumItemsOnIssueList() { 146 return numItemsOnIssueList; 147 } 148 149 public void setNumItemsOnIssueList(String value) { 150 numItemsOnIssueList = value; 151 } 152 153 public String getShowClosedOnIssueList() { 154 return showClosedOnIssueList; 155 } 156 157 public void setShowClosedOnIssueList(String value) { 158 showClosedOnIssueList = value; 159 } 160 161 public String getSortColumnOnIssueList() { 162 return sortColumnOnIssueList; 163 } 164 165 public void setSortColumnOnIssueList(String value) { 166 sortColumnOnIssueList = value; 167 } 168 169 public Integer[] getHiddenIndexSections() { 170 if (null == hiddenIndexSections) 171 return null; 172 return hiddenIndexSections.clone(); 173 } 174 175 public void setHiddenIndexSections(Integer[] value) { 176 if (null == value) 177 this.hiddenIndexSections = null; 178 else 179 hiddenIndexSections = value.clone(); 180 } 181 182 public String getRememberLastSearch() { 183 return rememberLastSearch; 184 } 185 186 public void setRememberLastSearch(String value) { 187 rememberLastSearch = value; 188 } 189 190 public String getUseTextActions() { 191 return useTextActions; 192 } 193 194 public void setUseTextActions(String value) { 195 useTextActions = value; 196 } 197 198 public void reset(ActionMapping mapping, HttpServletRequest request) { 199 action = null; 200 id = -1; 201 login = null; 202 currPassword = null; 203 password = null; 204 confPassword = null; 205 firstName = null; 206 lastName = null; 207 email = null; 208 superUser = false; 209 210 permissions = new HashMap<>(); 211 212 userLocale = null; 213 numItemsOnIndex = null; 214 numItemsOnIssueList = null; 215 showClosedOnIssueList = null; 216 sortColumnOnIssueList = null; 217 hiddenIndexSections = null; 218 rememberLastSearch = null; 219 useTextActions = null; 220 } 221 222 public ActionErrors validate(ActionMapping mapping, 223 HttpServletRequest request) { 224 225 ActionErrors errors = super.validate(mapping, request); 226 227 if (password == null || password.trim().equals("")) { 228 return errors; 229 } 230 231 if (!("register".equalsIgnoreCase(action) 232 || "create".equalsIgnoreCase(action) 233 || "update".equalsIgnoreCase(action) 234 || "preferences".equalsIgnoreCase(action) 235 ) && (currPassword == null || "".equals(currPassword))) { 236 237 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( 238 "itracker.web.error.missingpassword")); 239 240 } else if (!password.equals(confPassword)) { 241 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( 242 "itracker.web.error.matchingpass")); 243 } 244 245 246 request.setAttribute("warnings", errors); 247 request.setAttribute("isUpdate", true); 248 request.setAttribute("allowProfileUpdate", true); 249 request.setAttribute("allowPasswordUpdate", true); 250 251 return errors; 252 } 253 254 }