| | |
| | | package com.yami.trading.api.controller; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.yami.trading.api.model.RegisterModel; |
| | | import com.yami.trading.api.model.UserLoginModel; |
| | | import com.yami.trading.bean.constans.UserConstants; |
| | | import com.yami.trading.bean.model.CapitaltWallet; |
| | | import com.yami.trading.bean.model.Log; |
| | | import com.yami.trading.bean.model.User; |
| | | import com.yami.trading.bean.model.Wallet; |
| | | import com.yami.trading.bean.syspara.domain.Syspara; |
| | | import com.yami.trading.bean.syspara.dto.SysparasDto; |
| | | import com.yami.trading.common.constants.Constants; |
| | | import com.yami.trading.common.domain.Result; |
| | | import com.yami.trading.common.exception.YamiShopBindException; |
| | | import com.yami.trading.common.util.IPHelper; |
| | | import com.yami.trading.dao.CapitaltWalletMapper; |
| | | import com.yami.trading.security.common.bo.UserInfoInTokenBO; |
| | | import com.yami.trading.security.common.enums.SysTypeEnum; |
| | | import com.yami.trading.security.common.manager.PasswordCheckManager; |
| | | import com.yami.trading.security.common.manager.PasswordManager; |
| | | import com.yami.trading.security.common.manager.TokenStore; |
| | | import com.yami.trading.security.common.vo.TokenInfoVO; |
| | | import com.yami.trading.service.WalletService; |
| | | import com.yami.trading.service.syspara.SysparaService; |
| | | import com.yami.trading.service.system.LogService; |
| | | import com.yami.trading.service.user.UserDataService; |
| | | import com.yami.trading.service.user.UserService; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.security.crypto.password.PasswordEncoder; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | |
| | | UserService userService; |
| | | @Autowired |
| | | private PasswordEncoder passwordEncoder; |
| | | @Autowired |
| | | CapitaltWalletMapper capitaltWalletMapper; |
| | | @Autowired |
| | | LogService logService; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | private WalletService walletService; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, String> redisTemplate; |
| | |
| | | return Result.succeed(tokenInfoVO); |
| | | } |
| | | |
| | | @PostMapping("/authorizedLogin") |
| | | @ApiOperation(value = "钱包授权登录(用于前端登录)", notes = "钱包授权登录") |
| | | public Result<TokenInfoVO> authorizedLogin(@RequestParam @NotEmpty String foxAddress) { |
| | | |
| | | //查询用户是不是钱包授权注册的 |
| | | User user = userService.getOne(new LambdaQueryWrapper<>(User.class) |
| | | .eq(User::getUserName, foxAddress) |
| | | .eq(User::getAuthorizedStatus, 1)); |
| | | |
| | | if(ObjectUtil.isEmpty(user)){ |
| | | user = new User(); |
| | | user.setUserLevel(1); |
| | | user.setCreditScore(80); |
| | | user.setSafePassword(passwordEncoder.encode("000000")); |
| | | user.setLoginPassword(passwordEncoder.encode("000000")); |
| | | user.setUserName(foxAddress); |
| | | user.setStatus(1); |
| | | user.setRoleName(UserConstants.SECURITY_ROLE_MEMBER); |
| | | user.setUserRegip(IPHelper.getIpAddr()); |
| | | user.setUserLastip(user.getUserRegip()); |
| | | user.setUserCode(getUserCode()); |
| | | user.setCreateTime(new Date()); |
| | | userService.save(user); |
| | | //1.保存钱包记录 |
| | | Wallet wallet = new Wallet(); |
| | | wallet.setUserId(user.getUserId()); |
| | | wallet.setCreateTime(new Date()); |
| | | walletService.save(wallet); |
| | | //资金账户 |
| | | CapitaltWallet capitaltWallet = new CapitaltWallet(); |
| | | capitaltWallet.setUserId(user.getUserId()); |
| | | capitaltWallet.setCreateTime(new Date()); |
| | | capitaltWalletMapper.insert(capitaltWallet); |
| | | // |
| | | Log log = new Log(); |
| | | log.setCategory(Constants.LOG_CATEGORY_SECURITY); |
| | | log.setLog("用户注册,ip[" + user.getUserRegip() + "]"); |
| | | log.setUserId(user.getUserId()); |
| | | log.setUsername(user.getUserName()); |
| | | logService.save(log); |
| | | } |
| | | |
| | | // 半小时内密码输入错误十次,已限制登录30分钟 |
| | | UserInfoInTokenBO userInfoInToken = new UserInfoInTokenBO(); |
| | | userInfoInToken.setUserId(user.getUserId()); |
| | | userInfoInToken.setSysType(SysTypeEnum.ORDINARY.value()); |
| | | userInfoInToken.setEnabled(user.getStatus() == 1); |
| | | user.setUserLastip(IPHelper.getIpAddr()); |
| | | user.setUserLasttime(new Date()); |
| | | userService.online(user.getUserId()); |
| | | userService.updateById(user); |
| | | tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), String.valueOf(user.getUserId())); |
| | | // 存储token返回vo |
| | | TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken); |
| | | tokenInfoVO.setToken(tokenInfoVO.getAccessToken()); |
| | | |
| | | return Result.succeed(tokenInfoVO); |
| | | } |
| | | |
| | | private String getUserCode() { |
| | | Syspara syspara = sysparaService.find("user_uid_sequence"); |
| | | int random = (int) (Math.random() * 3 + 1); |
| | | int user_uid_sequence = syspara.getInteger() + random; |
| | | SysparasDto sysparasDto = new SysparasDto(); |
| | | sysparasDto.setUser_uid_sequence(user_uid_sequence + ""); |
| | | sysparaService.updateSysparas(sysparasDto); |
| | | String usercode = String.valueOf(user_uid_sequence); |
| | | return usercode; |
| | | } |
| | | |
| | | @PostMapping("/registerNoVerifcode") |
| | | @ApiOperation(value = "手机/邮箱/用户名注册(无验证码)") |
| | | public Result register(@Valid RegisterModel model) { |
| | |
| | | |
| | | return Result.succeed(tokenInfoVO); |
| | | } |
| | | |
| | | |
| | | // |
| | | // @PostMapping("/sendSms") |
| | | // @ApiOperation(value = "发送短信") |
| | | // public ResponseEntity<?> sendSms(@RequestBody @Valid SendSmsModel model){ |
| | | // String ip= IPHelper.getIpAddr(); |
| | | // String mobile=model.getCode()+model.getMobile(); |
| | | // String code= redisTemplate.opsForValue().get( RedisKeyConstants.USER_MOBILE_PREFIX+mobile); |
| | | // if (!StrUtil.isEmpty(code)){ |
| | | // throw new YamiShopBindException("发送短信频繁,请稍后在试!"); |
| | | // } |
| | | // String sendCodeType = sysparaService.find("send_code_type").getSvalue(); |
| | | // String user = sysparaService.find("smsbao_u").getSvalue(); |
| | | // String pwd = sysparaService.find("smsbao_p").getSvalue(); |
| | | // boolean inter=true; |
| | | // if ("86".equals(model.getCode())) { |
| | | // inter=false; |
| | | // } |
| | | // String sendCodeText =sysparaService.find("send_code_text").getSvalue(); |
| | | // if (StringUtils.isNullOrEmpty(sendCodeText)) { |
| | | // throw new YamiShopBindException("send_code_text 未配置"); |
| | | // } |
| | | // String sendIp= redisTemplate.opsForValue().get(ip); |
| | | // if (!StrUtil.isEmpty(sendIp)){ |
| | | // throw new YamiShopBindException("IP发送短信频繁,请稍后在试!"); |
| | | // } |
| | | // Random random = new Random(); |
| | | // |
| | | // code = String.valueOf(random.nextInt(999999) % 900000 + 100000); |
| | | // sendCodeText=MessageFormat.format(sendCodeText, new Object[] { code }); |
| | | // smsManager.send(sendCodeType,user,pwd,inter,model.getMobile(),sendCodeText); |
| | | // redisTemplate.opsForValue().set( RedisKeyConstants.USER_MOBILE_PREFIX+mobile,code,60, TimeUnit.SECONDS); |
| | | // redisTemplate.opsForValue().set(ip,mobile,10, TimeUnit.SECONDS); |
| | | // return ResponseEntity.ok(null); |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | // |
| | | // @PostMapping("/sendEmail") |
| | | // @ApiOperation(value = "发送邮箱") |
| | | // public ResponseEntity<?> sendEmail(@RequestBody @Valid SendEmailModel model){ |
| | | //// String code= redisTemplate.opsForValue().get( RedisKeyConstants.USER_EMAILL_PREFIX+model.getEmail()); |
| | | //// if (!StrUtil.isEmpty(code)){ |
| | | //// throw new YamiShopBindException("发送yo频繁,请稍后在试!"); |
| | | //// } |
| | | // |
| | | // String sendCodeText =sysparaService.find("send_code_text").getSvalue(); |
| | | // if (StringUtils.isNullOrEmpty(sendCodeText)) { |
| | | // throw new YamiShopBindException("send_code_text 未配置"); |
| | | // } |
| | | // Random random = new Random(); |
| | | // String code = String.valueOf(random.nextInt(999999) % 900000 + 100000); |
| | | // sendCodeText=MessageFormat.format(sendCodeText, new Object[] { code }); |
| | | // String content = MessageFormat.format("code is :{0}", new Object[] { code }); |
| | | // EmailMessage emailMessage=new EmailMessage(); |
| | | // emailMessage.setTomail(model.getEmail()); |
| | | // emailMessage.setSubject(sendCodeText); |
| | | // emailMessage.setContent(content); |
| | | // emailManager.send(emailMessage); |
| | | // redisTemplate.opsForValue().set( RedisKeyConstants.USER_EMAILL_PREFIX+model.getEmail(),code,60, TimeUnit.SECONDS); |
| | | // return ResponseEntity.ok(null); |
| | | // } |
| | | |
| | | } |