Subversion Repositories SmartDukaan

Rev

Rev 24984 | Rev 25009 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24984 Rev 25008
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.time.LocalDateTime;
4
import java.time.LocalDateTime;
4
import java.util.ArrayList;
5
import java.util.ArrayList;
-
 
6
import java.util.HashMap;
5
import java.util.HashSet;
7
import java.util.HashSet;
6
import java.util.List;
8
import java.util.List;
-
 
9
import java.util.Map;
7
import java.util.Set;
10
import java.util.Set;
8
import java.util.stream.Collectors;
11
import java.util.stream.Collectors;
9
 
12
 
10
import javax.servlet.http.Cookie;
13
import javax.servlet.http.Cookie;
11
import javax.servlet.http.HttpServletRequest;
14
import javax.servlet.http.HttpServletRequest;
Line 13... Line 16...
13
 
16
 
14
import org.apache.logging.log4j.LogManager;
17
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
18
import org.apache.logging.log4j.Logger;
16
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Value;
20
import org.springframework.beans.factory.annotation.Value;
-
 
21
import org.springframework.http.HttpStatus;
-
 
22
import org.springframework.http.ResponseEntity;
18
import org.springframework.stereotype.Controller;
23
import org.springframework.stereotype.Controller;
19
import org.springframework.transaction.annotation.Transactional;
24
import org.springframework.transaction.annotation.Transactional;
20
import org.springframework.ui.Model;
25
import org.springframework.ui.Model;
21
import org.springframework.ui.ModelMap;
26
import org.springframework.ui.ModelMap;
22
import org.springframework.web.bind.annotation.ModelAttribute;
27
import org.springframework.web.bind.annotation.ModelAttribute;
Line 24... Line 29...
24
import org.springframework.web.bind.annotation.RequestBody;
29
import org.springframework.web.bind.annotation.RequestBody;
25
import org.springframework.web.bind.annotation.RequestMapping;
30
import org.springframework.web.bind.annotation.RequestMapping;
26
import org.springframework.web.bind.annotation.RequestMethod;
31
import org.springframework.web.bind.annotation.RequestMethod;
27
import org.springframework.web.bind.annotation.RequestParam;
32
import org.springframework.web.bind.annotation.RequestParam;
28
 
33
 
-
 
34
import com.google.gson.Gson;
-
 
35
import com.google.gson.reflect.TypeToken;
29
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
36
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
30
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
31
import com.spice.profitmandi.common.model.Location;
37
import com.spice.profitmandi.common.model.Location;
32
import com.spice.profitmandi.common.model.ProfitMandiConstants;
38
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
39
import com.spice.profitmandi.common.web.client.RestClient;
33
import com.spice.profitmandi.dao.entity.auth.AuthUser;
40
import com.spice.profitmandi.dao.entity.auth.AuthUser;
34
import com.spice.profitmandi.dao.entity.dtr.Retailer;
41
import com.spice.profitmandi.dao.entity.dtr.Retailer;
35
import com.spice.profitmandi.dao.entity.dtr.Role;
42
import com.spice.profitmandi.dao.entity.dtr.Role;
36
import com.spice.profitmandi.dao.entity.dtr.User;
43
import com.spice.profitmandi.dao.entity.dtr.User;
37
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
44
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
38
import com.spice.profitmandi.dao.entity.dtr.UserRole;
45
import com.spice.profitmandi.dao.entity.dtr.UserRole;
39
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
46
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
40
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
47
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
41
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
48
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
42
import com.spice.profitmandi.dao.model.UserCart;
-
 
43
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
49
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
44
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
50
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
45
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
51
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
46
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
52
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
47
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
53
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
Line 88... Line 94...
88
	@Autowired
94
	@Autowired
89
	private FofoStoreRepository fofoStoreRepository;
95
	private FofoStoreRepository fofoStoreRepository;
90
 
96
 
91
	@Autowired
97
	@Autowired
92
	private MVCResponseSender mvcResponseSender;
98
	private MVCResponseSender mvcResponseSender;
-
 
99
	
-
 
100
	@Autowired
-
 
101
	private RestClient restClient;
93
 
102
 
94
	@Autowired
103
	@Autowired
95
	private CookiesProcessor cookiesProcessor;
104
	private CookiesProcessor cookiesProcessor;
96
 
105
 
97
	@Value("${google.api.key}")
106
	@Value("${google.api.key}")
Line 131... Line 140...
131
 
140
 
132
	@RequestMapping(value = "/", method = RequestMethod.GET)
141
	@RequestMapping(value = "/", method = RequestMethod.GET)
133
	public String home() {
142
	public String home() {
134
		return "redirect:/login";
143
		return "redirect:/login";
135
	}
144
	}
-
 
145
	
-
 
146
	@RequestMapping(value = "/mobileapp", method = RequestMethod.GET)
-
 
147
	public String mobileApp(HttpServletRequest request, Model model) throws Exception {
-
 
148
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
149
		if(roleManager.isAdmin(fofoDetails.getRoleIds())) {
-
 
150
			model.addAttribute("authToken", getToken(fofoDetails.getEmailId()));
-
 
151
		}
-
 
152
		return "mobileapp";
-
 
153
	}
136
 
154
 
-
 
155
	private String getToken(String emailId) throws Exception {
-
 
156
		Map<String, String> params = new HashMap<>();
-
 
157
		params.put("adminToken", "ecip$stgMay2014");
-
 
158
		params.put("emailId", emailId);
-
 
159
		String response = restClient.post("http://app.profitmandi.com:8080/user/admin", params, new HashMap<>());
-
 
160
		Type t = new TypeToken<ResponseEntity<Map<String,String>>>() {}.getType();
-
 
161
		ResponseEntity<Map<String,Object>> apiResponse = new Gson().fromJson(response, t);
-
 
162
		if(apiResponse.getStatusCode()==HttpStatus.OK) {
-
 
163
			return (String)apiResponse.getBody().get("token");
-
 
164
		} else {
-
 
165
			throw new Exception("Unauthorise access");
-
 
166
		}
-
 
167
		
-
 
168
	}
137
	@RequestMapping(value = "/login-as-partner", method = RequestMethod.GET)
169
	@RequestMapping(value = "/login-as-partner", method = RequestMethod.GET)
138
	public String adminLogin(HttpServletRequest request, Model model, HttpServletResponse response,
170
	public String adminLogin(HttpServletRequest request, Model model, HttpServletResponse response,
139
			@RequestParam int fofoId) throws Exception {
171
			@RequestParam int fofoId) throws Exception {
140
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
172
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
141
		if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
173
		if (roleManager.isAdmin(fofoDetails.getRoleIds())) {