Commit 8fa22f5a authored by renjie's avatar renjie

修改接口bug

parent 2d3ef609
......@@ -156,24 +156,6 @@ public class AccountController {
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)
public void contactus(Principal principal, @Valid @RequestBody ContactUs contactUs) {
......@@ -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)
void updateUserToken(@RequestParam("username") String username, @RequestParam("token") String 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)
public ResultDto forgetPassword(@Valid @RequestBody UserDto user) {
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 {
private String phone;
private String otp;
private String authCode;
private boolean enabled = false;
private String lockReason;
public String getOtp() {
return otp;
public String getAuthCode() {
return authCode;
}
public void setOtp(String otp) {
this.otp = otp;
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
public String getPhone() {
......
......@@ -563,8 +563,6 @@ public class AccountServiceImpl implements AccountService {
@Override
public Account createWithSms(User user) {
boolean isVps = true;
Account existing = repository.findByName(user.getUsername());
if (existing != null)
throw new ClientRequestException(AccountErrorCode.NAMEEXIST, "account already exists: " + user.getUsername());
......@@ -581,12 +579,12 @@ public class AccountServiceImpl implements AccountService {
if (existing != null)
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) {
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());
} else {
// otpRepository.delete(otp);
......@@ -597,7 +595,8 @@ public class AccountServiceImpl implements AccountService {
account.setName(user.getUsername());
account.setLastSeen(new Date());
account.setEmail(user.getEmail());
account.setPhoneNumber(user.getPhone());
account.setPhoneNumber(user.getUsername());
account.setPermission(15);
account.setAllowedToCreateSubUser(true);
......@@ -608,10 +607,6 @@ public class AccountServiceImpl implements AccountService {
log.info("new account has been created: " + account.getName());
if (isVps) {
SmsUtils.notifyNewUserRegistered(user.getUsername(), user.getPhone(), isVps ? "是" : "否");
}
notifyCustomerRegister(account);
return account;
}
......
......@@ -47,7 +47,7 @@ public class OAuth2AuthorizationConfig extends AuthorizationServerConfigurerAdap
clients.inMemory()
.withClient("browser")
.authorizedGrantTypes("refresh_token", "password")
.scopes("ui")
.scopes("browser")
.and()
.withClient("cloudam-browser")
.secret(env.getProperty("ACCOUNT_SERVICE_PASSWORD"))
......
......@@ -15,10 +15,8 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter
private Logger logger = LoggerFactory.getLogger(ResourceServerConfiguration.class);
@Override
public void configure(HttpSecurity http) throws Exception {
logger.info("=========================111111111=========");
http.exceptionHandling()
.and()
.logout()
......
......@@ -26,7 +26,9 @@ public class GroupController {
public ResultDto addGroup(Principal principal, @RequestBody GroupDto groupDto) {
ResultDto resultDto = new ResultDto();
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);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
......@@ -58,7 +60,7 @@ public class GroupController {
public ResultDto deleteGroup(Principal principal, @RequestBody GroupDto groupDto) {
ResultDto resultDto = new ResultDto();
try {
groupService.addGroup(principal.getName(), groupDto.getGroupName());
groupService.deleteGroup(principal.getName(), groupDto.getId());
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
......@@ -70,8 +72,21 @@ public class GroupController {
return resultDto;
}
List<GroupDto> getGroupList(String username) {
return null;
@RequestMapping("/list")
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 {
public ResultDto addShop(Principal principal, @RequestBody Shop shop) {
ResultDto resultDto = new ResultDto();
try {
shopService.addShop(principal.getName(), shop);
ShopDto shopDto = new ShopDto();
shopDto.setId(shopService.addShop(principal.getName(), shop));
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
......@@ -50,7 +51,9 @@ public class ShopController {
public ResultDto updateShop(Principal principal, @RequestBody Shop shop) {
ResultDto resultDto = new ResultDto();
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);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
......
......@@ -5,7 +5,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Document("usershops")
@Document(collection = "usershops")
public class UserShop {
@Id
......
......@@ -14,7 +14,9 @@ public class GroupDto {
}
public GroupDto(String id, String groupName, String details){
this.id = id;
this.groupName = groupName;
this.details = details;
}
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