Subversion Repositories SmartDukaan

Rev

Rev 7386 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7386 Rev 19706
Line 4... Line 4...
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
6
import in.shop2020.model.v1.order.HotspotStore;
6
import in.shop2020.model.v1.order.HotspotStore;
7
import in.shop2020.thrift.clients.TransactionClient;
7
import in.shop2020.thrift.clients.TransactionClient;
8
 
8
 
-
 
9
import org.apache.commons.lang.StringUtils;
9
import org.apache.struts2.convention.annotation.Action;
10
import org.apache.struts2.convention.annotation.Action;
10
import org.apache.struts2.convention.annotation.Result;
11
import org.apache.struts2.convention.annotation.Result;
11
import org.apache.struts2.convention.annotation.Results;
12
import org.apache.struts2.convention.annotation.Results;
12
import org.apache.thrift.TException;
13
import org.apache.thrift.TException;
13
import org.apache.thrift.transport.TTransportException;
14
import org.apache.thrift.transport.TTransportException;
Line 35... Line 36...
35
        if(loginStatus != null && loginStatus.equals("TRUE")){
36
        if(loginStatus != null && loginStatus.equals("TRUE")){
36
            redirectUrl = "/home";
37
            redirectUrl = "/home";
37
            return "redirect";
38
            return "redirect";
38
        }
39
        }
39
        //Try to get the stored store id from session
40
        //Try to get the stored store id from session
40
        storeIdString = (String) request.getSession().getAttribute("STORE_ID");
41
        storeIdString = request.getParameter("storeid");
41
        if(storeIdString == null || storeIdString.isEmpty()){
42
        hash = request.getParameter("hash");
42
            //If not found try to get the hotspotId from request
43
        //if store and hash(token) is available then validate. 
43
            //It is a bit confusing but "storeIdString" from the next line on means hotspot id
44
        if(!StringUtils.isEmpty(storeIdString) && !StringUtils.isEmpty(hash)){
44
            storeIdString = request.getParameter("storeid");
-
 
45
            if(storeIdString == null){
-
 
46
                return "authfail";
-
 
47
            }else{
45
        	try {
48
                //If we get the hotspot id then we fetch the store and store the store id in session to use on subsequent requests
-
 
49
                try {
46
        		//Validation logic here
50
                    TransactionClient tcl = new TransactionClient(); 
47
        		TransactionClient tcl = new TransactionClient(); 
51
                    HotspotStore hotSpotStore = tcl.getClient().getHotspotStore(0, storeIdString);
48
                HotspotStore hotSpotStore = tcl.getClient().getHotspotStore(0, storeIdString);
52
                    if(!request.getParameter("hash").equals(hotSpotStore.getSalt())) {
49
                if(!request.getParameter("hash").equals(hotSpotStore.getSalt())) {
53
                        return "authfail";
-
 
54
                    }
-
 
55
                    storeId = hotSpotStore.getId();
-
 
56
                    setHash(hotSpotStore.getSalt());
-
 
57
                    circleId = hotSpotStore.getCircleId();
-
 
58
                } catch (TTransportException e) {
-
 
59
                    e.printStackTrace();
-
 
60
                    return "authfail";
-
 
61
                } catch (TException e) {
-
 
62
                    e.printStackTrace();
-
 
63
                    return "authfail";
50
                    return "authfail";
64
                }
51
                }
-
 
52
                storeId = hotSpotStore.getId();
-
 
53
                //Save to session 
65
                request.getSession().setAttribute("STORE_ID", "" + storeId);
54
                request.getSession().setAttribute("STORE_ID", "" + storeId);
66
                request.getSession().setAttribute("HASH", hash);
55
                request.getSession().setAttribute("OCR_SESSION", "TRUE");
67
                request.getSession().setAttribute("CIRCLE_ID", "" + circleId);
56
                request.getSession().setAttribute("LOGGED_IN", "TRUE");
-
 
57
                redirectUrl = "/home";
-
 
58
                return "redirect";
-
 
59
 
-
 
60
            } catch (TTransportException e) {
-
 
61
                e.printStackTrace();
-
 
62
                return "authfail";
-
 
63
            } catch (TException e) {
-
 
64
                e.printStackTrace();
-
 
65
                return "authfail";
68
            }
66
            }
69
        } else {
-
 
70
            //FIXME : This seems to be useless code
-
 
71
            storeId = Long.parseLong(storeIdString);
-
 
72
        }
67
        }
73
 
-
 
74
        return INDEX;
68
        return INDEX;
75
    }
69
    }
76
 
70
 
77
    public String doLogin()
71
    public String doLogin()
78
    {
72
    {
79
        log.info("Logging in!");
73
        log.info("Logging in!");
80
        password = request.getParameter("password");
74
        password = request.getParameter("password");
81
        storeIdString = (String) request.getSession().getAttribute("STORE_ID");
75
        storeIdString = request.getParameter("storeid");
82
        if(storeIdString == null || storeIdString.isEmpty()){
76
        if(StringUtils.isEmpty(storeIdString) || StringUtils.isEmpty(password)){
-
 
77
        	setMessage("Store id or password is blank");
83
            return "authfail";
78
            return "INDEX";
84
        }
79
        }
85
        try {
80
        try {
86
            TransactionClient tcl = new TransactionClient(); 
81
            TransactionClient tcl = new TransactionClient(); 
87
            HotspotStore hotSpotStore = tcl.getClient().getHotspotStore(Long.parseLong(storeIdString), "");
82
            HotspotStore hotSpotStore = tcl.getClient().getHotspotStore(0, storeIdString);
88
            hash = (String) request.getSession().getAttribute("HASH");
-
 
89
            if(hash == null || !hash.equals(hotSpotStore.getSalt())) {
-
 
90
                return "authfail";
-
 
91
            }
-
 
92
            if(!hotSpotStore.getPassword().equals(password)){
83
            if(!hotSpotStore.getPassword().equals(password)){
93
                setMessage("Wrong Password. Try Again.");
84
                setMessage("Wrong Password. Try Again.");
94
                return INDEX;    
85
                return INDEX;    
95
            }
86
            }
96
            request.getSession().setAttribute("STORE_CIRCLE_CODE", tcl.getClient().getTelecomCircle(hotSpotStore.getCircleId(), "").getCode());
87
            request.getSession().setAttribute("STORE_ID", "" + hotSpotStore.getId());
97
            request.getSession().setAttribute("LOGGED_IN", "TRUE");
88
            request.getSession().setAttribute("LOGGED_IN", "TRUE");
98
        } catch (TTransportException e) {
89
        } catch (TTransportException e) {
99
            e.printStackTrace();
90
            e.printStackTrace();
100
            return "authfail";
91
            return "authfail";
101
        } catch (TException e) {
92
        } catch (TException e) {