1 package edu.drexel.cms.actions; 2 3 import javax.servlet.http.HttpServletRequest; 4 5 import org.apache.struts2.interceptor.ServletRequestAware; 6 7 import com.opensymphony.xwork2.ActionSupport; 8 9 import edu.drexel.cms.commons.CmsDataValidationException; 10 import edu.drexel.cms.data.CmsDAO; 11 import edu.drexel.cmsDb.datamodel.User; 12 import edu.drexel.cmsDb.datamodel.UserType; 13 import static edu.drexel.cms.commons.MessageKeys.*; 14 15 /*** 16 * New user registration action. 17 * 18 * @author jliang 19 * 20 */ 21 22 public class NewUserRegistrationAction extends ActionSupport implements ServletRequestAware { 23 24 private static final long serialVersionUID = 20070504L; 25 private static final String NEW_USER_ERROR_USER_NAME_EXISTS = "error.new.user.user.name.exists"; 26 private static final String NEW_USER_ERROR_EMAIL_EXISTS = "error.new.user.email.exists"; 27 private static final String NEW_USER_ERROR = "error.new.user"; 28 private static final String NEW_USER_COMPLETE = "success.new.user.complete"; 29 30 private HttpServletRequest _request; 31 private String _userName; 32 private String _password; 33 private String _firstName; 34 private String _lastName; 35 private String _middleName; 36 private String _affiliation; 37 private String _phone; 38 private String _email; 39 private String _additionContactInfo; 40 41 @Override 42 public String execute() { 43 try{ 44 if(CmsDAO.isUserExist(_userName)){ 45 addActionError(getText(NEW_USER_ERROR_USER_NAME_EXISTS)); 46 return INPUT; 47 } 48 if(CmsDAO.isEmailExist(_email)){ 49 addActionError(getText(NEW_USER_ERROR_EMAIL_EXISTS)); 50 return INPUT; 51 } 52 User user = new User(_userName, _password, _email, _phone, 53 _affiliation, _additionContactInfo, UserType.AUTHOR, _firstName, _lastName, _middleName); 54 CmsDAO.addUser(user); 55 addActionError(getText(NEW_USER_COMPLETE)); 56 return SUCCESS; 57 }catch(CmsDataValidationException ce){ 58 LOG.error(getText(INVALID_DATA)); 59 addActionError(ce.getMessage()); 60 return INPUT; 61 } 62 catch(Exception e){ 63 addActionError(getText(NEW_USER_ERROR)); 64 return INPUT; 65 } 66 } 67 68 public String getAdditionContactInfo() { 69 return _additionContactInfo; 70 } 71 72 public void setAdditionContactInfo(String additionContactInfo) { 73 _additionContactInfo = additionContactInfo; 74 } 75 76 public String getAffiliation() { 77 return _affiliation; 78 } 79 80 public void setAffiliation(String affiliation) { 81 _affiliation = affiliation; 82 } 83 84 public String getEmail() { 85 return _email; 86 } 87 88 public void setEmail(String email) { 89 _email = email; 90 } 91 92 public String getFirstName() { 93 return _firstName; 94 } 95 96 public void setFirstName(String firstName) { 97 _firstName = firstName; 98 } 99 100 public String getLastName() { 101 return _lastName; 102 } 103 104 public void setLastName(String lastName) { 105 _lastName = lastName; 106 } 107 108 public String getMiddleName() { 109 return _middleName; 110 } 111 112 public void setMiddleName(String middleName) { 113 _middleName = middleName; 114 } 115 116 public String getPassword() { 117 return _password; 118 } 119 120 public void setPassword(String password) { 121 _password = password; 122 } 123 124 public String getPhone() { 125 return _phone; 126 } 127 128 public void setPhone(String phone) { 129 _phone = phone; 130 } 131 132 public HttpServletRequest getRequest() { 133 return _request; 134 } 135 136 public void setRequest(HttpServletRequest request) { 137 _request = request; 138 } 139 140 public String getUserName() { 141 return _userName; 142 } 143 144 public void setUserName(String userName) { 145 _userName = userName; 146 } 147 148 public void setServletRequest(HttpServletRequest req) { 149 _request = req; 150 } 151 152 }