| | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.matrix.component.redis.RedisClient; |
| | | import com.matrix.core.constance.MatrixConstance; |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.core.tools.StringUtils; |
| | | import com.matrix.core.tools.UUIDUtil; |
| | | import com.matrix.core.tools.WebUtil; |
| | | import com.matrix.system.app.authority.AppAuthorityManager; |
| | | import com.matrix.system.app.dto.LoginDto; |
| | | import com.matrix.system.app.dto.PwdResetDto; |
| | | import com.matrix.system.app.dto.SmsCodeDto; |
| | | import com.matrix.system.app.dto.UploadPhotoDto; |
| | | import com.matrix.system.app.vo.UserInfoVo; |
| | | import com.matrix.system.common.authority.DefaultAuthorityManager; |
| | | import com.matrix.system.common.authority.strategy.AccountPasswordLogin; |
| | | import com.matrix.system.common.authority.strategy.LoginStrategy; |
| | | import com.matrix.system.common.bean.SysUsers; |
| | | import com.matrix.system.common.service.SysUsersService; |
| | | import com.matrix.system.common.tools.PasswordUtil; |
| | | import com.matrix.system.hive.bean.SysShopInfo; |
| | | import com.matrix.system.hive.plugin.util.CollectionUtils; |
| | | import com.matrix.system.hive.plugin.util.ImageUtil; |
| | | import com.matrix.system.hive.service.SysShopInfoService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiResponse; |
| | | import io.swagger.annotations.ApiResponses; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | private SysShopInfoService sysShopInfoService; |
| | | |
| | | @Autowired |
| | | private DefaultAuthorityManager authorityManager; |
| | | private AppAuthorityManager authorityManager; |
| | | |
| | | @Autowired |
| | | private RedisClient redisClient; |
| | | |
| | | @Value("${file_storage_path}") |
| | | private String fileStoragePath; |
| | | @Value("${static_resource_url}") |
| | | private String nginxUrl; |
| | | |
| | | @ApiOperation(value = "登陆接口", notes = "手机端登陆接口") |
| | | @ApiResponses({ |
| | |
| | | userInfoVo.setPhoto(user.getSuPhoto()); |
| | | |
| | | AjaxResult result = AjaxResult.buildSuccessInstance("登陆成功"); |
| | | authorityManager.initUserPower(result,user); |
| | | result.putInMap("user", userInfoVo); |
| | | result.putInMap("token", token); |
| | | return result; |
| | | } |
| | | |
| | | @ApiOperation(value = "退出登陆", notes = "退出登陆") |
| | | @GetMapping(value = "/loginOut") |
| | | public AjaxResult loginOut() { |
| | | SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); |
| | | String token = redisClient.getCachedValue(sysUsers.getSuId().toString()); |
| | | @ApiOperation(value = "图片上传接口", notes = "图片上传接口") |
| | | @PostMapping(value = "/uploadPhotoBase64") |
| | | public AjaxResult uploadPhotoBase64(@RequestBody @Validated UploadPhotoDto uploadPhotoDto) { |
| | | // 文件保存目录路径 |
| | | String savePath = fileStoragePath; |
| | | // 文件保存目录URL |
| | | String saveUrl = nginxUrl; |
| | | |
| | | redisClient.removeObject(token); |
| | | redisClient.removeObject(sysUsers.getSuId().toString()); |
| | | return AjaxResult.buildSuccessInstance("退出成功"); |
| | | // 保存和访问路径检查 |
| | | if (StringUtils.isBlank(saveUrl) || StringUtils.isBlank(savePath)) { |
| | | return AjaxResult.buildFailInstance("文件上传失败错误代码:001"); |
| | | } |
| | | |
| | | // 检查目录 |
| | | File uploadDir = new File(savePath); |
| | | if (!uploadDir.isDirectory()) { |
| | | uploadDir.mkdir(); |
| | | } |
| | | |
| | | String fileName = ImageUtil.base64ToFile(uploadPhotoDto.getBase64(), savePath, UUIDUtil.getRandomID() + ".png"); |
| | | LogUtil.info("fileName : {}", fileName); |
| | | |
| | | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("上传成功"); |
| | | ajaxResult.putInMap("file", saveUrl + fileName); |
| | | return ajaxResult; |
| | | } |
| | | |
| | | @ApiOperation(value = "短信验证码发送", notes = "短信验证码发送") |
| | | @PostMapping(value = "/sendSmsCode") |
| | | public AjaxResult sendSmsCode(@RequestBody @Validated SmsCodeDto smsCodeDto) { |
| | | SysUsers user = new SysUsers(); |
| | | user.setSuTel(smsCodeDto.getTelphone()); |
| | | List<SysUsers> users = sysUsersService.findByModel(user); |
| | | if (CollectionUtils.isEmpty(users)) { |
| | | return AjaxResult.buildFailInstance("该手机号不存在"); |
| | | } |
| | | |
| | | String codeExist = redisClient.getCachedValue(smsCodeDto.getTelphone()); |
| | | if (StringUtils.isNotBlank(codeExist)) { |
| | | return AjaxResult.buildFailInstance("请勿重复发送验证码"); |
| | | } |
| | | redisClient.saveValue(smsCodeDto.getTelphone(), "123456", 120); |
| | | return AjaxResult.buildSuccessInstance("发送成功"); |
| | | } |
| | | |
| | | @ApiOperation(value = "重置登陆密码", notes = "重置登陆密码") |
| | | @PostMapping(value = "/resetLoginPwd") |
| | | public AjaxResult resetLoginPwd(@RequestBody @Validated PwdResetDto pwdResetDto) throws UnsupportedEncodingException, NoSuchAlgorithmException { |
| | | SysUsers user = new SysUsers(); |
| | | user.setSuTel(pwdResetDto.getTelphone()); |
| | | List<SysUsers> users = sysUsersService.findByModel(user); |
| | | if (CollectionUtils.isEmpty(users)) { |
| | | return AjaxResult.buildFailInstance("该手机号不存在"); |
| | | } |
| | | |
| | | String code = redisClient.getCachedValue(pwdResetDto.getTelphone()); |
| | | if (StringUtils.isBlank(code)) { |
| | | return AjaxResult.buildFailInstance("验证码已失效,请重新发送"); |
| | | } |
| | | |
| | | if (!code.equals(pwdResetDto.getCode())) { |
| | | return AjaxResult.buildFailInstance("验证码错误"); |
| | | } |
| | | |
| | | user = users.get(0); |
| | | user.setSuPassword(pwdResetDto.getNewPwd()); |
| | | String pwd = PasswordUtil.getEncrypUserPwd(user); |
| | | |
| | | int i = sysUsersService.updateUserPassword(user.getSuId(), pwd); |
| | | if (i > 0) { |
| | | redisClient.removeObject(pwdResetDto.getTelphone()); |
| | | return AjaxResult.buildSuccessInstance("修改成功"); |
| | | } |
| | | return AjaxResult.buildFailInstance("修改失败"); |
| | | } |
| | | } |