diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/api/AuthorizeActionController.java b/Bench4Q-Web/src/main/java/org/bench4q/web/api/AuthorizeActionController.java deleted file mode 100644 index 07acd60c..00000000 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/api/AuthorizeActionController.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.bench4q.web.api; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.xml.bind.JAXBException; - -import org.apache.log4j.Logger; -import org.bench4q.share.communication.HttpRequester; -import org.bench4q.share.communication.HttpRequester.HttpResponse; -import org.bench4q.share.models.master.AuthorizeResponseModel; -import org.bench4q.share.models.master.RegisterResponseModel; -import org.bench4q.share.models.master.UserModel; -import org.bench4q.web.exception.CustomGenericException; -import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange; -import org.bench4q.web.model.BaseResponseModel; -import org.bench4q.web.model.TestPlanTaskModel; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.SessionAttributes; - -@Controller -@SessionAttributes({ "accessToken", "username", "testPlanTaskList" }) -public class AuthorizeActionController extends BaseControllerService { - private Logger logger = Logger.getLogger(AuthorizeActionController.class); - private String baseUrl = this.masterIp + "user"; - private String INVALIDATE_INPUT = "invalidate input"; - - @RequestMapping("login") - public @ResponseBody - BaseResponseModel login(UserModel user, ModelMap model) - throws CustomGenericException { - isValidate(user); - AuthorizeResponseModel authorizeResponseModel = authorize(baseUrl - + "/normalAuthorize", user); - return extractAuthorizeResponseModel(authorizeResponseModel, user, - model); - } - - @RequestMapping("adminLogin") - public @ResponseBody - BaseResponseModel adminLogin(UserModel user, ModelMap model) - throws CustomGenericException { - isValidate(user); - - AuthorizeResponseModel authorizeResponseModel = authorize(baseUrl - + "/adminAuthorize", user); - return extractAuthorizeResponseModel(authorizeResponseModel, user, - model); - } - - @RequestMapping("register") - @ResponseBody - public BaseResponseModel register(@RequestParam String userName, - @RequestParam String password, @RequestParam String scope) - throws CustomGenericException { - UserModel user = new UserModel(); - user.setUserName(userName); - user.setPassword(password); - isValidate(user); - Map params = this.makeParamsMap("userName", - user.getUserName()); - params.put("password", user.getPassword()); - params.put("scope", scope); - try { - - HttpResponse httpResponse = this.getHttpRequester().sendGet( - baseUrl + "/register", params, null); - if (HttpRequester.isInvalidResponse(httpResponse)) { - throw new CustomGenericException("0", - "invalidate httpResponse", - "AuthorizeActionController_register"); - } - RegisterResponseModel registerResponseModel = (RegisterResponseModel) ObjectXmlExchange - .fromXml(RegisterResponseModel.class, - httpResponse.getContent()); - return extractRegisterModel(registerResponseModel); - } catch (IOException e) { - logger.info(e, e.fillInStackTrace()); - throw new CustomGenericException("1", - "invalidate httpresponse:io exception", this.baseUrl - + "/register"); - } catch (JAXBException e) { - logger.info(e, e.fillInStackTrace()); - throw new CustomGenericException("1", - "invalidate httpresponse:JAXBException", this.baseUrl - + "/register"); - } - - } - - private AuthorizeResponseModel authorize(String url, UserModel user) - throws CustomGenericException { - try { - Map params = this.makeParamsMap("userName", - user.getUserName()); - params.put("password", user.getPassword()); - HttpResponse httpResponse = this.getHttpRequester().sendGet(url, - params, null); - if (HttpRequester.isInvalidResponse(httpResponse)) { - throw new CustomGenericException("1", "network error:", - "AuthorizeActionController_authorize"); - } - - return (AuthorizeResponseModel) ObjectXmlExchange.fromXml( - AuthorizeResponseModel.class, httpResponse.getContent()); - } catch (IOException e) { - logger.info(e, e.fillInStackTrace()); - throw new CustomGenericException("1", - "invalidate httpResponse:IOException", - "AuthorizeActionController_authorize"); - } catch (JAXBException e) { - logger.info(e, e.fillInStackTrace()); - throw new CustomGenericException("1", - "invalidate httpResponse:JAXBException", - "AuthorizeActionController_authorize"); - } - } - - private BaseResponseModel extractAuthorizeResponseModel( - AuthorizeResponseModel authorizeResponseModel, UserModel user, - ModelMap model) { - - if (!authorizeResponseModel.isSuccess()) { - logger.info("user name:" + user.getUserName()); - logger.info("user password:" + user.getPassword()); - logger.info("password or name wrong"); - return new BaseResponseModel(false, "password or name wrong!"); - } else { - model.addAttribute("accessToken", - authorizeResponseModel.getAccessToken()); - model.addAttribute("username", user.getUserName()); - List testPlanTaskModels = new ArrayList(); - model.addAttribute("testPlanTaskList", testPlanTaskModels); - return new BaseResponseModel(true); - } - - } - - private BaseResponseModel extractRegisterModel( - RegisterResponseModel registerResponseModel) { - - if (registerResponseModel.isSuccess()) - return new BaseResponseModel(true); - - else - return new BaseResponseModel(false, ""); - } - - private void isValidate(UserModel user) throws CustomGenericException { - if (user.getPassword() == null || user.getUserName() == null - || user.getPassword().equals("") - || user.getUserName().equals("")) - throw new CustomGenericException("0", INVALIDATE_INPUT, ""); - } - -} diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/newapi/UserController.java b/Bench4Q-Web/src/main/java/org/bench4q/web/api/UserController.java similarity index 89% rename from Bench4Q-Web/src/main/java/org/bench4q/web/newapi/UserController.java rename to Bench4Q-Web/src/main/java/org/bench4q/web/api/UserController.java index 0597a585..b524c470 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/newapi/UserController.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/api/UserController.java @@ -1,4 +1,4 @@ -package org.bench4q.web.newapi; +package org.bench4q.web.api; import java.util.ArrayList; import java.util.HashMap; @@ -10,16 +10,19 @@ import org.bench4q.share.models.master.RegisterResponseModel; import org.bench4q.share.models.master.UserModel; import org.bench4q.web.masterMessager.UserMessager; import org.bench4q.web.model.TestPlanTaskModel; +import org.bench4q.web.newapi.BaseController; import org.bench4q.web.validation.UserValidate; import org.bench4q.web.validation.ValidateResponseModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.SessionAttributes; +@Controller @SessionAttributes({ "accessToken", "username", "testPlanTaskList" }) public class UserController extends BaseController { @@ -50,7 +53,7 @@ public class UserController extends BaseController { @RequestParam String password, @RequestParam String scope) { Map map = new HashMap(); ValidateResponseModel validateResponseModel = this.getUserValidate() - .validateRegisterUser(userName, password, scope); + .validateRegisterUser(userName, password, scope); if (!validateResponseModel.isSuccess()) { return fail(map, validateResponseModel.getMessage()); } @@ -65,10 +68,9 @@ public class UserController extends BaseController { } - @RequestMapping("normalLogin") + @RequestMapping("login") @ResponseBody - public Map normalLogin(UserModel userModel, - ModelMap modelMap) { + public Map normalLogin(UserModel userModel, ModelMap modelMap) { Map map = new HashMap(); ValidateResponseModel validateResponseModel = this.getUserValidate() .validateUserLogin(userModel.getUserName(), @@ -78,6 +80,7 @@ public class UserController extends BaseController { } AuthorizeResponseModel authorizeResponseModel = this.getUserMessager() .normalLogin(userModel.getUserName(), userModel.getPassword()); + System.out.println(authorizeResponseModel.isSuccess()); if (authorizeResponseModel.isSuccess()) { updateSessionAttribute(modelMap, authorizeResponseModel, userModel.getUserName()); diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/newapi/AgentController.java b/Bench4Q-Web/src/main/java/org/bench4q/web/newapi/AgentController.java index e15c3915..0391ed13 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/newapi/AgentController.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/newapi/AgentController.java @@ -11,7 +11,6 @@ import org.bench4q.web.masterMessager.AgentManagerMessager; import org.bench4q.web.validation.AgentValidate; import org.bench4q.web.validation.ValidateResponseModel; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; diff --git a/Bench4Q-Web/src/main/webapp/script/login.js b/Bench4Q-Web/src/main/webapp/script/login.js index 6e650cc1..d725f3b8 100644 --- a/Bench4Q-Web/src/main/webapp/script/login.js +++ b/Bench4Q-Web/src/main/webapp/script/login.js @@ -1,5 +1,4 @@ - function checkName(name) { if (name == '') { @@ -24,22 +23,21 @@ function checkPass(password) { } } - $("body").keydown(function(e) { - var ee = e || window.event; - if(ee.keyCode == 13){ - login(); - } + var ee = e || window.event; + if (ee.keyCode == 13) { + login(); + } }); function login() { var userName = $('#username').val(); var password = $('#password').val(); - $.post('normalLogin', { + $.post('login', { userName : userName, password : password }, function(data) { - + if (data.success) { $('#loginMsg').hide(); window.location.replace("homepage.jsp"); @@ -49,7 +47,7 @@ function login() { else { alert(data.failedMessage); } - },"json"); + }, "json"); } function adminLogin() { @@ -83,7 +81,7 @@ function register() { $.post('register', { userName : userName, password : password, - rePassword:rePassword + rePassword : rePassword }, function(data) { if (data.success) { $('#registerMsg').hide(); @@ -99,6 +97,12 @@ function register() { }, "json"); } -$("#img").mouseover(function(){document.getElementById("img").setAttribute("src", "img/githubsignon1.jpg");}); +$("#img").mouseover( + function() { + document.getElementById("img").setAttribute("src", + "img/githubsignon1.jpg"); + }); -$("#img").mouseout(function(){document.getElementById("img").setAttribute("src", "img/githubsignon.jpg");}); +$("#img").mouseout(function() { + document.getElementById("img").setAttribute("src", "img/githubsignon.jpg"); +});