Unverified Commit bee418e2 authored by Hollow Man's avatar Hollow Man Committed by GitHub

Fix multiple locale showing in login failed page (#2434)

This commit is a further address to the issue #1518

Currently when the selected language is not English in login page, when login failed (e.g the password is incorrect), the login page will return with an English Page.
The commit fix this problem by adding an additional locale parameter to fail method in LoginServlet.java
parent b4557d64
...@@ -116,7 +116,7 @@ public class LoginServlet extends HttpServlet { ...@@ -116,7 +116,7 @@ public class LoginServlet extends HttpServlet {
// This is arranged via a security-constraint setup in web.xml // This is arranged via a security-constraint setup in web.xml
com.google.appengine.api.users.User apiUser = userService.getCurrentUser(); com.google.appengine.api.users.User apiUser = userService.getCurrentUser();
if (apiUser == null) { // Hmmm. I don't think this should happen if (apiUser == null) { // Hmmm. I don't think this should happen
fail(req, resp, "Google Authentication Failed"); // Not sure what else to do fail(req, resp, "Google Authentication Failed", locale); // Not sure what else to do
return; return;
} }
String email = apiUser.getEmail(); String email = apiUser.getEmail();
...@@ -184,12 +184,12 @@ public class LoginServlet extends HttpServlet { ...@@ -184,12 +184,12 @@ public class LoginServlet extends HttpServlet {
if (page.equals("setpw")) { if (page.equals("setpw")) {
String uid = getParam(req); String uid = getParam(req);
if (uid == null) { if (uid == null) {
fail(req, resp, "Invalid Set Password Link"); fail(req, resp, "Invalid Set Password Link", locale);
return; return;
} }
PWData data = storageIo.findPWData(uid); PWData data = storageIo.findPWData(uid);
if (data == null) { if (data == null) {
fail(req, resp, "Invalid Set Password Link"); fail(req, resp, "Invalid Set Password Link", locale);
return; return;
} }
if (DEBUG) { if (DEBUG) {
...@@ -300,13 +300,13 @@ public class LoginServlet extends HttpServlet { ...@@ -300,13 +300,13 @@ public class LoginServlet extends HttpServlet {
if (page.equals("sendlink")) { if (page.equals("sendlink")) {
String email = params.get("email"); String email = params.get("email");
if (email == null) { if (email == null) {
fail(req, resp, "No Email Address Provided"); fail(req, resp, "No Email Address Provided", locale);
return; return;
} }
// Send email here, for now we put it in the error string and redirect // Send email here, for now we put it in the error string and redirect
PWData pwData = storageIo.createPWData(email); PWData pwData = storageIo.createPWData(email);
if (pwData == null) { if (pwData == null) {
fail(req, resp, "Internal Error"); fail(req, resp, "Internal Error", locale);
return; return;
} }
String link = trimPage(req) + pwData.id + "/setpw"; String link = trimPage(req) + pwData.id + "/setpw";
...@@ -316,23 +316,23 @@ public class LoginServlet extends HttpServlet { ...@@ -316,23 +316,23 @@ public class LoginServlet extends HttpServlet {
return; return;
} else if (page.equals("setpw")) { } else if (page.equals("setpw")) {
if (userInfo == null || userInfo.getUserId().equals("")) { if (userInfo == null || userInfo.getUserId().equals("")) {
fail(req, resp, "Session Timed Out"); fail(req, resp, "Session Timed Out", locale);
return; return;
} }
User user = storageIo.getUser(userInfo.getUserId()); User user = storageIo.getUser(userInfo.getUserId());
String password = params.get("password"); String password = params.get("password");
if (password == null || password.equals("")) { if (password == null || password.equals("")) {
fail(req, resp, bundle.getString("nopassword")); fail(req, resp, bundle.getString("nopassword"), locale);
return; return;
} }
String hashedPassword; String hashedPassword;
try { try {
hashedPassword = PasswordHash.createHash(password); hashedPassword = PasswordHash.createHash(password);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
fail(req, resp, "System Error hashing password"); fail(req, resp, "System Error hashing password", locale);
return; return;
} catch (InvalidKeySpecException e) { } catch (InvalidKeySpecException e) {
fail(req, resp, "System Error hashing password"); fail(req, resp, "System Error hashing password", locale);
return; return;
} }
...@@ -354,7 +354,7 @@ public class LoginServlet extends HttpServlet { ...@@ -354,7 +354,7 @@ public class LoginServlet extends HttpServlet {
String hash = user.getPassword(); String hash = user.getPassword();
if ((hash == null) || hash.equals("")) { if ((hash == null) || hash.equals("")) {
fail(req, resp, "No Password Set for User"); fail(req, resp, "No Password Set for User", locale);
return; return;
} }
...@@ -365,7 +365,7 @@ public class LoginServlet extends HttpServlet { ...@@ -365,7 +365,7 @@ public class LoginServlet extends HttpServlet {
} }
if (!validLogin) { if (!validLogin) {
fail(req, resp, bundle.getString("invalidpassword")); fail(req, resp, bundle.getString("invalidpassword"), locale);
return; return;
} }
...@@ -440,8 +440,8 @@ public class LoginServlet extends HttpServlet { ...@@ -440,8 +440,8 @@ public class LoginServlet extends HttpServlet {
return sb.toString(); return sb.toString();
} }
private void fail(HttpServletRequest req, HttpServletResponse resp, String error) throws IOException { private void fail(HttpServletRequest req, HttpServletResponse resp, String error, String locale) throws IOException {
resp.sendRedirect("/login/?error=" + sanitizer.sanitize(error)); resp.sendRedirect("/login/?locale=" + sanitizer.sanitize(locale) + "&error=" + sanitizer.sanitize(error));
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment