Commit 97bc113a authored by renjie's avatar renjie

密码bug

parent ca824f15
...@@ -20,7 +20,7 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter ...@@ -20,7 +20,7 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/oauth/**").permitAll() .antMatchers("/oauth/**").permitAll()
.antMatchers("/shop/*","/ip/*","/group/*","/0xadministrator/*","/user/*").authenticated() .antMatchers("/shop/*","/ip/*","/group/*","/0xadministrator/*","/user/*","/history/*").authenticated()
.and() .and()
//关闭跨站请求防护 //关闭跨站请求防护
.csrf().disable(); .csrf().disable();
......
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.OperationHistory;
import com.edgec.browserbackend.browser.dto.HistoryListRequestDto;
import com.edgec.browserbackend.browser.dto.IpResourceRequestDto;
import com.edgec.browserbackend.browser.dto.LoginHistoryDto;
import com.edgec.browserbackend.browser.dto.OperationHistoryDto;
import com.edgec.browserbackend.browser.service.HistoryService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.security.Principal;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/history")
public class HistoryController {
@Autowired
HistoryService historyService;
@RequestMapping(value = "/login/add", method = RequestMethod.POST)
public ResultDto addLoginHistory(Principal principal, @RequestBody LoginHistoryDto loginHistoryDto) {
ResultDto resultDto = new ResultDto();
try {
historyService.addLoginHistory(principal.getName(), loginHistoryDto);
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(value = "/operation/add", method = RequestMethod.POST)
public ResultDto addOperationHistory(Principal principal, @RequestBody OperationHistoryDto operationHistoryDto) {
ResultDto resultDto = new ResultDto();
try {
historyService.addOperationHistory(principal.getName(), operationHistoryDto);
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(value = "/login/list", method = RequestMethod.POST)
public ResultDto getLoginHistories(Principal principal, @RequestBody HistoryListRequestDto historyListRequestDto) {
ResultDto resultDto = new ResultDto();
try {
resultDto.setData(historyService.getLoginHistories(principal.getName(), historyListRequestDto));
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(value = "/operation/list", method = RequestMethod.POST)
public ResultDto getOperationHistories(Principal principal, @RequestBody HistoryListRequestDto historyListRequestDto) {
ResultDto resultDto = new ResultDto();
try {
resultDto.setData(historyService.getOperationHistories(principal.getName(), historyListRequestDto));
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;
}
}
...@@ -6,6 +6,7 @@ import org.springframework.data.domain.Pageable; ...@@ -6,6 +6,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
public interface LoginHistoryRepository extends MongoRepository<LoginHistory, String> { public interface LoginHistoryRepository extends MongoRepository<LoginHistory, String> {
Page<LoginHistory> findByAdministratorOrderByLoginTime(String account, Pageable pageable); Page<LoginHistory> findByAdministratorOrderByLoginTime(String administrator, Pageable pageable);
Page<LoginHistory> findByAccountOrderByLoginTime(String account, Pageable pageable);
} }
package com.edgec.browserbackend.browser.repository; package com.edgec.browserbackend.browser.repository;
public interface OperationHistoryRepository { import com.edgec.browserbackend.browser.domain.OperationHistory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface OperationHistoryRepository extends MongoRepository<OperationHistory, String> {
Page<OperationHistory> findByAdministratorOrderByOperationTimeDesc(String administrator, Pageable pageable);
Page<OperationHistory> findByAccountOrderByOperationTimeDesc(String account, Pageable pageable);
} }
package com.edgec.browserbackend.browser.service.Impl; package com.edgec.browserbackend.browser.service.Impl;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.domain.LoginHistory; import com.edgec.browserbackend.browser.domain.LoginHistory;
import com.edgec.browserbackend.browser.domain.OperationHistory; import com.edgec.browserbackend.browser.domain.OperationHistory;
import com.edgec.browserbackend.browser.dto.*; import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.LoginHistoryRepository; import com.edgec.browserbackend.browser.repository.LoginHistoryRepository;
import com.edgec.browserbackend.browser.repository.OperationHistoryRepository; import com.edgec.browserbackend.browser.repository.OperationHistoryRepository;
import com.edgec.browserbackend.browser.service.HistoryService; import com.edgec.browserbackend.browser.service.HistoryService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service
public class HistoryServiceImpl implements HistoryService { public class HistoryServiceImpl implements HistoryService {
@Autowired
private AccountRepository accountRepository;
@Autowired @Autowired
private LoginHistoryRepository loginHistoryRepository; private LoginHistoryRepository loginHistoryRepository;
...@@ -26,23 +35,54 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -26,23 +35,54 @@ public class HistoryServiceImpl implements HistoryService {
@Override @Override
public void addLoginHistory(String username, LoginHistoryDto loginHistoryDto) { public void addLoginHistory(String username, LoginHistoryDto loginHistoryDto) {
Account account = accountRepository.findById(username).orElse(null);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
LoginHistory loginHistory = new LoginHistory(loginHistoryDto); LoginHistory loginHistory = new LoginHistory(loginHistoryDto);
loginHistory.setLoginTime(Instant.now().toEpochMilli()); loginHistory.setLoginTime(Instant.now().toEpochMilli());
loginHistory.setAccount(username);
if (account.getParent() == null)
loginHistory.setAdministrator(username);
else
loginHistory.setAdministrator(account.getParent());
loginHistory.setNickname(account.getNickname());
loginHistoryRepository.save(loginHistory); loginHistoryRepository.save(loginHistory);
} }
@Override @Override
public void addOperationHistory(String username, OperationHistoryDto operationHistoryDto) { public void addOperationHistory(String username, OperationHistoryDto operationHistoryDto) {
Account account = accountRepository.findById(username).orElse(null);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
OperationHistory operationHistory = new OperationHistory(operationHistoryDto);
operationHistory.setOperationTime(Instant.now().toEpochMilli());
operationHistory.setAccount(username);
operationHistory.setNickname(account.getNickname());
if (account.getParent() == null)
operationHistory.setAdministrator(username);
else
operationHistory.setAdministrator(account.getParent());
operationHistoryRepository.save(operationHistory);
} }
@Override @Override
public HistoryPageResultDto getLoginHistories(String username, HistoryListRequestDto historyListRequestDto) { public HistoryPageResultDto getLoginHistories(String username, HistoryListRequestDto historyListRequestDto) {
Account account = accountRepository.findById(username).orElse(null);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getPermission() < 8)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
if (historyListRequestDto.getAmount() > 100) if (historyListRequestDto.getAmount() > 100)
historyListRequestDto.setAmount(100); historyListRequestDto.setAmount(100);
Pageable pageable = PageRequest.of(historyListRequestDto.getPage(), historyListRequestDto.getAmount()); Pageable pageable = PageRequest.of(historyListRequestDto.getPage(), historyListRequestDto.getAmount());
HistoryPageResultDto historyPageResultDto = new HistoryPageResultDto(); HistoryPageResultDto historyPageResultDto = new HistoryPageResultDto();
Page<LoginHistory> loginHistoryPage = loginHistoryRepository.findByAdministratorOrderByLoginTime(username, pageable); Page<LoginHistory> loginHistoryPage;
if (account.getParent() == null) {
loginHistoryPage = loginHistoryRepository.findByAdministratorOrderByLoginTime(username, pageable);
} else {
loginHistoryPage = loginHistoryRepository.findByAccountOrderByLoginTime(username, pageable);
}
List<LoginHistoryDto> loginHistoryDtoList = new ArrayList<>(); List<LoginHistoryDto> loginHistoryDtoList = new ArrayList<>();
loginHistoryPage.getContent().forEach(x -> { loginHistoryPage.getContent().forEach(x -> {
loginHistoryDtoList.add(new LoginHistoryDto(x)); loginHistoryDtoList.add(new LoginHistoryDto(x));
...@@ -58,6 +98,32 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -58,6 +98,32 @@ public class HistoryServiceImpl implements HistoryService {
@Override @Override
public HistoryPageResultDto getOperationHistories(String username, HistoryListRequestDto historyListRequestDto) { public HistoryPageResultDto getOperationHistories(String username, HistoryListRequestDto historyListRequestDto) {
return null; Account account = accountRepository.findById(username).orElse(null);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getPermission() < 8)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
if (historyListRequestDto.getAmount() > 100)
historyListRequestDto.setAmount(100);
Pageable pageable = PageRequest.of(historyListRequestDto.getPage(), historyListRequestDto.getAmount());
HistoryPageResultDto historyPageResultDto = new HistoryPageResultDto();
Page<OperationHistory> operationHistories;
if (account.getParent() == null) {
operationHistories = operationHistoryRepository.findByAdministratorOrderByOperationTimeDesc(username, pageable);
} else {
operationHistories = operationHistoryRepository.findByAccountOrderByOperationTimeDesc(username, pageable);
}
List<OperationHistoryDto> operationHistoryDtos = new ArrayList<>();
operationHistories.getContent().forEach(x -> {
operationHistoryDtos.add(new OperationHistoryDto(x));
});
historyPageResultDto.setHistory(operationHistoryDtos);
PageInfo pageInfo = new PageInfo();
pageInfo.setCurrentPage(operationHistories.getNumber());
pageInfo.setTotalPages(operationHistories.getTotalPages());
pageInfo.setTotalItems((int)operationHistories.getTotalElements());
historyPageResultDto.setHistoryPage(pageInfo);
return historyPageResultDto;
} }
} }
...@@ -124,7 +124,7 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -124,7 +124,7 @@ public class IpResourceServiceImpl implements IpResourceService {
break; break;
} }
int len = strTable.length(); int len = strTable.length() - 3;
boolean bDone = true; boolean bDone = true;
do { do {
retStr = ""; retStr = "";
...@@ -142,6 +142,9 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -142,6 +142,9 @@ public class IpResourceServiceImpl implements IpResourceService {
bDone = false; bDone = false;
} }
} while (bDone); } while (bDone);
retStr += "a";
retStr += "A";
retStr += "1";
return retStr; return retStr;
} }
......
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