Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
396 ashish 1
package in.shop2020.serving.controllers;
2
 
3
import org.apache.struts2.rest.DefaultHttpHeaders;
4
import org.apache.struts2.rest.HttpHeaders;
5
import org.apache.thrift.TException;
6
 
7
import in.shop2020.model.v1.user.AuthenticationException;
8
import in.shop2020.model.v1.user.UserContextService.Client;
9
import in.shop2020.serving.rest.Auth;
10
import in.shop2020.thrift.clients.UserContextServiceClient;
11
import in.shop2020.thrift.clients.UserProfileClient;
12
 
13
import com.opensymphony.xwork2.ModelDriven;
14
 
15
public class AuthController implements ModelDriven<Object>{
16
 
17
	private Auth auth = new Auth();
18
 
19
	private UserContextServiceClient client = null;
20
 
21
	private int errorCode = 0;
22
	private String errorMessage;
23
 
398 ashish 24
	private String id;
25
 
396 ashish 26
	public AuthController(){
27
		try {
28
			client = new UserContextServiceClient();
29
		} catch (Exception e) {
30
			e.printStackTrace();
31
		}
32
	}
33
 
34
	@Override
35
	public Object getModel() {
36
		return auth;
37
	}
38
 
39
	public HttpHeaders create(){
398 ashish 40
		System.out.println(auth);
41
		return new DefaultHttpHeaders("lsuccess");
396 ashish 42
		//AUTH service to be invoked from here
43
		Client c = client.getClient();
44
		try {
398 ashish 45
 
396 ashish 46
			if (c.authenticateUser(auth.getUserName(), auth.getPassword(), true)){
47
				return new DefaultHttpHeaders("lsuccess");
48
			}
49
		} catch (AuthenticationException e) {
50
 
51
			errorCode = e.getErrorCode();
52
			errorMessage = e.getMessage();
53
 
54
		} catch (TException e) {
55
			// TODO Auto-generated catch block
56
			errorCode = -1;
57
			e.printStackTrace();
58
		}
59
		return new DefaultHttpHeaders("lfail");
60
	}
61
 
62
	public int getErrorCode() {
63
		return errorCode;
64
	}
65
 
66
	public String getErrorMessage() {
67
		return errorMessage;
68
	}
398 ashish 69
 
70
	public String getId(){
71
		return id;
72
	}
73
 
74
	public String setId(){
75
		this.id = id;
76
	}
396 ashish 77
}