注册功能_邮件激活_点击激活分析与注册功能_邮件激活_代码实现_Servlet

注册功能_邮件激活_点击激活分析

      经过分析,发现,用户激活其实就是修改用户表中的status为‘Y’

      

 

 

 

 

 

 

 

 

 

  //2.保存用户信息
        //2.1设置激活码, 唯一字符串
        user.setCode(UuidUtil.getUuid());
        //2.2设置激活状态
        user.setStatus("N");
        userDao.seve(user);

        //3.激活邮件发送,邮件正文?
        String content="<a href='http://localhost/travel/activeUserServlet?code="+user.getCode()+"'>点击激活【黑马旅游网】</a>";

        MailUtils.sendMail(user.getEmail(),content,"激活邮件");
        return true;
    }
}

 

 

注册功能_邮件激活_代码实现_Servlet

  激活代码实现:

  ActiveUserServlet

    

package cn.itcast.travel.web.servlet;

import cn.itcast.travel.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/activeUserServlet")
public class ActiveUserServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取激活码
        String code = request.getParameter("code");
        if (code !=null){
            //2.调用service完成激活
            UserServiceImpl service = new UserServiceImpl();
            boolean flag =  service.active(code);
            //3.判断标记
            String msg = null;
            if (flag){
                //激活成功
                msg = "激活成功,请<a href='login.html'>登录</a>";
            }else {
                //激活失败
                msg ="激活失败,请联系管理员!";
            }
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write(msg);

        }

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

 

    boolean active(String code);
}

 

    /**
     * 激活用户
     * @param code
     * @return
     */
    @Override
    public boolean active(String code) {
        return false;
    }

 

 

posted @ 2023-02-28 16:38  zj勇敢飞,xx永相随  阅读(20)  评论(0编辑  收藏  举报