Commit e987d372 authored by renjie's avatar renjie

第一版bug

parent 814d3b9b
...@@ -203,10 +203,10 @@ public class AccountController { ...@@ -203,10 +203,10 @@ public class AccountController {
} }
@RequestMapping(path = "/resetpassword", method = RequestMethod.POST) @RequestMapping(path = "/resetpassword", method = RequestMethod.POST)
public ResultDto forgetPassword(@Valid @RequestBody UserDto user) { public ResultDto forgetPassword(Principal principal, @RequestBody UserDto user) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
accountService.resetPassword(user); accountService.resetPassword(principal.getName(), user);
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { }catch (ClientRequestException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
......
...@@ -12,9 +12,9 @@ public class UserDto { ...@@ -12,9 +12,9 @@ public class UserDto {
private String phone; private String phone;
private String otp; private String authCode;
private String passwd; private String password;
public String getPhone() { public String getPhone() {
return phone; return phone;
...@@ -24,20 +24,20 @@ public class UserDto { ...@@ -24,20 +24,20 @@ public class UserDto {
this.phone = phone; this.phone = phone;
} }
public String getOtp() { public String getAuthCode() {
return otp; return authCode;
} }
public void setOtp(String otp) { public void setAuthCode(String authCode) {
this.otp = otp; this.authCode = authCode;
} }
public String getPasswd() { public String getPassword() {
return passwd; return password;
} }
public void setPasswd(String passwd) { public void setPassword(String password) {
this.passwd = passwd; this.password = password;
} }
public String getEmail() { public String getEmail() {
......
...@@ -42,7 +42,7 @@ public interface AccountService { ...@@ -42,7 +42,7 @@ public interface AccountService {
*/ */
Account saveChanges(String name, Account update); Account saveChanges(String name, Account update);
void resetPassword(UserDto user); void resetPassword(String username, UserDto user);
Account createSub(String name, AccountDto user); Account createSub(String name, AccountDto user);
......
...@@ -750,16 +750,13 @@ public class AccountServiceImpl implements AccountService { ...@@ -750,16 +750,13 @@ public class AccountServiceImpl implements AccountService {
} }
@Override @Override
public void resetPassword(UserDto user) { public void resetPassword(String username, UserDto user) {
if (user == null) if (user == null)
throw new ClientRequestException(AccountErrorCode.NAMEOREMAILNOTEXIST, "Can't find user with name or mail: " + user); throw new ClientRequestException(AccountErrorCode.NAMEOREMAILNOTEXIST, "Can't find user with name or mail: " + user);
Account account = repository.findByEmail(user.getEmail()); Account account = repository.findByName(user.getUsername());
if (account == null) { if (account == null) {
Account accountname = repository.findByName(user.getUsername()); throw new ClientRequestException(AccountErrorCode.NAMEOREMAILNOTEXIST, "Can't find user with name: " + user);
if (accountname == null)
throw new ClientRequestException(AccountErrorCode.NAMEOREMAILNOTEXIST, "Can't find user with name or mail: " + user);
account = accountname;
} }
User newuser = new User(); User newuser = new User();
...@@ -795,7 +792,7 @@ public class AccountServiceImpl implements AccountService { ...@@ -795,7 +792,7 @@ public class AccountServiceImpl implements AccountService {
if (otp == null) { if (otp == null) {
throw new ClientRequestException(AccountErrorCode.OTPWRONG, AccountErrorCode.OTPWRONG.getReason()); throw new ClientRequestException(AccountErrorCode.OTPWRONG, AccountErrorCode.OTPWRONG.getReason());
} }
if (!otp.getOtp().equals(user.getOtp())) { if (!otp.getOtp().equals(user.getAuthCode())) {
throw new ClientRequestException(AccountErrorCode.OTPWRONG, AccountErrorCode.OTPWRONG.getReason()); throw new ClientRequestException(AccountErrorCode.OTPWRONG, AccountErrorCode.OTPWRONG.getReason());
} }
...@@ -806,7 +803,7 @@ public class AccountServiceImpl implements AccountService { ...@@ -806,7 +803,7 @@ public class AccountServiceImpl implements AccountService {
User client = new User(); User client = new User();
client.setUsername(account.getName()); client.setUsername(account.getName());
client.setPassword(user.getPasswd()); client.setPassword(user.getPassword());
userAuthService.resetUserPassword(new com.edgec.browserbackend.auth.domain.User(client)); userAuthService.resetUserPassword(new com.edgec.browserbackend.auth.domain.User(client));
......
...@@ -33,7 +33,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -33,7 +33,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) throws Exception { public void configure(WebSecurity web) throws Exception {
web.ignoring() web.ignoring()
.antMatchers( "/user/authCode", "/user/signUp", .antMatchers( "/user/authCode", "/user/signUp",
"/user/reset*"); "/user/forgot**");
} }
@Override @Override
......
...@@ -35,7 +35,7 @@ public class Shop { ...@@ -35,7 +35,7 @@ public class Shop {
private String shopUA; private String shopUA;
private CharSequence shopCookie; private String shopCookie;
private long createTime; private long createTime;
...@@ -184,11 +184,11 @@ public class Shop { ...@@ -184,11 +184,11 @@ public class Shop {
this.shopPassword = shopPassword; this.shopPassword = shopPassword;
} }
public CharSequence getShopCookie() { public String getShopCookie() {
return shopCookie; return shopCookie;
} }
public void setShopCookie(CharSequence shopCookie) { public void setShopCookie(String shopCookie) {
this.shopCookie = shopCookie; this.shopCookie = shopCookie;
} }
......
...@@ -30,7 +30,7 @@ public class ShopResultDto { ...@@ -30,7 +30,7 @@ public class ShopResultDto {
private String shopUA; private String shopUA;
private CharSequence shopCookie; private String shopCookie;
private IpResource bindIp; private IpResource bindIp;
...@@ -151,11 +151,11 @@ public class ShopResultDto { ...@@ -151,11 +151,11 @@ public class ShopResultDto {
this.shopUA = shopUA; this.shopUA = shopUA;
} }
public CharSequence getShopCookie() { public String getShopCookie() {
return shopCookie; return shopCookie;
} }
public void setShopCookie(CharSequence shopCookie) { public void setShopCookie(String shopCookie) {
this.shopCookie = shopCookie; this.shopCookie = shopCookie;
} }
......
...@@ -169,7 +169,8 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -169,7 +169,8 @@ public class IpResourceServiceImpl implements IpResourceService {
String price = vendorPrices.stream() String price = vendorPrices.stream()
.filter(x -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(x.substring(0, x.indexOf("-")))) .filter(x -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(x.substring(0, x.indexOf("-"))))
.map(x -> x.substring(x.lastIndexOf("-") + 1)).collect(Collectors.joining()); .map(x -> x.substring(x.lastIndexOf("-") + 1)).collect(Collectors.joining());
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, Double.valueOf(price) * ipResourceRequestDto.getAmount()); double newprice = ipResourceRequestDto.getUnit().equals("week") ? (Integer.valueOf(price)/3) : Integer.valueOf(price);
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, newprice * ipResourceRequestDto.getAmount());
if (!ipChargeResultDto.isSuccess()) { if (!ipChargeResultDto.isSuccess()) {
throw new ClientRequestException(AccountErrorCode.NOTENOUGHBALANCE); throw new ClientRequestException(AccountErrorCode.NOTENOUGHBALANCE);
} }
...@@ -244,7 +245,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -244,7 +245,7 @@ public class IpResourceServiceImpl implements IpResourceService {
ipBuyResultDto = restTemplate.postForObject(URL + "/intelligroup/ipresources?accountId=browser", httpEntity, IpBuyResultDto.class); ipBuyResultDto = restTemplate.postForObject(URL + "/intelligroup/ipresources?accountId=browser", httpEntity, IpBuyResultDto.class);
if (StringUtils.isNotBlank(ipBuyResultDto.getErrorCode())) { if (StringUtils.isNotBlank(ipBuyResultDto.getErrorCode())) {
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1); IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1);
accountService.chargeByMoney(username, -Double.valueOf(price)*ipChargeRequestDto.getAmount(), ipChargeRequestDto); accountService.chargeByMoney(username, -newprice*ipChargeRequestDto.getAmount(), ipChargeRequestDto);
logger.error("fail to buy ip"); logger.error("fail to buy ip");
logger.error(ipBuyResultDto.getErrorCode()); logger.error(ipBuyResultDto.getErrorCode());
} }
...@@ -264,7 +265,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -264,7 +265,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}); });
if (ipBuyResultDto.getIplist().size() < ipResourceDtos.size()) { if (ipBuyResultDto.getIplist().size() < ipResourceDtos.size()) {
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1); IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1);
accountService.chargeByMoney(username, -Double.valueOf(price)*(ipResourceDtos.size() - ipBuyResultDto.getIplist().size()), ipChargeRequestDto); accountService.chargeByMoney(username, -newprice*(ipResourceDtos.size() - ipBuyResultDto.getIplist().size()), ipChargeRequestDto);
} }
} }
ipTransaction.setStatus(1); ipTransaction.setStatus(1);
...@@ -275,7 +276,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -275,7 +276,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}, ThreadPoolUtils.taskExecutorPool); }, ThreadPoolUtils.taskExecutorPool);
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1); IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1);
accountService.chargeByMoney(username, Double.valueOf(price) * ipChargeRequestDto.getAmount(), ipChargeRequestDto); accountService.chargeByMoney(username, newprice * ipChargeRequestDto.getAmount(), ipChargeRequestDto);
return ipTransactionDto; return ipTransactionDto;
} }
...@@ -294,7 +295,8 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -294,7 +295,8 @@ public class IpResourceServiceImpl implements IpResourceService {
.filter(vendorprice -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(vendorprice.substring(0, vendorprice.indexOf("-")))) .filter(vendorprice -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(vendorprice.substring(0, vendorprice.indexOf("-"))))
.map(vendorprice -> vendorprice.substring(vendorprice.lastIndexOf("-") + 1)).collect(Collectors.joining())).mapToDouble(Double::valueOf).sum(); .map(vendorprice -> vendorprice.substring(vendorprice.lastIndexOf("-") + 1)).collect(Collectors.joining())).mapToDouble(Double::valueOf).sum();
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, Double.valueOf(totalprice)); double newprice = ipResourceRequestDto.getUnit().equals("week") ? (int) (totalprice/3) : (int) totalprice;
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, newprice);
if (!ipChargeResultDto.isSuccess()) { if (!ipChargeResultDto.isSuccess()) {
throw new ClientRequestException(AccountErrorCode.NOTENOUGHBALANCE); throw new ClientRequestException(AccountErrorCode.NOTENOUGHBALANCE);
} }
...@@ -324,8 +326,9 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -324,8 +326,9 @@ public class IpResourceServiceImpl implements IpResourceService {
.filter(vendorprice -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(vendorprice.substring(0, vendorprice.indexOf("-")))) .filter(vendorprice -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(vendorprice.substring(0, vendorprice.indexOf("-"))))
.map(vendorprice -> vendorprice.substring(vendorprice.lastIndexOf("-") + 1)).collect(Collectors.joining()); .map(vendorprice -> vendorprice.substring(vendorprice.lastIndexOf("-") + 1)).collect(Collectors.joining());
double newprice1 = ipResourceRequestDto.getUnit().equals("week") ? (Integer.valueOf(price)/3) : Integer.valueOf(price);
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 2); IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 2);
accountService.chargeByMoney(username, Double.valueOf(price), ipChargeRequestDto); accountService.chargeByMoney(username, newprice1, ipChargeRequestDto);
ipResource.setValidTime(Instant.parse(x.getValidTill()).toEpochMilli()); ipResource.setValidTime(Instant.parse(x.getValidTill()).toEpochMilli());
ipResourceRepository.save(ipResource); ipResourceRepository.save(ipResource);
......
...@@ -80,6 +80,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -80,6 +80,7 @@ public class ShopServiceImpl implements ShopService {
shopResultDto.setOwner(username); shopResultDto.setOwner(username);
Shop shop = new Shop(); Shop shop = new Shop();
shop.of(shopResultDto); shop.of(shopResultDto);
shop.setCreateTime(Instant.now().toEpochMilli());
id = shopRepository.save(shop).getShopId(); id = shopRepository.save(shop).getShopId();
UserShop userShop = new UserShop(); UserShop userShop = new UserShop();
userShop.setUsername(username); userShop.setUsername(username);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment