Subversion Repositories SmartDukaan

Rev

Rev 595 | Blame | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.serving.controllers;

import in.shop2020.model.v1.user.Address;
import in.shop2020.model.v1.user.AddressType;
import in.shop2020.model.v1.user.User;
import in.shop2020.model.v1.user.UserState;
import in.shop2020.serving.pages.PageContentKeys;
import in.shop2020.serving.pages.PageEnum;
import in.shop2020.serving.pages.PageManager;
import in.shop2020.serving.services.PageLoaderHandler;
import in.shop2020.serving.utils.Utils;
import in.shop2020.thrift.clients.UserContextServiceClient;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.ParameterAware;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;

/**
 * @author rajveer
 *
 */

@Results({
    @Result(name="success", type="redirectAction", 
                params = {"actionName" , "login-details"}),
    @Result(name="redirect", type="redirectAction", 
            params = {"actionName" , "login"})
})
public class LoginDetailsController extends BaseController {

        private static final long serialVersionUID = 1L;

        private static Log log = LogFactory.getLog(LoginDetailsController.class);
        
        
        public LoginDetailsController() {
                super();
        }
        
    // POST /logindetails
    public String create() {
        log.info("LogindetailsController.create");

                
                String email = this.request.getParameter("txtLoginID");
                String oldPassword = this.request.getParameter("txtOldPassword");
                String newPassword = this.request.getParameter("txtNewPassword");
                
                if(this.userinfo.isLoggedIn()){
                        if(Utils.ChangePassword(userinfo.getUserId(), email, oldPassword, newPassword))
                        {
                                addActionMessage("Your password is updated successfully.");
                                return "success";
                        }
        }
                addActionError("Unable to update password. Either email or password is not correct.");
                return "success";
    }

    
    // GET /test
    public String index() throws UnsupportedEncodingException {
        log.info("this.request=" + this.request);
        
                if(!userinfo.isLoggedIn()){
                        setRedirectUrl();
                        return "redirect";
        }else{
                htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
                htmlSnippets.put("LOGIN_DETAILS", pageLoader.getLoginDetailsHtml(userinfo.getUserId()));
                return "index";
        }
        
    }
    
        public String getMyaccountHeaderSnippet(){
                return htmlSnippets.get("MYACCOUNT_HEADER");
        }
        
        public String getLoginDetailsSnippet(){
                return htmlSnippets.get("LOGIN_DETAILS");
        }
        
        public String getEmail(){
        return userinfo.getEmail();
    }
    
}