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