Revision 46268014 src/gr/ebs/gss/server/Registration.java

b/src/gr/ebs/gss/server/Registration.java
54 54
	private static final String ACCEPT_PARAM = "accept";
55 55

  
56 56
	/**
57
	 * The request parameter name for the name.
57
	 * The request parameter name for the firstname.
58 58
	 */
59
	private static final String NAME_PARAM = "name";
59
	private static final String FIRSTNAME_PARAM = "firstname";
60

  
61
	/**
62
	 * The request parameter name for the lastname.
63
	 */
64
	private static final String LASTNAME_PARAM = "lastname";
60 65

  
61 66
	/**
62 67
	 * The request parameter name for the username.
......
116 121

  
117 122
	@Override
118 123
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
119
		final String name = request.getParameter(NAME_PARAM);
124
		final String firstname = request.getParameter(FIRSTNAME_PARAM);
125
		final String lastname = request.getParameter(LASTNAME_PARAM);
120 126
		final String email = request.getParameter(EMAIL_PARAM);
121 127
		final String username = request.getParameter(USERNAME_PARAM);
122 128
		String password = request.getParameter(PASSWORD_PARAM);
......
128 134
		if (username == null || username.isEmpty()) {
129 135
			String error = URLEncoder.encode("No username was specified", "UTF-8");
130 136
			String errorUrl = "register.jsp?username=&error=" + error;
131
			errorUrl += "&name=" + (name == null? "": name);
137
			errorUrl += "&firstname=" + (firstname == null? "": firstname);
138
			errorUrl += "&lastname=" + (lastname == null? "": lastname);
139
			errorUrl += "&email=" + (email == null? "": email);
140
			response.sendRedirect(errorUrl);
141
			return;
142
		} else if (firstname == null || firstname.isEmpty()) {
143
			String error = URLEncoder.encode("No firstname was specified", "UTF-8");
144
			String errorUrl = "register.jsp?firstname=&error=" + error;
145
			errorUrl += "&username=" + username;
146
			errorUrl += "&lastname=" + (lastname == null? "": lastname);
132 147
			errorUrl += "&email=" + (email == null? "": email);
133 148
			response.sendRedirect(errorUrl);
134 149
			return;
135
		} else if (name == null || name.isEmpty()) {
136
			String error = URLEncoder.encode("No name was specified", "UTF-8");
137
			String errorUrl = "register.jsp?name=&error=" + error;
150
		} else if (lastname == null || lastname.isEmpty()) {
151
			String error = URLEncoder.encode("No lastname was specified", "UTF-8");
152
			String errorUrl = "register.jsp?lastname=&error=" + error;
138 153
			errorUrl += "&username=" + username;
154
			errorUrl += "&firstname=" + firstname;
139 155
			errorUrl += "&email=" + (email == null? "": email);
140 156
			response.sendRedirect(errorUrl);
141 157
			return;
......
143 159
			String error = URLEncoder.encode("No e-mail was specified", "UTF-8");
144 160
			String errorUrl = "register.jsp?email=&error=" + error;
145 161
			errorUrl += "&username=" + username;
146
			errorUrl += "&name=" + name;
162
			errorUrl += "&firstname=" + firstname;
163
			errorUrl += "&lastname=" + lastname;
147 164
			response.sendRedirect(errorUrl);
148 165
			return;
149 166
		} else if (password == null || password.isEmpty()) {
150 167
			String error = URLEncoder.encode("No password was specified", "UTF-8");
151 168
			String errorUrl = "register.jsp?error=" + error;
152 169
			errorUrl += "&username=" + username;
153
			errorUrl += "&name=" + name;
170
			errorUrl += "&firstname=" + firstname;
171
			errorUrl += "&lastname=" + lastname;
154 172
			errorUrl += "&email=" + email;
155 173
			response.sendRedirect(errorUrl);
156 174
			return;
......
158 176
			String error = URLEncoder.encode("Passwords do not match", "UTF-8");
159 177
			String errorUrl = "register.jsp?error=" + error;
160 178
			errorUrl += "&username=" + username;
161
			errorUrl += "&name=" + name;
179
			errorUrl += "&firstname=" + firstname;
180
			errorUrl += "&lastname=" + lastname;
162 181
			errorUrl += "&email=" + email;
163 182
			response.sendRedirect(errorUrl);
164 183
			return;
......
166 185
			String error = URLEncoder.encode("You must accept the terms and conditions", "UTF-8");
167 186
			String errorUrl = "register.jsp?error=" + error;
168 187
			errorUrl += "&username=" + username;
169
			errorUrl += "&name=" + name;
188
			errorUrl += "&firstname=" + firstname;
189
			errorUrl += "&lastname=" + lastname;
170 190
			errorUrl += "&email=" + email;
171 191
			response.sendRedirect(errorUrl);
172 192
			return;
......
178 198
			if (user != null) {
179 199
				String error = URLEncoder.encode("The username already exists", "UTF-8");
180 200
				String errorUrl = "register.jsp?username=&error=" + error;
181
				errorUrl += "&name=" + name;
201
				errorUrl += "&firstname=" + firstname;
202
				errorUrl += "&lastname=" + lastname;
182 203
				errorUrl += "&email=" + email;
183 204
				response.sendRedirect(errorUrl);
184 205
				return;
185 206
			}
186 207
			try {
187
				getService().createLdapUser(username, name, email, password);
188
			} catch (Exception exc) {
189
				String error = "An error occurred while communicating with the Shibboleth IdP";
190
				logger.error(error, exc);
191
				response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
208
				getService().createLdapUser(username, firstname, lastname, email, password);
209
			} catch (Exception e) {
210
				logger.error(e);
211
				response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
192 212
				return;
193 213
			}
194 214
			final UserDTO userDto = new TransactionHelper<UserDTO>().tryExecute(new Callable<UserDTO>() {
195 215
				@Override
196 216
				public UserDTO call() throws Exception {
197
					return getService().createUser(username, name, email, "", "").getDTO();
217
					return getService().createUser(username, firstname + " " + lastname, email, "", "").getDTO();
198 218
				}
199 219

  
200 220
			});
......
214 234
		} catch (DuplicateNameException e) {
215 235
			// Can't happen, but this is more user-friendly than an assert.
216 236
			String error = URLEncoder.encode("The username already exists", "UTF-8");
217
			String errorUrl = "register.jsp?username=&name=&email=&error=" + error;
237
			String errorUrl = "register.jsp?username=&firstname=&lastname=&email=&error=" + error;
218 238
			response.sendRedirect(errorUrl);
219 239
		} catch (ObjectNotFoundException e) {
220 240
			// Can't happen, but this is more user-friendly than an assert.
221 241
			String error = URLEncoder.encode("No username or name was specified", "UTF-8");
222
			String errorUrl = "register.jsp?username=&name=&email=&error=" + error;
242
			String errorUrl = "register.jsp?username=&firstname=&lastname=&email=&error=" + error;
223 243
			response.sendRedirect(errorUrl);
224 244
		} catch (Exception e) {
225
			// TODO Auto-generated catch block
226
			e.printStackTrace();
245
			logger.error(e);
246
			response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
227 247
		}
228 248
	}
229 249
}

Also available in: Unified diff