You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
58 lines
1.7 KiB
package com.iflytop.nuclear.controller;
|
|
|
|
import com.iflytop.nuclear.model.Account;
|
|
import com.iflytop.nuclear.service.AccountService;
|
|
import com.iflytop.nuclear.utils.ResponseData;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @author cool
|
|
* @desc 用户接口
|
|
*/
|
|
@Slf4j
|
|
@RestController
|
|
@CrossOrigin
|
|
@RequestMapping("/account")
|
|
public class AccountController {
|
|
|
|
@Autowired
|
|
AccountService accountService;
|
|
|
|
/**
|
|
* 查询用户列表
|
|
* @return
|
|
*/
|
|
@GetMapping("/list")
|
|
public ResponseData getAccountList() {
|
|
log.info("-----------------查询账户列表开始-----------------");
|
|
List<Account> accounts = accountService.list();
|
|
// 筛除password
|
|
// TODO
|
|
log.info("-----------------查询账户列表结束-----------------");
|
|
return ResponseData.success(accounts);
|
|
}
|
|
|
|
/**
|
|
* 注册接口,需要有ADMIN权限
|
|
* @param registerUser
|
|
* @return
|
|
*/
|
|
@PostMapping("/register")
|
|
@PreAuthorize("hasRole('ADMIN')")
|
|
public ResponseData registerAccount(@RequestBody Map<String,String> registerUser) {
|
|
log.info("-----------------注册账户开始-----------------");
|
|
boolean register = accountService.register(registerUser.get("username"), registerUser.get("password"), registerUser.get("role"));
|
|
if (register) {
|
|
log.info("-----------------注册账户成功-----------------");
|
|
return ResponseData.success();
|
|
}
|
|
return ResponseData.fail("注册失败,用户名重复!");
|
|
}
|
|
|
|
}
|