Subversion Repositories SmartDukaan

Rev

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

Rev 416 Rev 419
Line 11... Line 11...
11
import org.apache.thrift.TException;
11
import org.apache.thrift.TException;
12
 
12
 
13
import in.shop2020.model.v1.user.AuthenticationException;
13
import in.shop2020.model.v1.user.AuthenticationException;
14
import in.shop2020.model.v1.user.UserContextException;
14
import in.shop2020.model.v1.user.UserContextException;
15
import in.shop2020.model.v1.user.UserContextService.Client;
15
import in.shop2020.model.v1.user.UserContextService.Client;
-
 
16
import in.shop2020.serving.services.UserSessionInfo;
-
 
17
import in.shop2020.serving.utils.Utils;
16
import in.shop2020.thrift.clients.UserContextServiceClient;
18
import in.shop2020.thrift.clients.UserContextServiceClient;
17
import in.shop2020.thrift.clients.UserProfileClient;
19
import in.shop2020.thrift.clients.UserProfileClient;
18
 
20
 
19
import com.opensymphony.xwork2.ModelDriven;
21
import com.opensymphony.xwork2.ModelDriven;
20
 
22
 
Line 45... Line 47...
45
	@Override
47
	@Override
46
	public Object getModel() {
48
	public Object getModel() {
47
		return this.auth;
49
		return this.auth;
48
	}
50
	}
49
	
51
	
-
 
52
	public HttpHeaders show(){
-
 
53
		Client c = client.getClient();
-
 
54
		
-
 
55
		/*
-
 
56
		if(this.getId().equals("logout")){
-
 
57
			if(this.session.getAttribute("userid") != null 
-
 
58
					&& this.session.getAttribute("loggedin") != null
-
 
59
					&& this.session.getAttribute("loggedin").toString().equals("true")){
-
 
60
				
-
 
61
				long userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
62
				try {
-
 
63
					c.setUserAsLoggedOut(userId, (new Date()).getTime());
-
 
64
				} catch (UserContextException e) {
-
 
65
					// TODO Auto-generated catch block
-
 
66
					e.printStackTrace();
-
 
67
				} catch (TException e) {
-
 
68
					// TODO Auto-generated catch block
-
 
69
					e.printStackTrace();
-
 
70
				}
-
 
71
				
-
 
72
				this.session.removeAttribute("userid");
-
 
73
				this.session.removeAttribute("loggedin");
-
 
74
				this.session.removeAttribute("issessionid");
-
 
75
				this.session.removeAttribute("email");
-
 
76
				return new DefaultHttpHeaders("lsuccess");
-
 
77
			}else{
-
 
78
				return new DefaultHttpHeaders("lfail");
-
 
79
			}
-
 
80
		}*/
-
 
81
		
-
 
82
		if(this.getId().equals("logout")){
-
 
83
			if(userinfo.isLoggedIn()){
-
 
84
				long userId = userinfo.getUserId();
-
 
85
				
-
 
86
				try {
-
 
87
					c.setUserAsLoggedOut(userId, (new Date()).getTime());
-
 
88
					this.session.removeAttribute("userinfo");
-
 
89
				} catch (UserContextException e) {
-
 
90
					// TODO Auto-generated catch block
-
 
91
					e.printStackTrace();
-
 
92
				} catch (TException e) {
-
 
93
					// TODO Auto-generated catch block
-
 
94
					e.printStackTrace();
-
 
95
				}
-
 
96
				
-
 
97
				return new DefaultHttpHeaders("lsuccess");
-
 
98
			}else{
-
 
99
				return new DefaultHttpHeaders("lfail");
-
 
100
			}
-
 
101
		}
-
 
102
			
-
 
103
			
-
 
104
		return new DefaultHttpHeaders("lfail");
-
 
105
 
-
 
106
	}
-
 
107
	
50
	public HttpHeaders create(){
108
	public HttpHeaders create(){
51
		System.out.println(auth);
109
		System.out.println(auth);
52
		//return new DefaultHttpHeaders("lsuccess");
110
		//return new DefaultHttpHeaders("lsuccess");
53
		//AUTH service to be invoked from here
111
		//AUTH service to be invoked from here
54
		
112
		
Line 56... Line 114...
56
		try {
114
		try {
57
			
115
			
58
			if (c.authenticateUser(auth.getUserName(), auth.getPassword(), true)){
116
			if (c.authenticateUser(auth.getUserName(), auth.getPassword(), true)){
59
				long userId = c.getContext(auth.getUserName(), auth.getPassword()).getId();
117
				long userId = c.getContext(auth.getUserName(), auth.getPassword()).getId();
60
				c.setUserAsLoggedIn(userId, (new Date()).getTime());
118
				c.setUserAsLoggedIn(userId, (new Date()).getTime());
61
				this.session.removeAttribute("useid");
-
 
62
				this.session.removeAttribute("loggedin");
-
 
63
				this.session.removeAttribute("issessionid");
-
 
64
				
119
				
-
 
120
//				userinfo = (UserSessionInfo) this.session.getAttribute("userinfo");
-
 
121
 
65
				this.session.setAttribute("userid", userId+"");
122
				userinfo.setUserId(userId);
66
				this.session.setAttribute("loggedin", "true");
123
				userinfo.setLoggedIn(true);
-
 
124
				userinfo.setEmail(Utils.getEmailId(userId));
-
 
125
				
67
				this.session.setAttribute("issessionid", "false");
126
				this.session.setAttribute("userinfo", userinfo);
68
 
127
 
69
				Cookie cookie1 = new Cookie("userid", userId+"");
128
				Cookie cookie1 = new Cookie("userid", userId+"");
70
		    	this.response.addCookie(cookie1);
129
		    	this.response.addCookie(cookie1);
71
 
-
 
72
				return new DefaultHttpHeaders("lsuccess");
130
				return new DefaultHttpHeaders("lsuccess");
73
			}
131
			}
74
		} catch (AuthenticationException e) {
132
		} catch (AuthenticationException e) {
75
			
133
			
76
			errorCode = e.getErrorCode();
134
			errorCode = e.getErrorCode();