Commit 8fa22f5a authored by renjie's avatar renjie

修改接口bug

parent 2d3ef609
...@@ -156,24 +156,6 @@ public class AccountController { ...@@ -156,24 +156,6 @@ public class AccountController {
return resultDto; return resultDto;
} }
@RequestMapping(path = "/current", method = RequestMethod.POST)
public ResultDto createSubAccount(Principal principal, @Valid @RequestBody AccountDto user) {
ResultDto resultDto = new ResultDto();
try {
LimitedUsers.filterIfLimitedUser(principal);
Account account = accountService.createSub(principal.getName(), user);
resultDto.setStatus(0);
resultDto.setData(account);
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
@RequestMapping(path = "/contactus", method = RequestMethod.POST) @RequestMapping(path = "/contactus", method = RequestMethod.POST)
public void contactus(Principal principal, @Valid @RequestBody ContactUs contactUs) { public void contactus(Principal principal, @Valid @RequestBody ContactUs contactUs) {
...@@ -225,47 +207,11 @@ public class AccountController { ...@@ -225,47 +207,11 @@ public class AccountController {
} }
@RequestMapping(path = "/current/{child}", method = RequestMethod.PUT)
public ResultDto saveSubAccount(Principal principal, @PathVariable String child, @Valid @RequestBody AccountDto user) {
ResultDto resultDto = new ResultDto();
try {
LimitedUsers.filterIfLimitedUser(principal);
Account account1 =accountService.saveSub(principal.getName(), user);
resultDto.setStatus(0);
resultDto.setData(account1);
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
@RequestMapping(path = "/current/updatetoken", method = RequestMethod.POST) @RequestMapping(path = "/current/updatetoken", method = RequestMethod.POST)
void updateUserToken(@RequestParam("username") String username, @RequestParam("token") String token) { void updateUserToken(@RequestParam("username") String username, @RequestParam("token") String token) {
accountService.updateUserToken(username, token); accountService.updateUserToken(username, token);
} }
@RequestMapping(path = "/current/{child}", method = RequestMethod.DELETE)
public ResultDto deleteSubAccount(Principal principal, @PathVariable String child) {
ResultDto resultDto = new ResultDto();
try {
LimitedUsers.filterIfLimitedUser(principal);
accountService.deleteSub(principal.getName(), child);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
@RequestMapping(path = "/reset", method = RequestMethod.POST) @RequestMapping(path = "/reset", method = RequestMethod.POST)
public ResultDto forgetPassword(@Valid @RequestBody UserDto user) { public ResultDto forgetPassword(@Valid @RequestBody UserDto user) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
......
package com.edgec.browserbackend.account.controller;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.AccountDto;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.account.service.AccountService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.security.Principal;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/admin")
public class AdminController {
@Autowired
AccountService accountService;
@RequestMapping(path = "/subuser/add", method = RequestMethod.POST)
public ResultDto createSubAccount(Principal principal, @Valid @RequestBody AccountDto user) {
ResultDto resultDto = new ResultDto();
try {
LimitedUsers.filterIfLimitedUser(principal);
Account account = accountService.createSub(principal.getName(), user);
resultDto.setStatus(0);
resultDto.setData(account);
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
@RequestMapping(path = "/subuser/update", method = RequestMethod.PUT)
public ResultDto saveSubAccount(Principal principal, @PathVariable String child, @Valid @RequestBody AccountDto user) {
ResultDto resultDto = new ResultDto();
try {
LimitedUsers.filterIfLimitedUser(principal);
Account account1 =accountService.saveSub(principal.getName(), user);
resultDto.setStatus(0);
resultDto.setData(account1);
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
@RequestMapping(path = "/subuser/del", method = RequestMethod.DELETE)
public ResultDto deleteSubAccount(Principal principal, @PathVariable String child) {
ResultDto resultDto = new ResultDto();
try {
LimitedUsers.filterIfLimitedUser(principal);
accountService.deleteSub(principal.getName(), child);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
}
...@@ -20,18 +20,18 @@ public class User { ...@@ -20,18 +20,18 @@ public class User {
private String phone; private String phone;
private String otp; private String authCode;
private boolean enabled = false; private boolean enabled = false;
private String lockReason; private String lockReason;
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 getPhone() { public String getPhone() {
......
...@@ -563,8 +563,6 @@ public class AccountServiceImpl implements AccountService { ...@@ -563,8 +563,6 @@ public class AccountServiceImpl implements AccountService {
@Override @Override
public Account createWithSms(User user) { public Account createWithSms(User user) {
boolean isVps = true;
Account existing = repository.findByName(user.getUsername()); Account existing = repository.findByName(user.getUsername());
if (existing != null) if (existing != null)
throw new ClientRequestException(AccountErrorCode.NAMEEXIST, "account already exists: " + user.getUsername()); throw new ClientRequestException(AccountErrorCode.NAMEEXIST, "account already exists: " + user.getUsername());
...@@ -581,12 +579,12 @@ public class AccountServiceImpl implements AccountService { ...@@ -581,12 +579,12 @@ public class AccountServiceImpl implements AccountService {
if (existing != null) if (existing != null)
throw new ClientRequestException(AccountErrorCode.PHONEEXIST, "phone number already exists: " + user.getPhone()); throw new ClientRequestException(AccountErrorCode.PHONEEXIST, "phone number already exists: " + user.getPhone());
Otp otp = otpRepository.findByPhoneAndCreatedAtGreaterThanEqual(user.getPhone(), Instant.now().minusSeconds(600).toEpochMilli()); Otp otp = otpRepository.findByPhoneAndCreatedAtGreaterThanEqual(user.getUsername(), Instant.now().minusSeconds(600).toEpochMilli());
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());
} else { } else {
// otpRepository.delete(otp); // otpRepository.delete(otp);
...@@ -597,7 +595,8 @@ public class AccountServiceImpl implements AccountService { ...@@ -597,7 +595,8 @@ public class AccountServiceImpl implements AccountService {
account.setName(user.getUsername()); account.setName(user.getUsername());
account.setLastSeen(new Date()); account.setLastSeen(new Date());
account.setEmail(user.getEmail()); account.setEmail(user.getEmail());
account.setPhoneNumber(user.getPhone()); account.setPhoneNumber(user.getUsername());
account.setPermission(15);
account.setAllowedToCreateSubUser(true); account.setAllowedToCreateSubUser(true);
...@@ -608,10 +607,6 @@ public class AccountServiceImpl implements AccountService { ...@@ -608,10 +607,6 @@ public class AccountServiceImpl implements AccountService {
log.info("new account has been created: " + account.getName()); log.info("new account has been created: " + account.getName());
if (isVps) {
SmsUtils.notifyNewUserRegistered(user.getUsername(), user.getPhone(), isVps ? "是" : "否");
}
notifyCustomerRegister(account); notifyCustomerRegister(account);
return account; return account;
} }
......
...@@ -47,7 +47,7 @@ public class OAuth2AuthorizationConfig extends AuthorizationServerConfigurerAdap ...@@ -47,7 +47,7 @@ public class OAuth2AuthorizationConfig extends AuthorizationServerConfigurerAdap
clients.inMemory() clients.inMemory()
.withClient("browser") .withClient("browser")
.authorizedGrantTypes("refresh_token", "password") .authorizedGrantTypes("refresh_token", "password")
.scopes("ui") .scopes("browser")
.and() .and()
.withClient("cloudam-browser") .withClient("cloudam-browser")
.secret(env.getProperty("ACCOUNT_SERVICE_PASSWORD")) .secret(env.getProperty("ACCOUNT_SERVICE_PASSWORD"))
......
...@@ -15,10 +15,8 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter ...@@ -15,10 +15,8 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter
private Logger logger = LoggerFactory.getLogger(ResourceServerConfiguration.class); private Logger logger = LoggerFactory.getLogger(ResourceServerConfiguration.class);
@Override @Override
public void configure(HttpSecurity http) throws Exception { public void configure(HttpSecurity http) throws Exception {
logger.info("=========================111111111=========");
http.exceptionHandling() http.exceptionHandling()
.and() .and()
.logout() .logout()
......
...@@ -26,7 +26,9 @@ public class GroupController { ...@@ -26,7 +26,9 @@ public class GroupController {
public ResultDto addGroup(Principal principal, @RequestBody GroupDto groupDto) { public ResultDto addGroup(Principal principal, @RequestBody GroupDto groupDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
groupService.addGroup(principal.getName(), groupDto.getGroupName()); GroupDto groupDto1 = new GroupDto();
groupDto1.setId(groupService.addGroup(principal.getName(), groupDto.getGroupName()));
resultDto.setData(groupDto1);
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { }catch (ClientRequestException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
...@@ -58,7 +60,7 @@ public class GroupController { ...@@ -58,7 +60,7 @@ public class GroupController {
public ResultDto deleteGroup(Principal principal, @RequestBody GroupDto groupDto) { public ResultDto deleteGroup(Principal principal, @RequestBody GroupDto groupDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
groupService.addGroup(principal.getName(), groupDto.getGroupName()); groupService.deleteGroup(principal.getName(), groupDto.getId());
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { }catch (ClientRequestException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
...@@ -70,8 +72,21 @@ public class GroupController { ...@@ -70,8 +72,21 @@ public class GroupController {
return resultDto; return resultDto;
} }
List<GroupDto> getGroupList(String username) { @RequestMapping("/list")
return null; public ResultDto getGroupList(Principal principal) {
ResultDto resultDto = new ResultDto();
try {
List<GroupDto> groupDtos = groupService.getGroupList(principal.getName());
resultDto.setData(groupDtos);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
} }
} }
...@@ -29,7 +29,8 @@ public class ShopController { ...@@ -29,7 +29,8 @@ public class ShopController {
public ResultDto addShop(Principal principal, @RequestBody Shop shop) { public ResultDto addShop(Principal principal, @RequestBody Shop shop) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
shopService.addShop(principal.getName(), shop); ShopDto shopDto = new ShopDto();
shopDto.setId(shopService.addShop(principal.getName(), shop));
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { }catch (ClientRequestException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
...@@ -50,7 +51,9 @@ public class ShopController { ...@@ -50,7 +51,9 @@ public class ShopController {
public ResultDto updateShop(Principal principal, @RequestBody Shop shop) { public ResultDto updateShop(Principal principal, @RequestBody Shop shop) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
resultDto.setData(shopService.updateShop(principal.getName(), shop)); ShopDto shopDto = new ShopDto();
shopDto.setId(shopService.updateShop(principal.getName(), shop));
resultDto.setData(shopDto);
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { }catch (ClientRequestException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
......
...@@ -5,7 +5,7 @@ import org.springframework.data.mongodb.core.mapping.Document; ...@@ -5,7 +5,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List; import java.util.List;
@Document("usershops") @Document(collection = "usershops")
public class UserShop { public class UserShop {
@Id @Id
......
...@@ -14,7 +14,9 @@ public class GroupDto { ...@@ -14,7 +14,9 @@ public class GroupDto {
} }
public GroupDto(String id, String groupName, String details){ public GroupDto(String id, String groupName, String details){
this.id = id;
this.groupName = groupName;
this.details = details;
} }
public String getDetails() { public String getDetails() {
......
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