package com.emptyMe.org.service.imp;
import com.emptyMe.basic.utils.*;
import com.emptyMe.org.domain.User;
import com.emptyMe.org.mapper.LoginInfoMapper;
import com.emptyMe.org.mapper.UserMapper;
import com.emptyMe.org.query.LoginInfoQuery;
import com.emptyMe.org.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class UserServiceImpl implements IUserService {
@Autowired
private UserMapper mapper;
@Autowired
private LoginInfoMapper loginInfoMapper;
@Autowired
private RedisTemplate redisTemplate;
/**
* 获取验证码
*
* @param phone 手机号
* @return 返回是否成功及其他信息
*/
@Override
public AjaxResult getCode(String phone) {
User user = mapper.findByPhone(phone);
if (user != null) {
return AjaxResult.me(false, "该手机号已被注册过");
} else {
// 查询该手机号是否获取过验证码
String code = (String) redisTemplate.opsForValue().get(phone);
if (code == null) {
// 未发送过
code = CodeUtils.getCode();
redisTemplate.opsForValue().set(phone, code);
// 设置过期时间为10分钟
redisTemplate.expireAt(phone, new Date(System.currentTimeMillis() + 10 * 60 * 1000));
// 发送验证码
SMSUtils.sendSMS(phone, code + ",有效期:10分钟");
} else {
// 发送过
// 查看验证码是否过期
if (redisTemplate.getExpire(phone) < 0) {
// 过期了
// 重新获取验证码
code = CodeUtils.getCode();
redisTemplate.opsForValue().set(phone, code);
// 设置过期时间为10分钟
redisTemplate.expireAt(phone, new Date(System.currentTimeMillis() + 10 * 60 * 1000));
// 发送验证码
SMSUtils.sendSMS(phone, code + ",有效期:10分钟");
} else {
// 验证码没过期
SMSUtils.sendSMS(phone, code + ",有效期:10分钟");
}
}
// 验证码是否过期
return AjaxResult.me();
}
}
@Override
@Transactional
public AjaxResult registerByPhone(LoginInfoQuery query) {
if (StringUtils.isEmpty(query.getPhone())
&& StringUtils.isEmpty(query.getCode())
&& StringUtils.isEmpty(query.getPassword())
&& StringUtils.isEmpty(query.getRepassword())) {
return AjaxResult.me(false, "信息填写不完整");
} else {
if (!query.getPassword().equals(query.getRepassword())) {
// 两次密码不一致
return AjaxResult.me(false, "两次密码不一致");
} else {
if (mapper.findByPhone(query.getPhone()) != null) {
return AjaxResult.me(false, "该手机号已被注册");
} else {
// 密码一致
String code = (String) redisTemplate.opsForValue().get(query.getPhone());
// 查看该手机是否存在验证码
if (code == null || code.equals("")) {
return AjaxResult.me(false, "验证码错误");
} else {
// 存在验证码
// 判断验证码是否过期
if (redisTemplate.getExpire(query.getPhone()) > 0) {
// 验证码未过期
// 判断是否一致
if (!code.equals(query.getCode())) {
// 验证码不一致
return AjaxResult.me(false, "验证码错误");
} else {
// return AjaxResult.me();
query.setType(1);
query.setState(1);
query.setDisable(1);
String salt = StrUtils.getComplexRandomString(32);
query.setSalt(salt);
query.setPassword(MD5Utils.encrypByMd5(query.getPassword() + "empty" + salt + "me"));
loginInfoMapper.save(query);
mapper.save(query);
return AjaxResult.me();
}
} else {
return AjaxResult.me(false, "验证码已过期,请重新获取");
}
}
}
}
}
}
@Override
public AjaxResult logout() {
// redisTemplate.opsForValue().set("token",null);
redisTemplate.delete("token");
return AjaxResult.me();
}
@Override
public AjaxResult findByUsername(String username) {
if (username==null){
return AjaxResult.me(false,"用户未登录");
}
return AjaxResult.me(mapper.findByUsername(username).getId());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot+Vue的宠物商城系统源码+数据库(毕业设计).zip

共775个文件
png:142个
jpg:119个
js:101个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉

温馨提示
基于SpringBoot+Vue的宠物商城系统源码+数据库(毕业设计).zip已获导师指导并通过的高分项目。下载即可使用无需修改。项目简介 本项目是一套基于SpringBoot+Vue的宠物商城系统,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的Java学习者。也可作为期末大作业 包含:项目源码、数据库脚本、软件工具、项目说明等,该项目可以直接作为毕设使用。 项目都经过严格调试,确保可以运行! 技术实现 后台框架:SpringBoot 前台框架:VUE 数据库:MySQL 开发环境:JDK、Eclipse、Tomcat 本项目是一套基于SpringBoot+Vue的宠物商城系统,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的Java学习者。也可作为期末大作业 包含:项目源码、数据库脚本、软件工具、项目说明等,该项目可以直接作为毕设使用。 项目都经过严格调试,确保可以运行!基于SpringBoot+Vue的宠物商城系统基于SpringBoot+Vue的宠物商城系统基于SpringBoot+Vue的宠物商城系统基于SpringBoot+Vue的宠物商城系统
资源推荐
资源详情
资源评论




















收起资源包目录





































































































共 775 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8

张小妍的博客
- 粉丝: 1w+
- 资源: 1810
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
前往页