| 7266 |
anupam.sin |
1 |
package in.shop2020.recharge.controllers;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
import java.util.Random;
|
|
|
6 |
|
|
|
7 |
import in.shop2020.model.v1.order.HotspotStore;
|
|
|
8 |
import in.shop2020.thrift.clients.HelperClient;
|
|
|
9 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
10 |
import in.shop2020.utils.Mail;
|
|
|
11 |
|
|
|
12 |
public class ManageStoreController extends BaseController{
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
*
|
|
|
16 |
*/
|
|
|
17 |
private static final String chars = "0123456789";
|
|
|
18 |
private static final int LENGTH = 4;
|
|
|
19 |
private static final Random random = new Random();
|
|
|
20 |
private static final long serialVersionUID = 1L;
|
|
|
21 |
private String storecode = "";
|
|
|
22 |
private HotspotStore store = null;
|
|
|
23 |
private String message = "";
|
|
|
24 |
private String passwordGeneration = "";
|
|
|
25 |
private String password;
|
|
|
26 |
private long storeid;
|
|
|
27 |
|
|
|
28 |
public String index() {
|
|
|
29 |
return "index";
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public String searchStore() {
|
|
|
33 |
try{
|
|
|
34 |
TransactionClient tcl = new TransactionClient();
|
|
|
35 |
store = tcl.getClient().getHotspotStore(0, storecode);
|
|
|
36 |
if(store == null) {
|
|
|
37 |
setMessage("No store found for this code");
|
|
|
38 |
}
|
|
|
39 |
} catch (Exception e) {
|
|
|
40 |
log.error("Unable to get store for hotspotId : " + storecode, e);
|
|
|
41 |
setMessage("Internal error. Please try again");
|
|
|
42 |
}
|
|
|
43 |
return index();
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public String reset() throws Exception {
|
|
|
47 |
|
|
|
48 |
char[] buf = new char[LENGTH];
|
|
|
49 |
for (int i = 0; i < buf.length; i++) {
|
|
|
50 |
buf[i] = chars.charAt(random.nextInt(chars.length()));
|
|
|
51 |
}
|
|
|
52 |
password = new String(buf);
|
|
|
53 |
|
|
|
54 |
try {
|
|
|
55 |
TransactionClient tcl = new TransactionClient();
|
|
|
56 |
HotspotStore hotSpotStore = tcl.getClient().getHotspotStore(storeid, "");
|
|
|
57 |
boolean wasPasswordSet = tcl.getClient().updateHotspotStorePassword(storeid, password);
|
|
|
58 |
if(!wasPasswordSet) {
|
|
|
59 |
setPasswordGeneration("FAIL");
|
|
|
60 |
return index();
|
|
|
61 |
}
|
|
|
62 |
List<String> toList = new ArrayList<String>();
|
|
|
63 |
toList.add(hotSpotStore.getEmail());
|
|
|
64 |
HelperClient helperServiceClient = null;
|
|
|
65 |
helperServiceClient = new HelperClient();
|
|
|
66 |
in.shop2020.utils.HelperService.Client client = helperServiceClient.getClient();
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
Mail mail = new Mail();
|
|
|
70 |
mail.setSubject("New Password for Saholic Recharge");
|
|
|
71 |
mail.setTo(toList);
|
|
|
72 |
mail.setData("Your new password is : " + password);
|
|
|
73 |
client.sendMail(mail);
|
|
|
74 |
} catch(Exception e) {
|
|
|
75 |
setPasswordGeneration("FAIL");
|
|
|
76 |
log.error("Password generation/sending failed for storeId : " + storeId, e);
|
|
|
77 |
}
|
|
|
78 |
setPasswordGeneration("SUCCESS");
|
|
|
79 |
return index();
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public void setStore(HotspotStore store) {
|
|
|
83 |
this.store = store;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
public HotspotStore getStore() {
|
|
|
87 |
return store;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public void setStorecode(String storecode) {
|
|
|
91 |
this.storecode = storecode;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public String getStorecode() {
|
|
|
95 |
return storecode;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public String getMessage() {
|
|
|
99 |
return message;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public void setMessage(String message) {
|
|
|
103 |
this.message = message;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public void setPasswordGeneration(String passwordGeneration) {
|
|
|
107 |
this.passwordGeneration = passwordGeneration;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public String getPasswordGeneration() {
|
|
|
111 |
return passwordGeneration;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public String getPassword() {
|
|
|
115 |
return password;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
public void setPassword(String password) {
|
|
|
119 |
this.password = password;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
public long getStoreid() {
|
|
|
123 |
return storeid;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public void setStoreid(long storeid) {
|
|
|
127 |
this.storeid = storeid;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
}
|