| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.lang.reflect.Type;
|
3 |
import java.lang.reflect.Type;
|
| - |
|
4 |
import java.nio.charset.Charset;
|
| 4 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 5 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 6 |
import java.util.HashMap;
|
7 |
import java.util.HashMap;
|
| 7 |
import java.util.HashSet;
|
8 |
import java.util.HashSet;
|
| 8 |
import java.util.List;
|
9 |
import java.util.List;
|
| Line 12... |
Line 13... |
| 12 |
|
13 |
|
| 13 |
import javax.servlet.http.Cookie;
|
14 |
import javax.servlet.http.Cookie;
|
| 14 |
import javax.servlet.http.HttpServletRequest;
|
15 |
import javax.servlet.http.HttpServletRequest;
|
| 15 |
import javax.servlet.http.HttpServletResponse;
|
16 |
import javax.servlet.http.HttpServletResponse;
|
| 16 |
|
17 |
|
| - |
|
18 |
import org.apache.http.NameValuePair;
|
| - |
|
19 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| - |
|
20 |
import org.apache.http.client.utils.URIBuilder;
|
| - |
|
21 |
import org.apache.http.client.utils.URLEncodedUtils;
|
| - |
|
22 |
import org.apache.http.message.BasicNameValuePair;
|
| 17 |
import org.apache.logging.log4j.LogManager;
|
23 |
import org.apache.logging.log4j.LogManager;
|
| 18 |
import org.apache.logging.log4j.Logger;
|
24 |
import org.apache.logging.log4j.Logger;
|
| 19 |
import org.springframework.beans.factory.annotation.Autowired;
|
25 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 20 |
import org.springframework.beans.factory.annotation.Value;
|
26 |
import org.springframework.beans.factory.annotation.Value;
|
| - |
|
27 |
import org.springframework.beans.propertyeditors.URLEditor;
|
| 21 |
import org.springframework.http.HttpStatus;
|
28 |
import org.springframework.http.HttpStatus;
|
| 22 |
import org.springframework.http.ResponseEntity;
|
29 |
import org.springframework.http.ResponseEntity;
|
| 23 |
import org.springframework.stereotype.Controller;
|
30 |
import org.springframework.stereotype.Controller;
|
| 24 |
import org.springframework.transaction.annotation.Transactional;
|
31 |
import org.springframework.transaction.annotation.Transactional;
|
| 25 |
import org.springframework.ui.Model;
|
32 |
import org.springframework.ui.Model;
|
| Line 151... |
Line 158... |
| 151 |
}
|
158 |
}
|
| 152 |
return "mobileapp";
|
159 |
return "mobileapp";
|
| 153 |
}
|
160 |
}
|
| 154 |
|
161 |
|
| 155 |
private String getToken(String emailId) throws Exception {
|
162 |
private String getToken(String emailId) throws Exception {
|
| 156 |
Map<String, String> params = new HashMap<>();
|
163 |
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
| 157 |
params.put("adminToken", "ecip$stgMay2014");
|
164 |
nameValuePairs.add(new BasicNameValuePair("adminToken", "ecip$stgMay2014"));
|
| 158 |
params.put("emailId", emailId);
|
165 |
nameValuePairs.add(new BasicNameValuePair("emailId", "acad.amitgupta@gmail.com"));
|
| - |
|
166 |
String queryString=URLEncodedUtils.format(nameValuePairs, "UTF-8");
|
| 159 |
String response = restClient.post("http://app.profitmandi.com:8080/user/admin", params, new HashMap<>());
|
167 |
String response = restClient.post("http://app.profitmandi.com:8080/user/admin?" + queryString, new HashMap<>(), new HashMap<>());
|
| 160 |
Type t = new TypeToken<ResponseEntity<Map<String,String>>>() {}.getType();
|
168 |
Type t = new TypeToken<ResponseEntity<Map<String,String>>>() {}.getType();
|
| 161 |
ResponseEntity<Map<String,Object>> apiResponse = new Gson().fromJson(response, t);
|
169 |
ResponseEntity<Map<String,Object>> apiResponse = new Gson().fromJson(response, t);
|
| 162 |
if(apiResponse.getStatusCode()==HttpStatus.OK) {
|
170 |
if(apiResponse.getStatusCode()==HttpStatus.OK) {
|
| 163 |
return (String)apiResponse.getBody().get("token");
|
171 |
return (String)apiResponse.getBody().get("token");
|
| 164 |
} else {
|
172 |
} else {
|
| 165 |
throw new Exception("Unauthorise access");
|
173 |
throw new Exception("Unauthorised access");
|
| 166 |
}
|
174 |
}
|
| 167 |
|
175 |
|
| 168 |
}
|
176 |
}
|
| 169 |
@RequestMapping(value = "/login-as-partner", method = RequestMethod.GET)
|
177 |
@RequestMapping(value = "/login-as-partner", method = RequestMethod.GET)
|
| 170 |
public String adminLogin(HttpServletRequest request, Model model, HttpServletResponse response,
|
178 |
public String adminLogin(HttpServletRequest request, Model model, HttpServletResponse response,
|