Java Web activation mailbox and retrieve password _java

Source: Internet
Author: User
Tags java web stringbuffer

Almost every web site or forum, such as users need to register by sending mail to the mailbox to activate the user, how to activate the mailbox Na?
Design activation steps:
1, send the Activation Action link address to the user's mailbox.
2, the user to the mailbox check mail.
3, the user clicks the link, jumps to the Success page (modifies activates the state), activates successfully.

Realize:

/** * Send mail * * @param request * @return/@RequestMapping (value = "/sendemail.jhtml") @ResponseBody 
  Public String SendEmail (HttpServletRequest request) {Dynamicparams params = new Dynamicparams (request); 
  StringBuilder builder = new StringBuilder (); 
  StringBuffer url = new StringBuffer (); 
  String type = params.getstring ("type"); 
  Long uid = params.getlong ("id"); 
  User user = Usermanager.find (UID); 
   
   String subject = ""; 
   Determines if the IF ("1". Equals (String.valueof (User.getemailstatus ())) {return errmsg ()) is activated; 
   String ContextPath = Request.getcontextpath (); 
   String rurl = string.valueof (Request.getrequesturl ()); 
   Url.append (rurl.substring (0, Rurl.indexof (contextpath))); 
   Url.append (ContextPath + "/account"); Mailbox Activation//Url.append ("/activateemail.jhtml?email=" + user.getemail () +//"&id=" + uid + "&mode=activate" 
   ); 
   Url.append ("/activateemail.jhtml?id=" + uid + "&mode=activate"); 
   BodyBuilder.append (" 

mailsender.mailsimple (User.getemail (), Subject, builder.tostring (), false, null); That is to send the Mail tool class, if there is no clear reference to my previous article (Spring Mail to send mail)

Forgot password (reset password)

Background: Also is a function that each big website will have, by sending the authentication code to the user registers the mailbox resets the password

Design: 1 Enter username/mobile number/email, verify code.
2 The user chooses the handset authentication or the mailbox authentication, sends the authentication code to the handset or the mailbox. If the user's mailbox is not active, mailbox authentication is not allowed.
3 The user entered the verification code successfully, enter the password to reset the page.
4) Reset Password

Process:

Realize:

/** * Send mail * * @param request * @return/@RequestMapping (value = "/sendemail.jhtml") @ResponseBody public 
 String SendEmail (HttpServletRequest request) {Dynamicparams params = new Dynamicparams (request); 
 StringBuilder builder = new StringBuilder (); 
 StringBuffer url = new StringBuffer (); 
 String type = params.getstring ("type"); 
 Long uid = params.getlong ("id"); 
 User user = Usermanager.find (UID); 
  
  String subject = ""; 
  Type = Forget password reset String verifycode = Verifycodeutils.generateverifycode (4); 
  Request.getsession (). setattribute ("Resetcertcode", Verifycode); 
  Url.append ("<font color= ' Red ' >" + verifycode + "</font>"); Text Builder.append (" 

To this point, the activation of the mailbox and forgotten password function has been preliminarily completed! Hope that everyone's learning help, we can start to activate the mailbox and retrieve the password.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.