<–start–> 
需求描述:当客户打开收到邮箱激活码的邮件,点击激活链接,正确填写激活码后就会完成邮箱激活的步骤。 
在后台编程代码编写中,有以下几个要点: 
① 接收客户的手机号码和邮箱激活码。 
② 先判断激活码是否有效。如果激活码无效,提示用户。 
③ 如果激活码有效,接下来就要判断用户是否在重复绑定邮箱,customer表中 
的type字段就是用来甄别邮箱是否已经激活,默认该字段的值是空值,如果type字段的值为1表示用户已经绑定邮箱。 
④ 如果用户没有绑定过邮箱,就完成邮箱的绑定。 
编写CustomerAction类,提供activeMail方法: 
① 使用属性驱动接收激活码。

// 属性驱动
private String activecode;
public void setActivecode(String activecode) {
this.activecode = activecode;
}

② 判断激活码是否有效。因为先前已经将邮箱激活码存入了redis中,所以我们 
可以直接从redis中获取激活码,判断用户提交的激活码是否为空或者与redis中存储的不同,这两种情况均表示激活码无效。 
③ 解决响应到客户端的中文乱码的问题。

ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");

④ 激活码有效的话,为了避免用户重复点击激活地址导致重复绑定情形发生, 
就需要通过webservice查询crm系统中的客户信息,判断是否已经绑定。 
⑤ 对于已经激活邮箱的用户,在redis中删除邮箱激活码。

// 删除redis的激活码
redisTemplate.delete(model.getTelephone());

完整的CustomerAction代码:

@Action("customer_activeMail")
public String activeMail() throws IOException {
ServletActionContext.getResponse().setContentType(
"text/html;charset=utf-8");
// 判断激活码是否有效
String activecodeRedis = redisTemplate.opsForValue().get(
model.getTelephone());
if (activecodeRedis == null || !activecodeRedis.equals(activecodeRedis)) {
// 激活码无效
ServletActionContext.getResponse().getWriter()
.println("激活码无效,请登录系统,重新绑定邮箱!");
} else {
// 激活码有效
// 防止重复绑定
// 调用CRM webService 查询客户信息,判断是否已经绑定
Customer customer = WebClient
.create("http://localhost:9002/crm_management/services"
+ "/customerService/customer/telephone/"
+ model.getTelephone())
.accept(MediaType.APPLICATION_JSON).get(Customer.class);
if (customer.getType() == null || customer.getType() != 1) {
// 没有绑定,进行绑定
WebClient.create(
"http://localhost:9002/crm_management/services"
+ "/customerService/customer/updatetype/"
+ model.getTelephone()).get();
ServletActionContext.getResponse().getWriter()
.println("邮箱绑定成功!");
} else {
// 已经绑定过
ServletActionContext.getResponse().getWriter()
.println("邮箱已经绑定过,无需重复绑定!");
} // 删除redis的激活码
redisTemplate.delete(model.getTelephone());
}
return NONE;
}

在crm_management系统中,编写webservice服务接口findByTelephone,通过手机号码来查询客户信息。

@Path("/customer/telephone/{telephone}")
@GET
@Consumes({ "application/xml", "application/json" })
public Customer findByTelephone(@PathParam("telephone") String telephone);

编写updateType服务接口,当激活码有效时,就修改customer表中的type字段的值为1。

@Path("/customer/updatetype/{telephone}")
@GET
public void updateType(@PathParam("telephone") String telephone);

在实现类CustomerServiceImpl中实现findByTelephone和updateType这两个方法。

@Override
public Customer findByTelephone(String telephone) {
return customerRepository.findByTelephone(telephone);
} @Override
public void updateType(String telephone) {
customerRepository.updateType(telephone);
}

在CustomerRepository的dao中编写方法,运用spring data jpa完成持久层的操作。

public Customer findByTelephone(String telephone);

@Query("update Customer set type=1 where telephone= ?")
@Modifying
public void updateType(String telephone);

完整的CustomerService服务接口代码:

public interface CustomerService {

@Path("/customer/telephone/{telephone}")
@GET
@Consumes({ "application/xml", "application/json" })
public Customer findByTelephone(@PathParam("telephone") String telephone); @Path("/customer/updatetype/{telephone}")
@GET
public void updateType(@PathParam("telephone") String telephone); }

完整的CustomerServiceImpl实现类代码:

@Service
@Transactional
public class CustomerServiceImpl implements CustomerService { // 注入DAO
@Autowired
private CustomerRepository customerRepository; @Override
public Customer findByTelephone(String telephone) {
return customerRepository.findByTelephone(telephone);
} @Override
public void updateType(String telephone) {
customerRepository.updateType(telephone);
} }

完整的CustomerRepository持久层代码:

public interface CustomerRepository extends JpaRepository<Customer, Integer> {

public Customer findByTelephone(String telephone);

@Query("update Customer set type=1 where telephone= ?")
@Modifying
public void updateType(String telephone); }

<–end–>

Java案例-用户注册邮箱绑定激活功能实现的更多相关文章

  1. JAVA 实现 QQ 邮箱发送验证码功能(不局限于框架)

    JAVA 实现 QQ 邮箱发送验证码功能(不局限于框架) 本来想实现 QQ 登录,有域名一直没用过,还得备案,好麻烦,只能过几天再更新啦. 先把实现的发送邮箱验证码更能更新了. 老规矩,更多内容在注释 ...

  2. PHP用户注册邮箱验证激活帐号

    我们在很多网站注册会员时,注册完成后,系统会自动向用户的邮箱发送一封邮件,这封邮件的内容就是一个URL链接,用户需要点击打开这个链接才能激活之前在该网站注册的帐号.激活成功后才能正常使用会员功能. 本 ...

  3. ThinkPHP 3.2 用户注册邮箱验证激活帐号

    本文将结合实例,讲解如何使用PHP+Mysql完成注册帐号.发送激活邮件.验证激活帐号.处理URL链接过期的功能. 业务流程 1.用户提交注册信息. 2.写入数据库,此时帐号状态未激活. 3.将用户名 ...

  4. PHP用户注册邮箱并验证激活帐号

    我们在很多网站注册会员时,注册完成后,系统会自动向用户的邮箱发送一封邮件,这封邮件的内容就是一个URL链接,用户需要点击打开这个链接才能激活之前在该网站注册的帐号.激活成功后才能正常使用会员功能. 查 ...

  5. java实现邮箱验证的功能

    在日常生活中,我们在一个网站中注册一个账户时,往往在提交个人信息后,网站还要我们通过手机或邮件来验证,邮件的话大概会是下面这个样子的: 用户通过点击链接从而完成注册,然后才能登录. 也许你会想,为什么 ...

  6. .NET下用C#实现邮箱激活功能

    最近要用到安全邮箱激活的功能,故写篇博客记录下. 思路:在表中增加一个字段State来记录邮箱是否激活(0激活,1未激活.) 1.发送邮件.     1-1,给邮箱发送邮件.内容:激活地址+GUID. ...

  7. php实现邮箱激活功能

    php实现邮箱激活功能 一.样例 二.文件结构 其中swiftmailer-master是第三方插件,用来发验证邮件 三.核心代码 doAction.php 响应页面 <?php header( ...

  8. 075 01 Android 零基础入门 01 Java基础语法 09 综合案例-数组移位 07 综合案例-数组移位-主方法功能4的实现

    075 01 Android 零基础入门 01 Java基础语法 09 综合案例-数组移位 07 综合案例-数组移位-主方法功能4的实现 本文知识点:综合案例-数组移位-主方法功能4的实现 说明:因为 ...

  9. 074 01 Android 零基础入门 01 Java基础语法 09 综合案例-数组移位 06 综合案例-数组移位-主方法功能3的实现

    074 01 Android 零基础入门 01 Java基础语法 09 综合案例-数组移位 06 综合案例-数组移位-主方法功能3的实现 本文知识点:综合案例-数组移位-主方法功能3的实现 说明:因为 ...

随机推荐

  1. vue-router 管理视图详解

    什么是路由 在web开发中,路由是指根据url分配到对应的处理程序,当访问不同的url就会切换到对应的处理程序 在vue中一个url对应的就是一个组件,当访问不同的url,对应的组件就会呈现到页面中 ...

  2. 面试总结——JVM篇

    前言:该篇主要对Java虚拟机相关的题目进行介绍. JVM篇 基本上在面试的时候,都会或多或少的涉及JVM,主要看面试官的侧重点,笔者在面试过程中,是通过volatile问题,引导了JVM相关问题上的 ...

  3. [2] LabelImg图片标注 与 YOLOv3 网络训练 (待补充)

    LabelImg是一个图形图像注释工具. 它是用Python编写的,并使用Qt作为其图形界面. 注释以PASCAL VOC格式保存为XML文件,这是ImageNet使用的格式.Besdies,它也支持 ...

  4. 转://Linux Multipath多路径配置与使用案例

    在Linux平台一部分存储产品使用操作系统自带的多路径软件,包括最常见的HP和IBM的部分存储产品,在Linux自带的多路径软件叫做multipath,这篇文章以HP EVA系列存储在Linux平台的 ...

  5. ansible批量免秘登录

    ansible批量免秘登录   主控机 10.22.0.185 centos7 被控机 10.22.0.186 centos7 一.主控机安装ansible yum install epel-rele ...

  6. pyspider环境部署2--pyspider安装

    接上篇文章,在python3.6.4安装完成的基础上,安装相关依赖模块及pyspider. 依赖安装 1.setuptools和pip setuptools和pip是python的包管理工具,pyth ...

  7. 使用webstrom开发react-native时react-native代码会出现红色下划线的解决方法

    问题:使用webstrom开发react-native时react-native代码会出现红色下划线的解决方法 解决方法:webstrom ->preferences->Laugrange ...

  8. Feature Extractor[VGG]

    0. 背景 Karen Simonyan等人在2014年参加Imagenet挑战赛的时候提出的深度卷积神经网络.作者通过对2013年的ILSVRC中最好的深度神经网络模型(他们最初的对应模型都是ale ...

  9. python中join()函数的使用方法

    函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下:    join():    连接字符串数组.将字符串.元组.列表中的元素以指定的字 ...

  10. 图片自适应完美兼容IE8

    <!DOCTYPE html><html lang="en"><head> <meta charset="gb2312" ...