| 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;
|
- |
|
| 5 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| 6 |
import java.util.ArrayList;
|
5 |
import java.util.ArrayList;
|
| 7 |
import java.util.HashMap;
|
6 |
import java.util.HashMap;
|
| 8 |
import java.util.HashSet;
|
7 |
import java.util.HashSet;
|
| 9 |
import java.util.List;
|
8 |
import java.util.List;
|
| Line 14... |
Line 13... |
| 14 |
import javax.servlet.http.Cookie;
|
13 |
import javax.servlet.http.Cookie;
|
| 15 |
import javax.servlet.http.HttpServletRequest;
|
14 |
import javax.servlet.http.HttpServletRequest;
|
| 16 |
import javax.servlet.http.HttpServletResponse;
|
15 |
import javax.servlet.http.HttpServletResponse;
|
| 17 |
|
16 |
|
| 18 |
import org.apache.http.NameValuePair;
|
17 |
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;
|
18 |
import org.apache.http.client.utils.URLEncodedUtils;
|
| 22 |
import org.apache.http.message.BasicNameValuePair;
|
19 |
import org.apache.http.message.BasicNameValuePair;
|
| 23 |
import org.apache.logging.log4j.LogManager;
|
20 |
import org.apache.logging.log4j.LogManager;
|
| 24 |
import org.apache.logging.log4j.Logger;
|
21 |
import org.apache.logging.log4j.Logger;
|
| 25 |
import org.springframework.beans.factory.annotation.Autowired;
|
22 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 26 |
import org.springframework.beans.factory.annotation.Value;
|
23 |
import org.springframework.beans.factory.annotation.Value;
|
| 27 |
import org.springframework.beans.propertyeditors.URLEditor;
|
- |
|
| 28 |
import org.springframework.http.HttpStatus;
|
- |
|
| 29 |
import org.springframework.http.ResponseEntity;
|
- |
|
| 30 |
import org.springframework.stereotype.Controller;
|
24 |
import org.springframework.stereotype.Controller;
|
| 31 |
import org.springframework.transaction.annotation.Transactional;
|
25 |
import org.springframework.transaction.annotation.Transactional;
|
| 32 |
import org.springframework.ui.Model;
|
26 |
import org.springframework.ui.Model;
|
| 33 |
import org.springframework.ui.ModelMap;
|
27 |
import org.springframework.ui.ModelMap;
|
| 34 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
28 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
| Line 41... |
Line 35... |
| 41 |
import com.google.gson.Gson;
|
35 |
import com.google.gson.Gson;
|
| 42 |
import com.google.gson.reflect.TypeToken;
|
36 |
import com.google.gson.reflect.TypeToken;
|
| 43 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
37 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 44 |
import com.spice.profitmandi.common.model.Location;
|
38 |
import com.spice.profitmandi.common.model.Location;
|
| 45 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
39 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
40 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
| 46 |
import com.spice.profitmandi.common.web.client.RestClient;
|
41 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 47 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
42 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 48 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
43 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 49 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
44 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 50 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
45 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| Line 160... |
Line 155... |
| 160 |
}
|
155 |
}
|
| 161 |
|
156 |
|
| 162 |
private String getToken(String emailId) throws Exception {
|
157 |
private String getToken(String emailId) throws Exception {
|
| 163 |
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
158 |
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
| 164 |
nameValuePairs.add(new BasicNameValuePair("adminToken", "ecip$stgMay2014"));
|
159 |
nameValuePairs.add(new BasicNameValuePair("adminToken", "ecip$stgMay2014"));
|
| 165 |
nameValuePairs.add(new BasicNameValuePair("emailId", "acad.amitgupta@gmail.com"));
|
160 |
nameValuePairs.add(new BasicNameValuePair("emailId", emailId));
|
| 166 |
String queryString=URLEncodedUtils.format(nameValuePairs, "UTF-8");
|
161 |
String queryString=URLEncodedUtils.format(nameValuePairs, "UTF-8");
|
| 167 |
String response = restClient.post("http://app.profitmandi.com:8080/user/admin?" + queryString, new HashMap<>(), new HashMap<>());
|
162 |
String response = restClient.post("http://app.profitmandi.com:8080/profitmandi-web/user/admin?" + queryString, new HashMap<>(), new HashMap<>());
|
| 168 |
Type t = new TypeToken<ResponseEntity<Map<String,String>>>() {}.getType();
|
163 |
Type t = new TypeToken<ProfitMandiResponse<Map<String,Object>>>() {}.getType();
|
| 169 |
ResponseEntity<Map<String,Object>> apiResponse = new Gson().fromJson(response, t);
|
164 |
ProfitMandiResponse <Map<String,Object>> apiResponse = new Gson().fromJson(response, t);
|
| 170 |
if(apiResponse.getStatusCode()==HttpStatus.OK) {
|
165 |
if(apiResponse.getStatusCode().equals("200")) {
|
| 171 |
return (String)apiResponse.getBody().get("token");
|
166 |
return (new StringBuilder((String)apiResponse.getResponse().get("token")).reverse().toString());
|
| 172 |
} else {
|
167 |
} else {
|
| 173 |
throw new Exception("Unauthorised access");
|
168 |
throw new Exception("Unauthorised access");
|
| 174 |
}
|
169 |
}
|
| 175 |
|
170 |
|
| 176 |
}
|
171 |
}
|