| | |
| | | package com.xiaopeng.account.controller; |
| | | |
| | | import com.xiaopeng.account.constant.I18nKeyConstant; |
| | | import com.xiaopeng.account.service.ISysUserService; |
| | | import com.xiaopeng.account.service.IXpOperationsUserService; |
| | | import com.xiaopeng.account.service.impl.SysLoginService; |
| | |
| | | import com.xiaopeng.api.model.account.XpOperationsUser; |
| | | import com.xiaopeng.api.vo.account.LoginOperationUser; |
| | | import com.xiaopeng.api.vo.account.LoginUser; |
| | | import com.xiaopeng.api.vo.operation.SmsVo; |
| | | import com.xiaopeng.common.core.constant.VerificationCodeConstants; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.JwtUtils; |
| | | import com.xiaopeng.common.core.utils.StringUtils; |
| | | import com.xiaopeng.common.redis.service.RedisService; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | |
| | | @Value("${sms.appid}") |
| | | private String sms_appid; |
| | | // @Autowired |
| | | // private EncryptionDecryptionUtil encryptionDecryptionUtil; |
| | | |
| | | @ApiOperation(value = "用户登录", tags = "管理后台-用户登录") |
| | | @PostMapping("/base/v1/login") |
| | |
| | | // 修改用户最后登录时间 |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /* @ApiOperation(value = "解密测试", tags = "管理后台-用户登录") |
| | | @PostMapping("/base/v1/decrypted") |
| | | public R<?> decrypted(@RequestBody LoginBody form, HttpServletRequest request) { |
| | | String decrypt = encryptionDecryptionUtil.decrypt(form.getUsername(), request); |
| | | return R.ok(decrypt); |
| | | } |
| | | @ApiOperation(value = "加密测试", tags = "管理后台-用户登录") |
| | | @GetMapping("/base/v1/encrypted") |
| | | public R<String> encrypted(HttpServletRequest request, HttpServletResponse response) { |
| | | String content = "Hello, World!"; |
| | | String sessionId = request.getSession(true).getId(); |
| | | if(StringUtils.isEmpty(sessionId)){ |
| | | throw new ServiceException("请求失败,请稍后重试", I18nKeyConstant.REQUEST_FAILED); |
| | | } |
| | | Object cacheObject = redisService.getCacheObject("session:id:" + sessionId); |
| | | if (null != cacheObject) { |
| | | JSONObject jsonObject = JSONObject.parseObject(cacheObject.toString()); |
| | | return R.ok(jsonObject.getString("publicKey")); |
| | | } |
| | | KeyPair keyPair = RSAUtil.generateKeyPair(); |
| | | String publicKey = RSAUtil.getPublicKey(keyPair); |
| | | String privateKey = RSAUtil.getPrivateKey(keyPair); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("publicKey", publicKey); |
| | | jsonObject.put("privateKey", privateKey); |
| | | redisService.setCacheObject("session:id:" + sessionId, jsonObject.toJSONString(), 1L, TimeUnit.MINUTES); |
| | | JSONObject encrypt = EncryptionDecryptionUtil.encrypt(content, privateKey); |
| | | response.setHeader("xps", encrypt.getString("aes_key")); |
| | | return R.ok(encrypt.getString("content")); |
| | | }*/ |
| | | @ApiOperation(value = "账号密码登录", tags = {"运维APP登录"}) |
| | | @PostMapping("base/v1/operationPasswordLogin") |
| | | public R<?> operationPasswordLogin(@RequestBody AppLoginPasswordDTO appLoginPasswordDTO, HttpServletRequest request) { |
| | |
| | | codeType = VerificationCodeConstants.UPDATE_PASSWORD_CODE; |
| | | break; |
| | | } |
| | | |
| | | SmsVo vo = new SmsVo(); |
| | | vo.setAppId(sms_appid); |
| | | vo.setPushType(1); |
| | | vo.setReceivers(appLoginPasswordDTO.getPhoneNumber()); |
| | | vo.setTemplateCode("RobotaxiVerifyCodeSmsTpl"); |
| | | vo.setAppPushConfigCode("RobotaxiVerifyCodeSms"); |
| | | vo.setParams(new HashMap<>()); |
| | | vo.getParams().put("code", code); |
| | | SmsDto smsDto = smsClient.pushSms(vo); |
| | | if(null == smsDto || smsDto.getCode() != 200){ |
| | | throw new ServiceException("短信发送失败", I18nKeyConstant.SMS_PUSH_FAILED); |
| | | } |
| | | //TODO 短信服务开通后再开启 |
| | | // SmsVo vo = new SmsVo(); |
| | | // vo.setAppId(sms_appid); |
| | | // vo.setPushType(1); |
| | | // vo.setReceivers(appLoginPasswordDTO.getPhoneNumber()); |
| | | // vo.setTemplateCode("RobotaxiVerifyCodeSmsTpl"); |
| | | // vo.setAppPushConfigCode("RobotaxiVerifyCodeSms"); |
| | | // vo.setParams(new HashMap<>()); |
| | | // vo.getParams().put("code", code); |
| | | // SmsDto smsDto = smsClient.pushSms(vo); |
| | | // if(null == smsDto || smsDto.getCode() != 200){ |
| | | // throw new ServiceException("短信发送失败", I18nKeyConstant.SMS_PUSH_FAILED); |
| | | // } |
| | | redisService.setCacheObject(codeType+appLoginPasswordDTO.getPhoneNumber(), code, 60L, TimeUnit.SECONDS); |
| | | return R.ok(); |
| | | } |