Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
569 rajveer 1
package in.shop2020.serving.controllers;
2
 
3
 
4
import in.shop2020.model.v1.user.UserContextService.Client;
5
import in.shop2020.serving.controllers.BaseController;
6
import in.shop2020.thrift.clients.UserContextServiceClient;
7
 
8
import org.apache.juli.logging.Log;
9
import org.apache.juli.logging.LogFactory;
627 rajveer 10
import org.apache.struts2.convention.annotation.Result;
11
import org.apache.struts2.convention.annotation.Results;
569 rajveer 12
import org.apache.struts2.rest.DefaultHttpHeaders;
13
import org.apache.struts2.rest.HttpHeaders;
14
 
627 rajveer 15
@Results({
16
    @Result(name="failure", type="redirectAction", 
17
    		params = {"actionName" , "forgot-password"})
18
})
569 rajveer 19
public class ForgotPasswordController extends BaseController{
20
 
21
	private static final long serialVersionUID = 1L;
22
	private static Log log = LogFactory.getLog(ForgotPasswordController.class);
23
 
24
		public ForgotPasswordController(){
25
			super();	
26
		}
27
 
28
		 // GET /Forgot password page
29
		 public HttpHeaders index() {		
30
			return new DefaultHttpHeaders("index").disableCaching();
31
		 }
32
 
33
		// POST /Forgot password
34
		public String create() {
35
	    	log.info("ForgotPasswordController.create");
36
	    	String emailId = request.getParameter("emailId");
37
	    	if(emailId != null){
38
	    		UserContextServiceClient userContextServiceClient;
39
				try {
40
					userContextServiceClient = new UserContextServiceClient();
41
		    		Client client = userContextServiceClient.getClient();
627 rajveer 42
		    		if(client.forgotPassword(emailId)){
43
		    			addActionMessage("Password sent to your email address.");
44
		    			return "success";
45
		    		}else{
46
		    			addActionError("Email address is not registered with us.");
47
		    			return "failure";
48
		    		}
569 rajveer 49
				} catch (Exception e) {
50
					e.printStackTrace();
627 rajveer 51
					addActionError("Something went wrong. Try again.");
569 rajveer 52
				}
53
	    	}
627 rajveer 54
	    	return "failure";
569 rajveer 55
	    }
56
 
57
}