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.