Subversion Repositories SmartDukaan

Rev

Rev 2449 | Rev 2835 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
167 ashish 1
package in.shop2020.hotspot.dashbaord.server.handler;
2
 
493 rajveer 3
import org.apache.thrift.TException;
4
 
167 ashish 5
import in.shop2020.hotspot.dashbaord.shared.actions.AuthRequest;
6
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse;
345 ashish 7
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse.NEXT;
493 rajveer 8
import in.shop2020.thrift.clients.HelperServiceClient;
2449 chandransh 9
import in.shop2020.utils.DashboardUser;
2781 chandransh 10
import in.shop2020.utils.Role;
493 rajveer 11
import in.shop2020.utils.HelperService.Client;
12
import in.shop2020.utils.HelperServiceException;
167 ashish 13
import net.customware.gwt.dispatch.server.ActionHandler;
14
import net.customware.gwt.dispatch.server.ExecutionContext;
15
import net.customware.gwt.dispatch.shared.ActionException;
16
 
17
public class AuthHandler implements ActionHandler<AuthRequest, AuthResponse>{
18
 
19
	@Override
2449 chandransh 20
	public AuthResponse execute(AuthRequest request, ExecutionContext response)	throws ActionException {
167 ashish 21
		String userName = request.getUsername();
493 rajveer 22
		String password = request.getPassword();
23
 
2449 chandransh 24
		boolean status = false;
25
		long warehouseId = -1;
26
		boolean isAdmin = false;
2781 chandransh 27
		boolean isCategoryManager = false;
2449 chandransh 28
		NEXT nextScreen = null;
29
		String message = null;
493 rajveer 30
 
31
		try {
2449 chandransh 32
			HelperServiceClient hsc = new HelperServiceClient();
33
			Client client =  hsc.getClient();
34
			DashboardUser dashboardUser = client.authenticateDashboardUser(userName, password);
35
			status = true;
36
			nextScreen = NEXT.INBOX;
37
			warehouseId = dashboardUser.getWarehouseId();
2781 chandransh 38
			if(dashboardUser.getRole() == Role.ADMIN)
39
			    isAdmin = true;
40
			else if(dashboardUser.getRole() == Role.CATEGORY_MANAGER)
41
			    isCategoryManager = true;
2449 chandransh 42
			message = "You are charming, loving and affectionate";
493 rajveer 43
		} catch (HelperServiceException e) {
44
			e.printStackTrace();
45
		} catch (TException e) {
46
			e.printStackTrace();
2449 chandransh 47
		} catch (Exception e) {
48
			e.printStackTrace();
493 rajveer 49
		}
2781 chandransh 50
		return new AuthResponse(userName, status, message, nextScreen, warehouseId, isAdmin, isCategoryManager);
167 ashish 51
	}
52
 
53
	@Override
2449 chandransh 54
	public Class<AuthRequest> getActionType() {		
167 ashish 55
		return AuthRequest.class;
56
	}
57
 
58
	@Override
59
	public void rollback(AuthRequest arg0, AuthResponse arg1,
60
			ExecutionContext arg2) throws ActionException {
2449 chandransh 61
		//TODO Auto-generated method stub
167 ashish 62
	}
63
 
64
}