Subversion Repositories SmartDukaan

Rev

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

Rev 2209 Rev 2449
Line 4... Line 4...
4
 
4
 
5
import in.shop2020.hotspot.dashbaord.shared.actions.AuthRequest;
5
import in.shop2020.hotspot.dashbaord.shared.actions.AuthRequest;
6
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse;
6
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse;
7
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse.NEXT;
7
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse.NEXT;
8
import in.shop2020.thrift.clients.HelperServiceClient;
8
import in.shop2020.thrift.clients.HelperServiceClient;
-
 
9
import in.shop2020.utils.DashboardUser;
9
import in.shop2020.utils.HelperService.Client;
10
import in.shop2020.utils.HelperService.Client;
10
import in.shop2020.utils.HelperServiceException;
11
import in.shop2020.utils.HelperServiceException;
11
import net.customware.gwt.dispatch.server.ActionHandler;
12
import net.customware.gwt.dispatch.server.ActionHandler;
12
import net.customware.gwt.dispatch.server.ExecutionContext;
13
import net.customware.gwt.dispatch.server.ExecutionContext;
13
import net.customware.gwt.dispatch.shared.ActionException;
14
import net.customware.gwt.dispatch.shared.ActionException;
14
 
15
 
15
public class AuthHandler implements ActionHandler<AuthRequest, AuthResponse>{
16
public class AuthHandler implements ActionHandler<AuthRequest, AuthResponse>{
16
 
17
 
17
	@Override
18
	@Override
18
	public AuthResponse execute(AuthRequest request, ExecutionContext response)
19
	public AuthResponse execute(AuthRequest request, ExecutionContext response)	throws ActionException {
19
			throws ActionException {
-
 
20
		String userName = request.getUsername();
20
		String userName = request.getUsername();
21
		String password = request.getPassword();
21
		String password = request.getPassword();
22
 
-
 
23
		
-
 
24
		
22
		
-
 
23
		boolean status = false;
-
 
24
		long warehouseId = -1;
-
 
25
		boolean isAdmin = false;
25
		HelperServiceClient hsc = null;
26
		NEXT nextScreen = null;
26
		Client client = null;
27
		String message = null;
27
		
28
		
28
		try {
29
		try {
29
			hsc = new HelperServiceClient();
30
			HelperServiceClient hsc = new HelperServiceClient();
30
			client =  hsc.getClient();
31
			Client client =  hsc.getClient();
31
//			client.addUser(userName, password, 1);
32
			DashboardUser dashboardUser = client.authenticateDashboardUser(userName, password);
32
		} catch (Exception e) {
33
			status = true;
33
			e.printStackTrace();
34
			nextScreen = NEXT.INBOX;
34
		}
-
 
35
		
-
 
36
		try {
-
 
37
			long warehouseId = client.authenticateUser(userName, password);
35
			warehouseId = dashboardUser.getWarehouseId();
38
			if(warehouseId != -1){
36
			isAdmin = dashboardUser.isAdmin();
39
				return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.INBOX, warehouseId);
37
			message = "You are charming, loving and affectionate";
40
			}
-
 
41
		} catch (HelperServiceException e) {
38
		} catch (HelperServiceException e) {
42
			// TODO Auto-generated catch block
-
 
43
			e.printStackTrace();
39
			e.printStackTrace();
44
		} catch (TException e) {
40
		} catch (TException e) {
45
			// TODO Auto-generated catch block
41
			e.printStackTrace();
-
 
42
		} catch (Exception e) {
46
			e.printStackTrace();
43
			e.printStackTrace();
47
		}
44
		}
48
		
-
 
49
		/*
-
 
50
		if (userName.trim().toUpperCase().equals("SHOP2020")){
-
 
51
			return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.INBOX, 1);
-
 
52
		}
-
 
53
		
-
 
54
			if(getThreadLocalRequest().getSession(true) == null){
-
 
55
				getThreadLocalRequest().getSession(true);
-
 
56
			}
-
 
57
			HttpSession httpSession = getThreadLocalRequest().getSession(true);
-
 
58
			httpSession.setAttribute("userName", userName);
-
 
59
			httpSession.setAttribute("warehouseId", "1");
-
 
60
 
-
 
61
		 	HttpSession session = getThreadLocalRequest().getSession(true);
-
 
62
			String warehouseId = null;
-
 
63
			if(session.getAttribute("warehouseId") !=null){
-
 
64
				warehouseId = session.getAttribute("warehouseId").toString();
-
 
65
			}
-
 
66
			else{
-
 
67
				warehouseId = "Default";
-
 
68
			} 
-
 
69
			 */
-
 
70
			
-
 
71
			
-
 
72
			  
-
 
73
		
-
 
74
		
-
 
75
		if (userName.trim().toUpperCase().equals("ADMIN")){
-
 
76
 
-
 
77
			 
-
 
78
			
-
 
79
			
-
 
80
			return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.ADMIN, -1);
-
 
81
		}
-
 
82
		else
-
 
83
			return new AuthResponse(userName, false, "None", NEXT.INBOX, -1);
45
		return new AuthResponse(userName, status, message, nextScreen, warehouseId, isAdmin);
84
	}
46
	}
85
 
47
 
86
	@Override
48
	@Override
87
	public Class<AuthRequest> getActionType() {
49
	public Class<AuthRequest> getActionType() {		
88
		
-
 
89
		return AuthRequest.class;
50
		return AuthRequest.class;
90
	}
51
	}
91
 
52
 
92
	@Override
53
	@Override
93
	public void rollback(AuthRequest arg0, AuthResponse arg1,
54
	public void rollback(AuthRequest arg0, AuthResponse arg1,
94
			ExecutionContext arg2) throws ActionException {
55
			ExecutionContext arg2) throws ActionException {
95
				
56
		//TODO Auto-generated method stub
96
	}
57
	}
97
 
58
 
98
}
59
}