Subversion Repositories SmartDukaan

Rev

Rev 345 | Rev 2209 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.hotspot.dashbaord.server.handler;

import org.apache.thrift.TException;

import in.shop2020.hotspot.dashbaord.shared.actions.AuthRequest;
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse;
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse.NEXT;
import in.shop2020.thrift.clients.HelperServiceClient;
import in.shop2020.utils.HelperService.Client;
import in.shop2020.utils.HelperServiceException;
import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

public class AuthHandler implements ActionHandler<AuthRequest, AuthResponse>{

        @Override
        public AuthResponse execute(AuthRequest request, ExecutionContext response)
                        throws ActionException {
                String userName = request.getUsername();
                String password = request.getPassword();

                
                
                HelperServiceClient hsc = null;
                Client client = null;
                
                try {
                        hsc = new HelperServiceClient();
                        client =  hsc.getClient();
//                      client.addUser(userName, password, 1);
                } catch (Exception e) {
                        e.printStackTrace();
                }
                
                try {
                        long warehouseId = client.authenticateUser(userName, password);
                        if(warehouseId != -1){
                                return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.INBOX, warehouseId);
                        }
                } catch (HelperServiceException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (TException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                /*
                if (userName.trim().toUpperCase().equals("SHOP2020")){
                        return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.INBOX, 1);
                }
                
                        if(getThreadLocalRequest().getSession(true) == null){
                                getThreadLocalRequest().getSession(true);
                        }
                        HttpSession httpSession = getThreadLocalRequest().getSession(true);
                        httpSession.setAttribute("userName", userName);
                        httpSession.setAttribute("warehouseId", "1");

                        HttpSession session = getThreadLocalRequest().getSession(true);
                        String warehouseId = null;
                        if(session.getAttribute("warehouseId") !=null){
                                warehouseId = session.getAttribute("warehouseId").toString();
                        }
                        else{
                                warehouseId = "Default";
                        } 
                         */
                        
                        
                          
                
                
                if (userName.trim().toUpperCase().equals("ADMIN")){

                         
                        
                        
                        return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.ADMIN, -1);
                }
                else
                        return new AuthResponse(userName, false, "None", NEXT.INBOX, -1);
        }

        @Override
        public Class<AuthRequest> getActionType() {
                
                return AuthRequest.class;
        }

        @Override
        public void rollback(AuthRequest arg0, AuthResponse arg1,
                        ExecutionContext arg2) throws ActionException {
                                
        }

}