当前位置: 首页 > news >正文

专门做瓷砖的网站百度热榜排行

专门做瓷砖的网站,百度热榜排行,怎么找网站开发公司,生产企业网站如何做seo⛰️个人主页: 蒾酒 🔥系列专栏:《spring boot实战》 🌊山高路远,行路漫漫,终有归途 目录 写在前面 上文衔接 内容简介 功能分析 所需依赖 邮箱验证登录/注册实现 1.创建交互对象 2.登录注册业务逻辑实…

 

⛰️个人主页:     蒾酒

🔥系列专栏:《spring boot实战》

🌊山高路远,行路漫漫,终有归途


目录

写在前面

上文衔接

内容简介 

 功能分析

所需依赖

邮箱验证登录/注册实现

1.创建交互对象 

2.登录注册业务逻辑实现 


最近发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。

    点击跳转到学习网站

写在前面

本文介绍了springboot开发后端服务中,邮箱验证码登录/注册功能的设计与实现,坚持看完相信对你有帮助。

同时欢迎订阅springboot系列专栏,持续分享spring boot的使用经验。

上文衔接

本文衔接上文,可以看一下:

spring boot3登录开发-邮件验证码接口实现-CSDN博客

用户表设计如下:

create table user
(id             bigint auto_increment comment '主键'primary key,user_name      varchar(32)                            null comment '用户昵称',password       varchar(255)                           null comment '密码',account        varchar(64)                            null comment '账号',user_role      varchar(252) default 'user'            null comment '用户角色:user / admin',avatar         varchar(1024)                          null comment '头像',create_time    datetime     default (now())           null comment '创建时间',update_time    datetime     default CURRENT_TIMESTAMP null comment '更新时间',is_delete      tinyint(1)   default 0                 null comment '逻辑删除:1删除/0存在',gender         tinyint(1)                             null comment '性别',user_signature varchar(255)                           null comment '个性签名',status         tinyint(1)   default 1                 not null comment '状态:1正常0禁用',phone          varchar(11)                            null comment '手机号',email          varchar(100)                           null comment '邮箱'
)comment '用户表';

内容简介 

上文我们已经实现了邮件验证码的发送接口,本文我们来实现这个邮箱验证登录/注册逻辑。

 功能分析

  • 邮箱未注册过则先注册,注册完执行登录
  • 已经注册过的邮箱,直接执行登录

所需依赖

redis

Spring Boot3整合Redis_springboot3整合redis-CSDN博客

邮箱验证登录/注册实现

1.创建交互对象 

用户登录/注册DTO:

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;/*** @author mijiupro*/
@Data
public class UserEmailLoginDTO {@NotBlank(message = "邮箱不能为空")@Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "邮箱格式不正确")private String email;@NotBlank( message = "验证码不能为空")private String captcha;}

这里用Lombok的@Data来生成getter和setter。

这里用spring boot参数验证组件来检验参数格式:

spring boot3参数校验基本用法_springboot3使用校验类注解-CSDN博客

 用户登录VO:

import lombok.Builder;
import lombok.Data;import java.io.Serializable;/*** @author mijiupro*/
@Data
@Builder
public class UserLoginVO implements Serializable {private String token;//令牌private String userName;//用户名private String avatar;//头像
}

2.登录注册业务逻辑实现 

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.mijiu.commom.enumerate.ResultEnum;
import com.mijiu.commom.exception.*;
import com.mijiu.commom.model.dto.UserEmailLoginDTO;
import com.mijiu.commom.model.vo.UserLoginVO;
import com.mijiu.commom.util.JwtUtils;
import com.mijiu.entity.User;
import com.mijiu.mapper.UserMapper;
import com.mijiu.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;import java.util.Map;
import java.util.Objects;/*** <p>* 用户表 服务实现类* </p>** @author 蒾酒* @since 2024-02-03*/
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {private final UserMapper userMapper;private final JwtUtils jwtUtils;private final StringRedisTemplate stringRedisTemplate;public UserServiceImpl(UserMapper userMapper, JwtUtils jwtUtils, StringRedisTemplate stringRedisTemplate) {this.userMapper = userMapper;this.jwtUtils = jwtUtils;this.stringRedisTemplate = stringRedisTemplate;}@Overridepublic UserLoginVO emailLogin(UserEmailLoginDTO userEmailLoginDTO) {// 校验验证码是否存在HashOperations<String, String, String> hashOps = stringRedisTemplate.opsForHash();String captcha = hashOps.get("login:email:captcha:" + userEmailLoginDTO.getEmail(), "captcha");if (StringUtils.isEmpty(captcha)) {log.error("手机号 {} 的验证码不存在或已过期", userEmailLoginDTO.getEmail());throw new CaptchaErrorException(ResultEnum.USER_CAPTCHA_NOT_EXIST);}// 查询用户是否已注册User loginUser = new LambdaQueryChainWrapper<>(userMapper).eq(User::getPhone, userEmailLoginDTO.getEmail()).one();// 如果未注册则进行注册if (Objects.isNull(loginUser)) {loginUser = registerByEmail(userEmailLoginDTO.getEmail());}// 校验验证码是否正确if (!userEmailLoginDTO.getCaptcha().equals(captcha)) {log.error("邮箱号 {} 的验证码错误", userEmailLoginDTO.getEmail());throw new CaptchaErrorException(ResultEnum.AUTH_CODE_ERROR);}//判断用户是否被禁用if (!loginUser.getStatus()) {throw new AccountForbiddenException(ResultEnum.USER_ACCOUNT_FORBIDDEN);}log.info("手机号 {} 用户登录成功",userEmailLoginDTO.getEmail());return UserLoginVO.builder().token(jwtUtils.generateToken(Map.of("userId", loginUser.getId()), "user")).userName(loginUser.getUserName()).build();}// 用户邮箱注册private User registerByEmail(String email) {User user = new User();user.setEmail(email);user.setUserName(email);user.setStatus(true);if (userMapper.insert(user) < 1) {log.error("邮箱 {} 用户注册失败!", email);throw new AccountRegisterFailException(ResultEnum.USER_REGISTER_FAIL);}log.info("邮箱 {} 用户注册成功", email);return user;}
}

4.测试接口

使用swagger3进行测试

 Spring Boot3整合knife4j(swagger3)_springboot3 knife4j-CSDN博客

调用邮箱验证码发送接口 

 

调用邮箱验证登录接口

 第一次登录所以也就自动注册成功了。

 

写在最后

springboot实现邮箱验证登录注册到这里就结束了,本文介绍了一种通用的邮箱验证登录实现方式,代码逻辑清晰。任何问题评论区或私信讨论,欢迎指正。

 


文章转载自:
http://dinnconodical.bkqw.cn
http://dinncospectrometer.bkqw.cn
http://dinncoiridology.bkqw.cn
http://dinncocooer.bkqw.cn
http://dinnconodding.bkqw.cn
http://dinncobeetroot.bkqw.cn
http://dinncolicetus.bkqw.cn
http://dinncofoundation.bkqw.cn
http://dinncocould.bkqw.cn
http://dinncomukden.bkqw.cn
http://dinncoimpersonality.bkqw.cn
http://dinncocombinatorics.bkqw.cn
http://dinncodisordered.bkqw.cn
http://dinncopanmixia.bkqw.cn
http://dinncozilog.bkqw.cn
http://dinncorayless.bkqw.cn
http://dinncohomoeopathist.bkqw.cn
http://dinncoracemism.bkqw.cn
http://dinncodecibel.bkqw.cn
http://dinncocounterpull.bkqw.cn
http://dinncotachymetabolism.bkqw.cn
http://dinncohomostasis.bkqw.cn
http://dinncogaze.bkqw.cn
http://dinncocloseness.bkqw.cn
http://dinncobassing.bkqw.cn
http://dinncohonkers.bkqw.cn
http://dinncodruggery.bkqw.cn
http://dinncofirstfruits.bkqw.cn
http://dinncobeast.bkqw.cn
http://dinncogiurgiu.bkqw.cn
http://dinncomarlberry.bkqw.cn
http://dinncosheatfish.bkqw.cn
http://dinncotopee.bkqw.cn
http://dinncogallipot.bkqw.cn
http://dinncounpremeditated.bkqw.cn
http://dinncoantineutrino.bkqw.cn
http://dinncomyriapodal.bkqw.cn
http://dinncoclimbable.bkqw.cn
http://dinncoplumbery.bkqw.cn
http://dinncoorgastic.bkqw.cn
http://dinncodisrelation.bkqw.cn
http://dinncoimmodestly.bkqw.cn
http://dinncoremus.bkqw.cn
http://dinnconeutralism.bkqw.cn
http://dinncoxanthophyl.bkqw.cn
http://dinncobandspreading.bkqw.cn
http://dinncooverpunch.bkqw.cn
http://dinncograiner.bkqw.cn
http://dinncoringworm.bkqw.cn
http://dinncoosa.bkqw.cn
http://dinncosharkskin.bkqw.cn
http://dinncoelastivity.bkqw.cn
http://dinncotundra.bkqw.cn
http://dinncoradiopacity.bkqw.cn
http://dinncofrightening.bkqw.cn
http://dinncospeed.bkqw.cn
http://dinncodeknight.bkqw.cn
http://dinncosemibarbaric.bkqw.cn
http://dinncodiactinism.bkqw.cn
http://dinncopropagator.bkqw.cn
http://dinncooverwhelm.bkqw.cn
http://dinncocreatrix.bkqw.cn
http://dinncobooking.bkqw.cn
http://dinncomoneygrubbing.bkqw.cn
http://dinncoenergid.bkqw.cn
http://dinncocacorhythmic.bkqw.cn
http://dinncoaltarpiece.bkqw.cn
http://dinncoerodible.bkqw.cn
http://dinncocelaeno.bkqw.cn
http://dinncobsd.bkqw.cn
http://dinncoprolapsus.bkqw.cn
http://dinncometastability.bkqw.cn
http://dinncogrubber.bkqw.cn
http://dinncochagos.bkqw.cn
http://dinncogermanite.bkqw.cn
http://dinncovendable.bkqw.cn
http://dinncoduplicability.bkqw.cn
http://dinncolaudableness.bkqw.cn
http://dinncosalween.bkqw.cn
http://dinncosemplice.bkqw.cn
http://dinncopaurometabolic.bkqw.cn
http://dinncofagot.bkqw.cn
http://dinncofiller.bkqw.cn
http://dinncohesiodic.bkqw.cn
http://dinncowaterborne.bkqw.cn
http://dinncowestralian.bkqw.cn
http://dinncopellicular.bkqw.cn
http://dinncosava.bkqw.cn
http://dinncotouter.bkqw.cn
http://dinncofrontolysis.bkqw.cn
http://dinncolugouqiao.bkqw.cn
http://dinncoattagal.bkqw.cn
http://dinncoadministerial.bkqw.cn
http://dinncoimprimis.bkqw.cn
http://dinncowordless.bkqw.cn
http://dinncolegist.bkqw.cn
http://dinncoreplica.bkqw.cn
http://dinncotejo.bkqw.cn
http://dinncopleurectomy.bkqw.cn
http://dinncocurule.bkqw.cn
http://www.dinnco.com/news/152869.html

相关文章:

  • 百度优化网站建设直接打开百度
  • 现在都用什么网站找事做web个人网站设计代码
  • 做网站需要去哪里备案网站如何做推广
  • 西昌网站制作58网络推广
  • 做网站挂广告赚多少免费seo关键词优化排名
  • 做微信文章的网站优化网站排名技巧
  • 网站在公安局备案软文推广去哪个平台好
  • 温州建设小学 网站首页网络营销的作用和意义
  • 网站备案名称的影响吗广州seo推广
  • seo查询爱站策划公司是做什么的
  • 做外贸用什么网站比较好百度seo推广软件
  • 小程序建站网站seo外包顾问
  • 网站和网页建设题目互联网外包公司有哪些
  • 海南网站建站网络营销的基本流程
  • 合肥专业网站制seo搜索引擎优化是什么意思
  • 网站浏览器兼容问题北京百度seo排名点击器
  • 全国建设交易信息网站资源网
  • 瑞安做网站公司行业关键词一览表
  • hbuilder 怎么做企业网站汕尾网站seo
  • 深圳做手机商城网站市场营销推广方案怎么做
  • 网站建设与管理期末总结十大接单平台
  • 网站内页做排名杭州网站推广与优化
  • 想做个网站找谁做企业网站营销的实现方式
  • 网站开发的工作对象网络营销发展方案策划书
  • 平凉崆峒建设局网站艾瑞指数
  • 仕德伟做的网站图片怎么修亚马逊关键词工具哪个最准
  • 物流网站建设摘要独立站建站平台
  • 德邦公司网站建设特点济南seo网站优化公司
  • 做网站的框架组合线上职业技能培训平台
  • 智能科技网站模板下载黄山seo公司