This commit is contained in:
Tienan Chen 2013-09-06 11:37:31 +08:00
parent f7276b4777
commit 05d26a3810
1 changed files with 88 additions and 85 deletions

View File

@ -32,35 +32,29 @@ public class AuthorizeActionController extends BaseActionController {
return resultModel;
}
@RequestMapping("login.do")
public String login(UserModel user, ModelMap model) throws IOException, JAXBException {
public String login(UserModel user, ModelMap model) throws IOException,
JAXBException {
System.out.println("enter authorize");
String urlString = masterIP + "user/authorize";
String username = user.getUsername();
String password = user.getPassword();
Map<String, String> params = new HashMap<String, String>();
params.put("userName", username);
params.put("password", password);
HttpRequester httpRequester = new HttpRequester();
HttpResponse httpResponse = httpRequester.sendGet(urlString,
params, null);
AuthorizeResponseModel authorizeResponseModel = extractAuthorizeResponseModel(httpResponse
.getContent());
AuthorizeResponseModel authorizeResponseModel = authorize(user);
if (authorizeResponseModel.isSuccess()) {
System.out.println("success");
model.addAttribute("accessToken", authorizeResponseModel.getAccessToken());
model.addAttribute("username", username);
model.addAttribute("accessToken",
authorizeResponseModel.getAccessToken());
model.addAttribute("username", user.getUsername());
return "homepage";
} else {
model.addAttribute("rtmsg", "somthing is wrong with the password, please try again.");
model.addAttribute("rtmsg",
"somthing is wrong with the password, please try again.");
return "userlogin";
}
}
@RequestMapping("adminlogin.do")
public String adminlogin (UserModel user, ModelMap model) throws IOException, JAXBException{
System.out.println("enter admin authorize");
private AuthorizeResponseModel authorize(UserModel user)
throws IOException, JAXBException {
String urlString = masterIP + "user/authorize";
String username = user.getUsername();
String password = user.getPassword();
@ -68,16 +62,25 @@ public class AuthorizeActionController extends BaseActionController {
params.put("userName", username);
params.put("password", password);
HttpRequester httpRequester = new HttpRequester();
HttpResponse httpResponse = httpRequester.sendGet(urlString,
params, null);
AuthorizeResponseModel authorizeResponseModel = extractAuthorizeResponseModel(httpResponse
.getContent());
HttpResponse httpResponse = httpRequester.sendGet(urlString, params,
null);
return extractAuthorizeResponseModel(httpResponse.getContent());
}
@RequestMapping("adminlogin.do")
public String adminlogin(UserModel user, ModelMap model)
throws IOException, JAXBException {
System.out.println("enter admin authorize");
AuthorizeResponseModel authorizeResponseModel = authorize(user);
if (authorizeResponseModel.isSuccess()) {
System.out.println("success");
model.addAttribute("accessToken", authorizeResponseModel.getAccessToken());
model.addAttribute("accessToken",
authorizeResponseModel.getAccessToken());
return "admin";
} else {
model.addAttribute("rtmsg", "somthing is wrong with the password, please try again.");
model.addAttribute("rtmsg",
"somthing is wrong with the password, please try again.");
return "adminlogin";
}
}