Subversion Repositories SmartDukaan

Rev

Rev 20564 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.hotspotstore.controllers;

import java.io.IOException;

import org.json.JSONObject;

import com.hotspotstore.services.SendGridMail;
import com.hotspotstore.services.VerifyRecaptcha;
import com.hotspotstore.storage.Mongo;


public class ContactUsController extends BaseController{

        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        private String result;
        private String name;
        private String eid;

        public String getEid() {
                return eid;
        }

        public void setEid(String eid) {
                this.eid = eid;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public String getEmail() {
                return email;
        }

        public void setEmail(String email) {
                this.email = email;
        }

        public String getCity() {
                return city;
        }

        public void setCity(String city) {
                this.city = city;
        }

        public String getState() {
                return state;
        }

        public void setState(String state) {
                this.state = state;
        }

        public String getMobile() {
                return mobile;
        }

        public void setMobile(String mobile) {
                this.mobile = mobile;
        }

        public String getCategory() {
                return category;
        }

        public void setCategory(String category) {
                this.category = category;
        }

        public String getMsg() {
                return msg;
        }

        public void setMsg(String msg) {
                this.msg = msg;
        }

        private String email;
        private String city;
        private String state;
        private String mobile;
        private String category;
        private String msg;
        private String productName;
        private String queryType;

        public String getQueryType() {
                return queryType;
        }

        public void setQueryType(String queryType) {
                this.queryType = queryType;
        }

        public String getProductName() {
                return productName;
        }

        public void setProductName(String productName) {
                this.productName = productName;
        }

        public String getResult() {
                return result;
        }

        public void setResult(String result) {
                this.result = result;
        }

        public String index(){
                try {
                        JSONObject hotspotEntity = Mongo.getHotspotEntity(Long.valueOf(eid));
                        productName = hotspotEntity.getString("title");
                } catch (Exception e) {
                        System.out.println(e);
                }
                return "index";
        }

        public String create(){
                try {
                        String gRecaptchaResponse = request.getParameter("g-recaptcha-response");
                        StringBuilder sb = new StringBuilder();
                        String subject ="";
                        String mailTo ="wecare@spicehotspot.co.in";
                        //String mailTo ="kshitij.sood@saholic.com";
                        try{
                                if (queryType.equalsIgnoreCase("generalQuery")){
                                        subject = "General Query";
                                        sb.append("Name : "+name +"\n");
                                        sb.append("Customer Email : "+email+"\n");
                                        sb.append("City : "+city+"\n");
                                        sb.append("State : "+state+"\n");
                                        sb.append("Phone : "+mobile+"\n");
                                        sb.append("Category : "+category+"\n");
                                        sb.append("Message : "+msg);
                                }
                                else if (queryType.equalsIgnoreCase("productQuery")){
                                        JSONObject hotspotEntity = Mongo.getHotspotEntity(Long.valueOf(eid));
                                        productName = hotspotEntity.getString("title");
                                        subject = "Product Query - " +productName;
                                        sb.append("Name : "+name+"\n");
                                        sb.append("Product Name : "+productName+"\n");
                                        sb.append("Customer Email : "+email+"\n");
                                        sb.append("City : "+city+"\n");
                                        sb.append("State : "+state+"\n");
                                        sb.append("Phone : "+mobile+"\n");
                                        sb.append("Category : "+category+"\n");
                                        sb.append("Message : "+msg);
                                }
                                else{
                                        throw new Exception();
                                }
                                SendGridMail.sendMail(mailTo, subject, sb.toString());
                        }
                        catch(Exception e){
                                setResult("OOPS!!!We are unable to process your request.");
                                return "index";
                        }
                        boolean verify = VerifyRecaptcha.verify(gRecaptchaResponse);
                        if (verify){
                                setResult("Thank you, your query has been submitted.");
                                return "index";
                        }
                        setResult("Captcha verification failed.");

                } catch (IOException e) {
                        System.out.println(e);
                        setResult("OOPS!!!We are unable to process your request.");
                }
                return "index";

        }


}