Search in sources :

Example 1 with Admin

use of com.yh.weatherpush.entity.Admin in project weather-push by yangh124.

the class AdminController method info.

@ApiOperation("获取用户信息")
@GetMapping("/info")
public Result<JSONObject> info(Principal principal) {
    if (principal == null) {
        return Result.unauthorized(null);
    }
    String username = principal.getName();
    Admin admin = adminService.getAdminByUsername(username);
    JSONObject result = new JSONObject();
    result.put("name", admin.getNickName());
    result.put("avatar", admin.getAvatar());
    return Result.success(result);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Admin(com.yh.weatherpush.entity.Admin) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with Admin

use of com.yh.weatherpush.entity.Admin in project weather-push by yangh124.

the class AdminServiceImpl method updatePassword.

@CacheEvict(value = "admin", key = "#updPwdParam.username")
@Override
public void updatePassword(UpdPwdParam updPwdParam) {
    Admin admin = getAdminByUsername(updPwdParam.getUsername());
    boolean matches = passwordEncoder.matches(updPwdParam.getOldPassword(), admin.getPassword());
    if (!matches) {
        throw new ApiException("原密码错误");
    }
    String newPassword = updPwdParam.getNewPassword();
    String confirmPassword = updPwdParam.getConfirmPassword();
    if (!newPassword.equals(confirmPassword)) {
        throw new ApiException("确认密码与新密码不一致!");
    }
    String pwd = passwordEncoder.encode(newPassword);
    LambdaUpdateWrapper<Admin> updateWrapper = new UpdateWrapper<Admin>().lambda().set(Admin::getPassword, pwd).eq(Admin::getId, admin.getId());
    update(updateWrapper);
}
Also used : Admin(com.yh.weatherpush.entity.Admin) ApiException(com.yh.weatherpush.exception.ApiException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Aggregations

Admin (com.yh.weatherpush.entity.Admin)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ApiException (com.yh.weatherpush.exception.ApiException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 CacheEvict (org.springframework.cache.annotation.CacheEvict)1