init
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.backend.webbackend.Controller;
|
||||
|
||||
import com.backend.webbackend.Service.userService;
|
||||
import com.backend.webbackend.Tools.Tools;
|
||||
import com.backend.webbackend.Vo.ResultVo;
|
||||
import com.backend.webbackend.domain.User;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("user")
|
||||
public class userController {
|
||||
@Autowired
|
||||
userService userService;
|
||||
@Autowired
|
||||
private Tools tools;
|
||||
|
||||
|
||||
//返回所有部门信息:用于用户注册时选择部门
|
||||
@GetMapping("dept")
|
||||
public ResultVo getAllDept(){
|
||||
return ResultVo.Success("",userService.getAlldept());
|
||||
}
|
||||
|
||||
//用户注册
|
||||
@PostMapping("register")
|
||||
public ResultVo register(@RequestBody User user){
|
||||
if(userService.register(user)){
|
||||
return ResultVo.Success("","注册成功");
|
||||
}
|
||||
else {
|
||||
return ResultVo.Error("","注册失败");
|
||||
}
|
||||
}
|
||||
|
||||
//用户登录
|
||||
@PostMapping("login")
|
||||
public ResultVo login(@RequestBody User user) {
|
||||
if(!userService.login(user.getUsername(),user.getPassword())){
|
||||
return ResultVo.Error("","用户名或密码错误");
|
||||
}
|
||||
return ResultVo.Success("","登陆成功");
|
||||
}
|
||||
|
||||
//用户信息修改
|
||||
@PostMapping("update")
|
||||
public ResultVo updateUserInfo(@RequestBody User user){
|
||||
try
|
||||
{
|
||||
//密码加密
|
||||
user.setPassword(tools.encryptPassword(user.getPassword()));
|
||||
userService.updateUserInfo(user);
|
||||
return ResultVo.Success("","用户信息修改成功");
|
||||
}
|
||||
catch (Exception e){
|
||||
throw new RuntimeException("用户信息修改失败");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user