Subversion Repositories SmartDukaan

Rev

Rev 6086 | Rev 6103 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6086 Rev 6091
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import in.shop2020.datalogger.DataLogger;
-
 
4
import in.shop2020.datalogger.EventType;
3
import in.shop2020.model.v1.order.OrderType;
5
import in.shop2020.model.v1.order.OrderType;
4
import in.shop2020.model.v1.order.RechargeCoupon;
6
import in.shop2020.model.v1.order.RechargeCoupon;
5
import in.shop2020.model.v1.order.RechargeOrder;
7
import in.shop2020.model.v1.order.RechargeOrder;
6
import in.shop2020.model.v1.order.RechargeOrderStatus;
8
import in.shop2020.model.v1.order.RechargeOrderStatus;
7
import in.shop2020.model.v1.order.RechargeType;
9
import in.shop2020.model.v1.order.RechargeType;
Line 15... Line 17...
15
import in.shop2020.serving.utils.Utils;
17
import in.shop2020.serving.utils.Utils;
16
import in.shop2020.thrift.clients.HelperClient;
18
import in.shop2020.thrift.clients.HelperClient;
17
import in.shop2020.thrift.clients.TransactionClient;
19
import in.shop2020.thrift.clients.TransactionClient;
18
import in.shop2020.thrift.clients.UserClient;
20
import in.shop2020.thrift.clients.UserClient;
19
import in.shop2020.utils.HelperServiceException;
21
import in.shop2020.utils.HelperServiceException;
-
 
22
import in.shop2020.utils.Mail;
20
 
23
 
21
import java.util.ArrayList;
24
import java.util.ArrayList;
22
import java.util.List;
25
import java.util.List;
23
import java.util.Map;
26
import java.util.Map;
-
 
27
import java.util.Random;
24
 
28
 
25
import javax.servlet.http.Cookie;
29
import javax.servlet.http.Cookie;
26
 
30
 
27
import org.apache.log4j.Logger;
31
import org.apache.log4j.Logger;
28
import org.apache.struts2.convention.annotation.Result;
32
import org.apache.struts2.convention.annotation.Result;
Line 30... Line 34...
30
import org.apache.thrift.TException;
34
import org.apache.thrift.TException;
31
import org.apache.thrift.transport.TTransportException;
35
import org.apache.thrift.transport.TTransportException;
32
 
36
 
33
@SuppressWarnings({ "serial", "serial" })
37
@SuppressWarnings({ "serial", "serial" })
34
@Results({
38
@Results({
35
    @Result(name="recharge-pay-options-redirect", type="redirectAction", params = {"actionName" , "recharge-pay-options", "rechargeOrderId", "${rechargeOrderId}", "amount", "${amount}"}),
39
    @Result(name="recharge-pay-options-redirect", type="redirectAction", params = {"actionName" , "recharge-pay-options", "rechargeOrderId", "${rechargeOrderId}", "amount", "${amount}", "userId", "${userId}"}),
36
    @Result(name="create-recharge-redirect", type="redirectAction", params = {"actionName" , "wallet-only-payment", "rechargeOrderId", "${rechargeOrderId}"})
40
    @Result(name="create-recharge-redirect", type="redirectAction", params = {"actionName" , "wallet-only-payment", "rechargeOrderId", "${rechargeOrderId}"})
37
})
41
})
38
 
42
 
39
public class ConfirmController extends BaseController{
43
public class ConfirmController extends BaseController{
40
 
44
 
Line 53... Line 57...
53
    private List<String> couponIds = null;
57
    private List<String> couponIds = null;
54
    private List<RechargeCoupon> coupons = null;
58
    private List<RechargeCoupon> coupons = null;
55
    private String userId;
59
    private String userId;
56
    private String message = "";
60
    private String message = "";
57
    private String totalAmount = "";
61
    private String totalAmount = "";
-
 
62
    private static final String chars = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-
 
63
    private static final Random random = new Random();
-
 
64
    private static final int LENGTH = 10;
58
    private static Logger log = Logger.getLogger(Class.class);
65
    private static Logger log = Logger.getLogger(Class.class);
59
    
66
    
60
    public String index() {
67
    public String index() {
61
        return "index";
68
        return "index";
62
    }
69
    }
Line 83... Line 90...
83
                
90
                
84
            } catch (Exception e) {
91
            } catch (Exception e) {
85
                log.error("Unable to get user wallet", e);
92
                log.error("Unable to get user wallet", e);
86
            }
93
            }
87
        }
94
        }
-
 
95
        setUserId("" + createUserAndSendMail(email));
88
        return index();
96
        return index();
89
        
97
        
90
    }
98
    }
91
    
99
    
92
    private void setTotalAmount(String amount2) {
100
    private void setTotalAmount(String amount2) {
Line 96... Line 104...
96
 
104
 
97
    public String createRecharge(){
105
    public String createRecharge(){
98
        if(userinfo.isLoggedIn()) {
106
        if(userinfo.isLoggedIn()) {
99
            setUserId("" + userinfo.getUserId());
107
            setUserId("" + userinfo.getUserId());
100
        } else {
108
        } else {
101
            setUserId("686085");
109
            //setUserId("686085");
102
        }
110
        }
103
        
111
        
104
        try {
112
        try {
105
            TransactionClient tc = new TransactionClient();
113
            TransactionClient tc = new TransactionClient();
106
            RechargeOrder rechargeOrder = new RechargeOrder();
114
            RechargeOrder rechargeOrder = new RechargeOrder();
Line 129... Line 137...
129
        } else {
137
        } else {
130
            return "recharge-pay-options-redirect";
138
            return "recharge-pay-options-redirect";
131
        }
139
        }
132
    }
140
    }
133
    
141
    
-
 
142
    private static String generateNewPassword() {
-
 
143
        char[] buf = new char[LENGTH];
-
 
144
        for (int i = 0; i < buf.length; i++) {
-
 
145
            buf[i] = chars.charAt(random.nextInt(chars.length()));
-
 
146
        }
-
 
147
        return new String(buf);
-
 
148
    }
-
 
149
    
-
 
150
    private long createUserAndSendMail(String email) {
-
 
151
        User user = null;
-
 
152
        String password = null;
-
 
153
        try{
-
 
154
        UserClient ucl = new UserClient();
-
 
155
        user = ucl.getClient().getUserByEmail(email);
-
 
156
        if(user == null) {
-
 
157
            user = new User();
-
 
158
            user.setEmail(email);
-
 
159
            password = generateNewPassword();
-
 
160
            String encryptedPassword = desEncrypter.encrypt(password);
-
 
161
            user.setPassword(encryptedPassword);
-
 
162
            user.setCommunicationEmail(email);
-
 
163
            UserClient userContextServiceClient = new UserClient();
-
 
164
            in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
165
            user = userClient.createUser(user);
-
 
166
            }
-
 
167
            //DataLogger.logData(EventType.REGISTER_SUCCESS, getSessionId(), user.getUserId(), email, "", email);
-
 
168
        }catch (UserContextException ux){
-
 
169
            //DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
-
 
170
            return -1;               
-
 
171
        } catch (TTransportException e) {
-
 
172
            //DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
-
 
173
            return -1;
-
 
174
        } catch (TException e) {
-
 
175
            //DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
-
 
176
            return -1;
-
 
177
        }
-
 
178
        /*
-
 
179
        List<String> toList = new ArrayList<String>();
-
 
180
        toList.add(email);
-
 
181
        HelperClient helperServiceClient = null;
-
 
182
        try {
-
 
183
            helperServiceClient = new HelperClient();
-
 
184
            in.shop2020.utils.HelperService.Client client = helperServiceClient.getClient();
-
 
185
            Mail mail = new Mail();
-
 
186
            mail.setSubject("Registration successful");
-
 
187
            mail.setTo(toList);
-
 
188
            mail.setData("Your have successfully registered with Saholic.com. Your user name is: " + email + " and your password is: " +  password);
-
 
189
            client.sendMail(mail);
-
 
190
        } catch (Exception e) {
-
 
191
            log.error("Unexpected error while mailing the new password");
-
 
192
            return -1;
-
 
193
        }*/
-
 
194
        return user.getUserId();
-
 
195
    }
-
 
196
    
134
    public String temp() {
197
    public String temp() {
135
        try {
198
        try {
136
            UserClient ucl = new UserClient();
199
            UserClient ucl = new UserClient();
137
            User user = ucl.getClient().getUserByEmail(email);
200
            User user = ucl.getClient().getUserByEmail(email);
138
            if(user == null) {
201
            if(user == null) {