| 23781 |
ashik.ali |
1 |
package com.spice.profitmandi.service.user;
|
| 21525 |
amit.gupta |
2 |
|
| 33247 |
ranu |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
5 |
import com.spice.profitmandi.common.util.DesEncrypter;
|
|
|
6 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
|
|
7 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
8 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
|
|
9 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
|
|
10 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
|
|
11 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
|
|
12 |
import in.shop2020.model.v1.order.TransactionService;
|
| 21525 |
amit.gupta |
13 |
import org.hibernate.Criteria;
|
|
|
14 |
import org.hibernate.Session;
|
|
|
15 |
import org.hibernate.SessionFactory;
|
|
|
16 |
import org.hibernate.criterion.Restrictions;
|
|
|
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23781 |
ashik.ali |
18 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 21525 |
amit.gupta |
19 |
import org.springframework.stereotype.Component;
|
|
|
20 |
|
| 33247 |
ranu |
21 |
import java.time.LocalDateTime;
|
|
|
22 |
import java.util.HashMap;
|
|
|
23 |
import java.util.HashSet;
|
|
|
24 |
import java.util.List;
|
|
|
25 |
import java.util.Map;
|
| 21525 |
amit.gupta |
26 |
|
|
|
27 |
@Component
|
|
|
28 |
public class UserServiceImpl implements UserService {
|
|
|
29 |
|
|
|
30 |
@Autowired
|
| 22931 |
ashik.ali |
31 |
private SessionFactory sessionFactory;
|
| 21525 |
amit.gupta |
32 |
|
|
|
33 |
@Autowired
|
| 23781 |
ashik.ali |
34 |
@Qualifier(value = "userRepository")
|
| 23204 |
ashik.ali |
35 |
private UserRepository userRepository;
|
| 21525 |
amit.gupta |
36 |
|
|
|
37 |
@Autowired
|
| 24099 |
amit.gupta |
38 |
@Qualifier(value = "userUserRepository")
|
|
|
39 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
|
|
40 |
|
|
|
41 |
@Autowired
|
| 23204 |
ashik.ali |
42 |
private RetailerRepository retailerRepo;
|
| 21525 |
amit.gupta |
43 |
|
| 23204 |
ashik.ali |
44 |
@Autowired
|
|
|
45 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
46 |
|
|
|
47 |
@Autowired
|
|
|
48 |
private UserAccountRepository userAccountRepository;
|
|
|
49 |
|
|
|
50 |
@Autowired
|
|
|
51 |
private UserRoleRepository userRoleRepository;
|
|
|
52 |
|
| 23781 |
ashik.ali |
53 |
@Autowired
|
|
|
54 |
private RoleRepository roleRepository;
|
|
|
55 |
|
| 24099 |
amit.gupta |
56 |
private static final DesEncrypter encrypter = new DesEncrypter("saholic");
|
|
|
57 |
|
|
|
58 |
|
| 23204 |
ashik.ali |
59 |
@SuppressWarnings("deprecation")
|
| 21525 |
amit.gupta |
60 |
@Override
|
|
|
61 |
public boolean updateActivation(int userId, int retailerId, String activationCode) throws Throwable {
|
|
|
62 |
|
|
|
63 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
64 |
TransactionService.Client tsc = transactionServiceClient.getClient();
|
|
|
65 |
boolean registered = tsc.registerRsa(retailerId, activationCode);
|
|
|
66 |
|
|
|
67 |
Session session = sessionFactory.getCurrentSession();
|
|
|
68 |
|
|
|
69 |
if(!registered){
|
|
|
70 |
Criteria cr = session.createCriteria(ActivationCode.class);
|
|
|
71 |
cr.add(Restrictions.eq("code", activationCode)).add(Restrictions.eq("status", true));
|
|
|
72 |
ActivationCode code = (ActivationCode)cr.uniqueResult();
|
|
|
73 |
if(code==null) {
|
|
|
74 |
return false;
|
|
|
75 |
} else {
|
|
|
76 |
registered=true;
|
|
|
77 |
code.setStatus(false);
|
|
|
78 |
session.update(code);
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
if(registered) {
|
| 23204 |
ashik.ali |
83 |
User user = userRepository.selectById(userId);
|
| 21525 |
amit.gupta |
84 |
user.setActivated(true);
|
| 22845 |
amit.gupta |
85 |
user.setActivationTime(LocalDateTime.now());
|
| 21525 |
amit.gupta |
86 |
user.setReferrer(activationCode);
|
|
|
87 |
session.update(user);
|
|
|
88 |
|
|
|
89 |
Retailer retailer = retailerRepo.selectById(retailerId);
|
|
|
90 |
retailer.setActive(true);
|
|
|
91 |
session.update(retailer);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
return registered;
|
|
|
95 |
}
|
| 22845 |
amit.gupta |
96 |
|
|
|
97 |
|
|
|
98 |
@Override
|
|
|
99 |
public boolean createActivationCode(int userId) throws Throwable {
|
|
|
100 |
// TODO Auto-generated method stub
|
|
|
101 |
return false;
|
|
|
102 |
}
|
| 23204 |
ashik.ali |
103 |
|
|
|
104 |
@Override
|
|
|
105 |
public Map<String, String> getEmailsAndFofoStoreCodeByUserId(int userId) throws ProfitMandiBusinessException {
|
|
|
106 |
User user = userRepository.selectById(userId);
|
| 23273 |
ashik.ali |
107 |
UserAccount userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
| 23781 |
ashik.ali |
108 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 23204 |
ashik.ali |
109 |
Map<String, String> map = new HashMap<>();
|
|
|
110 |
map.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
|
|
111 |
map.put(ProfitMandiConstants.SECONDRY_EMAIL_ID, user.getSecondryEmailId());
|
| 23781 |
ashik.ali |
112 |
userRoleRepository.selectByUserIdAndRoleId(userId, role.getId());
|
| 23273 |
ashik.ali |
113 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(userAccount.getAccountKey());
|
| 23204 |
ashik.ali |
114 |
map.put(ProfitMandiConstants.CODE, fofoStore.getCode());
|
|
|
115 |
return map;
|
|
|
116 |
}
|
| 23984 |
govind |
117 |
|
|
|
118 |
|
|
|
119 |
@Override
|
| 33247 |
ranu |
120 |
public Map<Integer, String> getAllUseUserIdEmailIdMap(List<Integer> userIds) throws ProfitMandiBusinessException {
|
| 23984 |
govind |
121 |
Map<Integer, String> userIdEmailIdMap=new HashMap<>();
|
|
|
122 |
List<User> users=userRepository.selectAllByIds(new HashSet<>(userIds));
|
|
|
123 |
for(User user:users)
|
|
|
124 |
{
|
|
|
125 |
userIdEmailIdMap.put(user.getId(),user.getEmailId());
|
|
|
126 |
}
|
|
|
127 |
return userIdEmailIdMap;
|
|
|
128 |
}
|
| 24099 |
amit.gupta |
129 |
|
|
|
130 |
|
|
|
131 |
@Override
|
|
|
132 |
public User authenticate(String emailMobile, String password) throws ProfitMandiBusinessException {
|
|
|
133 |
User user = userRepository.selectByEmailIdOrMobileNumber(emailMobile);
|
|
|
134 |
if(!user.getPassword().equals(encrypter.decrypt(password))) {
|
|
|
135 |
throw new ProfitMandiBusinessException("Username Password", emailMobile, "Invalid Username or Password");
|
|
|
136 |
}
|
|
|
137 |
return user;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
@Override
|
|
|
142 |
public boolean resetPassword(String emailMobile, String password) throws ProfitMandiBusinessException {
|
|
|
143 |
User user = userRepository.selectByEmailIdOrMobileNumber(emailMobile);
|
|
|
144 |
user.setPassword(encrypter.encrypt(password));
|
|
|
145 |
userRepository.persist(user);
|
|
|
146 |
return true;
|
|
|
147 |
}
|
| 23781 |
ashik.ali |
148 |
|
| 21525 |
amit.gupta |
149 |
}
|