| Line 1... |
Line 1... |
| 1 |
package in.shop2020.serving.interceptors;
|
1 |
package in.shop2020.serving.interceptors;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.serving.services.UserSessionInfo;
|
3 |
import in.shop2020.serving.services.UserSessionInfo;
|
| - |
|
4 |
import in.shop2020.serving.utils.Utils;
|
| - |
|
5 |
|
| - |
|
6 |
import java.util.HashMap;
|
| - |
|
7 |
import java.util.Map;
|
| 4 |
|
8 |
|
| 5 |
import javax.servlet.http.HttpServletRequest;
|
9 |
import javax.servlet.http.HttpServletRequest;
|
| 6 |
import javax.servlet.http.HttpServletResponse;
|
10 |
import javax.servlet.http.HttpServletResponse;
|
| 7 |
|
11 |
|
| 8 |
import org.apache.commons.codec.binary.Base64;
|
12 |
import org.apache.commons.codec.binary.Base64;
|
| 9 |
import org.apache.log4j.Logger;
|
13 |
import org.apache.log4j.Logger;
|
| 10 |
import org.apache.struts2.ServletActionContext;
|
14 |
import org.apache.struts2.ServletActionContext;
|
| - |
|
15 |
import org.json.JSONObject;
|
| 11 |
|
16 |
|
| 12 |
import com.opensymphony.xwork2.ActionInvocation;
|
17 |
import com.opensymphony.xwork2.ActionInvocation;
|
| 13 |
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
18 |
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
| 14 |
|
19 |
|
| - |
|
20 |
import de.ailis.pherialize.Pherialize;
|
| - |
|
21 |
|
| 15 |
public class LoginInterceptor extends AbstractInterceptor {
|
22 |
public class LoginInterceptor extends AbstractInterceptor {
|
| 16 |
|
23 |
|
| 17 |
|
24 |
|
| 18 |
/**
|
25 |
/**
|
| 19 |
*
|
26 |
*
|
| Line 26... |
Line 33... |
| 26 |
HttpServletRequest request = ServletActionContext.getRequest();
|
33 |
HttpServletRequest request = ServletActionContext.getRequest();
|
| 27 |
HttpServletResponse response = ServletActionContext.getResponse();
|
34 |
HttpServletResponse response = ServletActionContext.getResponse();
|
| 28 |
|
35 |
|
| 29 |
UserSessionInfo userInfo = (UserSessionInfo) request.getAttribute(UserInterceptor.USER_INFO_COOKIE_NAME);
|
36 |
UserSessionInfo userInfo = (UserSessionInfo) request.getAttribute(UserInterceptor.USER_INFO_COOKIE_NAME);
|
| 30 |
if(userInfo.isPrivateDealUser()){
|
37 |
if(userInfo.isPrivateDealUser()){
|
| 31 |
String next = request.getContextPath();
|
- |
|
| 32 |
System.out.println(next);
|
- |
|
| 33 |
//response.sendRedirect(getMobileRedirectUrl(userInfo.getUserId(), next));
|
38 |
response.sendRedirect(getMobileRedirectUrl(String.valueOf(userInfo.getUserId()), request));
|
| - |
|
39 |
return null;
|
| 34 |
}
|
40 |
}
|
| 35 |
if(userInfo == null || !userInfo.isLoggedIn()){
|
41 |
if(userInfo == null || !userInfo.isLoggedIn()){
|
| 36 |
response.sendRedirect("/login?redirectUrl=" + getRedirectUrl(request));
|
42 |
response.sendRedirect("/login?redirectUrl=" + getRedirectUrl(request));
|
| 37 |
return null;
|
43 |
return null;
|
| 38 |
}
|
44 |
}
|
| 39 |
return invocation.invoke();
|
45 |
return invocation.invoke();
|
| 40 |
}
|
46 |
}
|
| 41 |
|
47 |
|
| 42 |
/*String getMobileRedirectUrl(long userId){
|
48 |
String getMobileRedirectUrl(String userId, HttpServletRequest request){
|
| - |
|
49 |
UserSessionInfo userInfo = (UserSessionInfo) request.getAttribute(UserInterceptor.USER_INFO_COOKIE_NAME);
|
| 43 |
return "";
|
50 |
String next = "cart";
|
| - |
|
51 |
log.info("next " + next);
|
| - |
|
52 |
String serverName = request.getServerName().replaceFirst("www", "m");
|
| - |
|
53 |
try {
|
| - |
|
54 |
String authUrl = "http://localhost:8080/mobileapi/login!authorizeProfitMandiUser?userId=" +
|
| - |
|
55 |
String.valueOf(userInfo.getUserId()) + "&source=Saholic";
|
| - |
|
56 |
String urlResponse = Utils.fetchUrl(authUrl);
|
| - |
|
57 |
JSONObject responseToken = new JSONObject(urlResponse);
|
| - |
|
58 |
String token = responseToken.getString("tokenString");
|
| - |
|
59 |
log.info("token " +token);
|
| - |
|
60 |
|
| - |
|
61 |
|
| - |
|
62 |
Map<String, Object> mapData = new HashMap<String, Object>();
|
| - |
|
63 |
mapData.put("next", next);
|
| - |
|
64 |
mapData.put("Id", userId);
|
| - |
|
65 |
mapData.put("cartId", userInfo.getCartId());
|
| - |
|
66 |
mapData.put("email", userInfo.getEmail());
|
| - |
|
67 |
mapData.put("isPrivateDealUser", userInfo.isPrivateDealUser());
|
| 44 |
String data = "?data=" + Base64.encodeBase64String((serialize($data)));
|
68 |
String data = Base64.encodeBase64String(Pherialize.serialize(mapData).getBytes());
|
| - |
|
69 |
|
| 45 |
$token = '&token='.md5(Configure::read('saholicapikey').'|'.$user['UserAccount'][0]['account_key']);
|
70 |
String url = "http://" + serverName + "/autologin/?data=" + data + "&token=" + token + "&v=2";
|
| - |
|
71 |
log.info("url " + url);
|
| - |
|
72 |
return url;
|
| - |
|
73 |
} catch (Exception e) {
|
| - |
|
74 |
log.info("Could not parse", e);
|
| - |
|
75 |
log.info(next);
|
| - |
|
76 |
return "http://" + serverName + "/" + next;
|
| - |
|
77 |
}
|
| 46 |
}*/
|
78 |
}
|
| 47 |
|
79 |
|
| 48 |
public String getRedirectUrl(HttpServletRequest request) {
|
80 |
public String getRedirectUrl(HttpServletRequest request) {
|
| 49 |
String queryString = request.getQueryString();
|
81 |
String queryString = request.getQueryString();
|
| 50 |
if (queryString == null) {
|
82 |
if (queryString == null) {
|
| 51 |
queryString = "";
|
83 |
queryString = "";
|