Subversion Repositories SmartDukaan

Rev

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

Rev 408 Rev 416
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.util.Date;
-
 
4
 
-
 
5
import javax.servlet.http.Cookie;
-
 
6
 
-
 
7
import org.apache.struts2.convention.annotation.Result;
-
 
8
import org.apache.struts2.convention.annotation.Results;
3
import org.apache.struts2.rest.DefaultHttpHeaders;
9
import org.apache.struts2.rest.DefaultHttpHeaders;
4
import org.apache.struts2.rest.HttpHeaders;
10
import org.apache.struts2.rest.HttpHeaders;
5
import org.apache.thrift.TException;
11
import org.apache.thrift.TException;
6
 
12
 
7
import in.shop2020.model.v1.user.AuthenticationException;
13
import in.shop2020.model.v1.user.AuthenticationException;
-
 
14
import in.shop2020.model.v1.user.UserContextException;
8
import in.shop2020.model.v1.user.UserContextService.Client;
15
import in.shop2020.model.v1.user.UserContextService.Client;
9
import in.shop2020.thrift.clients.UserContextServiceClient;
16
import in.shop2020.thrift.clients.UserContextServiceClient;
10
import in.shop2020.thrift.clients.UserProfileClient;
17
import in.shop2020.thrift.clients.UserProfileClient;
11
 
18
 
12
import com.opensymphony.xwork2.ModelDriven;
19
import com.opensymphony.xwork2.ModelDriven;
13
 
20
 
-
 
21
@Results({
-
 
22
    @Result(name="success", type="redirectAction", params = {"actionName" , 
-
 
23
    		"entity"})
-
 
24
})
14
public class AuthController implements ModelDriven<Object>{
25
public class AuthController extends BaseController implements ModelDriven<Object>{
15
 
26
 
16
	private Auth auth = new Auth();
27
	private Auth auth = new Auth();
17
	
28
	
18
	private UserContextServiceClient client = null;
29
	private UserContextServiceClient client = null;
19
	
30
	
20
	private int errorCode = 0;
31
	private int errorCode = 0;
21
	private String errorMessage;
32
	private String errorMessage;
22
	
33
	
23
	private String id;
34
	private String id;
24
	
35
	
-
 
36
	
25
	public AuthController(){
37
	public AuthController(){
26
		try {
38
		try {
27
		//	client = new UserContextServiceClient();
39
			client = new UserContextServiceClient();
28
		} catch (Exception e) {
40
		} catch (Exception e) {
29
			e.printStackTrace();
41
			e.printStackTrace();
30
		}
42
		}
31
	}
43
	}
32
	
44
	
Line 35... Line 47...
35
		return this.auth;
47
		return this.auth;
36
	}
48
	}
37
	
49
	
38
	public HttpHeaders create(){
50
	public HttpHeaders create(){
39
		System.out.println(auth);
51
		System.out.println(auth);
40
		return new DefaultHttpHeaders("lsuccess");
52
		//return new DefaultHttpHeaders("lsuccess");
41
		//AUTH service to be invoked from here
53
		//AUTH service to be invoked from here
42
		/*
54
		
43
		Client c = client.getClient();
55
		Client c = client.getClient();
44
		try {
56
		try {
45
			
57
			
46
			if (c.authenticateUser(auth.getUserName(), auth.getPassword(), true)){
58
			if (c.authenticateUser(auth.getUserName(), auth.getPassword(), true)){
-
 
59
				long userId = c.getContext(auth.getUserName(), auth.getPassword()).getId();
-
 
60
				c.setUserAsLoggedIn(userId, (new Date()).getTime());
-
 
61
				this.session.removeAttribute("useid");
-
 
62
				this.session.removeAttribute("loggedin");
-
 
63
				this.session.removeAttribute("issessionid");
-
 
64
				
-
 
65
				this.session.setAttribute("userid", userId+"");
-
 
66
				this.session.setAttribute("loggedin", "true");
-
 
67
				this.session.setAttribute("issessionid", "false");
-
 
68
 
-
 
69
				Cookie cookie1 = new Cookie("userid", userId+"");
-
 
70
		    	this.response.addCookie(cookie1);
-
 
71
 
47
				return new DefaultHttpHeaders("lsuccess");
72
				return new DefaultHttpHeaders("lsuccess");
48
			}
73
			}
49
		} catch (AuthenticationException e) {
74
		} catch (AuthenticationException e) {
50
			
75
			
51
			errorCode = e.getErrorCode();
76
			errorCode = e.getErrorCode();
Line 53... Line 78...
53
			
78
			
54
		} catch (TException e) {
79
		} catch (TException e) {
55
			// TODO Auto-generated catch block
80
			// TODO Auto-generated catch block
56
			errorCode = -1;
81
			errorCode = -1;
57
			e.printStackTrace();
82
			e.printStackTrace();
-
 
83
		} catch (UserContextException e) {
-
 
84
			// TODO Auto-generated catch block
-
 
85
			errorCode = -1;
-
 
86
			e.printStackTrace();
58
		}
87
		}
59
		return new DefaultHttpHeaders("lfail");
88
		return new DefaultHttpHeaders("lfail");
60
		*/
89
		
61
	}
90
	}
62
 
91
 
63
	public int getErrorCode() {
92
	public int getErrorCode() {
64
		return errorCode;
93
		return errorCode;
65
	}
94
	}