Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
507 rajveer 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
762 rajveer 5
import in.shop2020.model.v1.user.UserContextException;
507 rajveer 6
import in.shop2020.serving.utils.Utils;
762 rajveer 7
import in.shop2020.thrift.clients.UserContextServiceClient;
507 rajveer 8
 
9
import java.io.UnsupportedEncodingException;
10
 
11
import org.apache.juli.logging.Log;
12
import org.apache.juli.logging.LogFactory;
13
import org.apache.struts2.convention.annotation.Result;
14
import org.apache.struts2.convention.annotation.Results;
762 rajveer 15
import org.apache.thrift.TException;
507 rajveer 16
 
17
/**
18
 * @author rajveer
19
 *
20
 */
21
 
595 rajveer 22
@Results({
23
    @Result(name="success", type="redirectAction", 
650 rajveer 24
    		params = {"actionName" , "login-details"}),
25
    @Result(name="redirect", type="redirectAction", 
26
    	    params = {"actionName" , "login"})
595 rajveer 27
})
650 rajveer 28
public class LoginDetailsController extends BaseController {
507 rajveer 29
 
595 rajveer 30
	private static final long serialVersionUID = 1L;
31
 
517 rajveer 32
	private static Log log = LogFactory.getLog(LoginDetailsController.class);
507 rajveer 33
 
34
 
517 rajveer 35
	public LoginDetailsController() {
507 rajveer 36
		super();
37
	}
38
 
39
    // POST /logindetails
40
    public String create() {
41
    	log.info("LogindetailsController.create");
42
 
43
 
44
		String email = this.request.getParameter("txtLoginID");
45
		String oldPassword = this.request.getParameter("txtOldPassword");
46
		String newPassword = this.request.getParameter("txtNewPassword");
47
 
48
		if(this.userinfo.isLoggedIn()){
762 rajveer 49
			if(changePassword(userinfo.getUserId(), email, oldPassword, newPassword))
507 rajveer 50
			{
595 rajveer 51
				addActionMessage("Your password is updated successfully.");
507 rajveer 52
				return "success";
53
			}
54
    	}
595 rajveer 55
		addActionError("Unable to update password. Either email or password is not correct.");
56
		return "success";
507 rajveer 57
    }
58
 
59
 
60
    // GET /test
650 rajveer 61
    public String index() throws UnsupportedEncodingException {
507 rajveer 62
    	log.info("this.request=" + this.request);
63
 
650 rajveer 64
		if(!userinfo.isLoggedIn()){
65
			setRedirectUrl();
66
			return "redirect";
67
    	}else{
595 rajveer 68
    		htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
650 rajveer 69
    		htmlSnippets.put("LOGIN_DETAILS", pageLoader.getLoginDetailsHtml(userinfo.getUserId()));
70
    		return "index";
507 rajveer 71
    	}
72
 
73
    }
74
 
762 rajveer 75
 
76
	public boolean changePassword(long userId, String email, String oldPassword, String newPassword) {
77
 
78
 
79
		try {
80
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
81
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
82
 
83
			return userClient.updatePassword(userId,oldPassword, newPassword);
84
		} catch (UserContextException e) {
85
			e.printStackTrace();
86
		} catch (TException e) {
87
			e.printStackTrace();
88
		} catch (Exception e) {
89
			e.printStackTrace();
90
		}
91
		return false;
92
	}
93
 
94
 
95
 
507 rajveer 96
	public String getMyaccountHeaderSnippet(){
97
		return htmlSnippets.get("MYACCOUNT_HEADER");
98
	}
99
 
100
	public String getLoginDetailsSnippet(){
101
		return htmlSnippets.get("LOGIN_DETAILS");
102
	}
103
 
650 rajveer 104
	public String getEmail(){
595 rajveer 105
    	return userinfo.getEmail();
507 rajveer 106
    }
107
 
108
}