Subversion Repositories SmartDukaan

Rev

Rev 555 | 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"})
})
public class LoginDetailsController extends BaseController 
        implements ParameterAware {

        
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        /**
         * 
         */
        private static Log log = LogFactory.getLog(LoginDetailsController.class);
        
        private Map<String,String> htmlSnippets = new HashMap<String, String>();
        /**
         * 
         */
        
        private Map<String, String[]> reqparams;
        
        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 HttpHeaders index() throws UnsupportedEncodingException {
        log.info("this.request=" + this.request);
        
        if(this.userinfo.isLoggedIn()){
                PageLoaderHandler pageLoader = new PageLoaderHandler();
                
                htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(this.userinfo.isLoggedIn(), this.userinfo.getNameOfUser()));
                htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
                htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 0));
                htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
                
                htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
                htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), true));
                htmlSnippets.put("BROWSE_HISTORY", pageLoader.getBrowseHistoryHtml(userinfo.getUserId(), userinfo.isLoggedIn()));
                htmlSnippets.put("FOOTER", pageLoader.getFooterHtml());
                
                return new DefaultHttpHeaders("index").disableCaching();
        
        }else{
                return new DefaultHttpHeaders("login").disableCaching();
        }
        
    }
    
    public String getHeaderSnippet(){
                return htmlSnippets.get("HEADER");
        }
        
        public String getMainMenuSnippet(){
                return htmlSnippets.get("MAIN_MENU");
        }
        
        public String getSearchBarSnippet(){
                return htmlSnippets.get("SEARCH_BAR");
        }
                        
        
        public String getCustomerServiceSnippet(){
                return htmlSnippets.get("CUSTOMER_SERVICE");
        }
        
        public String getMyaccountHeaderSnippet(){
                return htmlSnippets.get("MYACCOUNT_HEADER");
        }
        
        public String getLoginDetailsSnippet(){
                return htmlSnippets.get("LOGIN_DETAILS");
        }
        
        public String getMyResearchSnippet(){
                return htmlSnippets.get("MY_RESEARCH");
        }

        public String getBrowseHistorySnippet(){
                return htmlSnippets.get("BROWSE_HISTORY");
        }
        
        public String getFooterSnippet(){
                return htmlSnippets.get("FOOTER");
        }
        
        public String getJsFileSnippet(){
                return htmlSnippets.get("JS_FILES");
        }
        
        public String getCssFileSnippet(){
                return htmlSnippets.get("CSS_FILES");
        }
        
    public String getEmail(){
        return userinfo.getEmail();
    }
    
        @Override
        public void setParameters(Map<String, String[]> reqmap) {
                log.info("setParameters:" + reqmap);
                
                this.reqparams = reqmap;
        }

}