The ability of the MVC application to request a password (ii)

Source: Internet
Author: User

After completing the http://www.cnblogs.com/insus/p/3471534.html of the MVC application request password (i), if you do, all requests are only listed in the Mailinglist table and not sent out.

Insus.net continues now, allowing this function to be as perfect as possible.


In the previous article, there was a stored procedure:



In this stored procedure #38 with the #39 line code, is a hyperlink that is really present in the MVC application. In other words, when you send a message to a member, you send the view of the link to the member's mailbox. Therefore, we have to create this view.

To create this view, you have to create a model to make it easier to display dynamic data in this view.


Go to controller MemberController.cs add a view ActionResult:


To create a view:


This view is the message content. You can customize this content for your reference only.

Now we have to deal with the data of the Mailinglist table, the data of this table is a record that is generated when the member requests the password. Each record, that is, to send an email to the member. This can write a stored procedure and distribute them on the same rows:



First, create a temporary table, insert all the records into the temporary table, and then remove the same record that you just inserted into the temporary table. Finally, the temporary table left JOIN message reference table is returned to the MVC application. In the entities directory of the application, create an entity:



The next implementation, or the focus of this article, is that the MVC application automatically executes the ability to send mail:
Go to Insus.net's blog, open http://www.cnblogs.com/insus/archive/2010/03/16/1687688.html download insusmailutility and refer to the MVC application:

In the MVC application, in the App_start directory, write AutomationTask.cs:

At this point, you also need to modify the Global.asax file to add the certain code.

As long as the application is running, AutomationTask.cs will also execute automatically. Now can demonstrate, first to modify a test member's mailbox, changed to live mailbox:



Then, just like the last demo, use this member account to request a password and then open the mailbox and you'll see the message:

Members simply click on the hyperlink, which will guide the reset password view. Now we need to write the Reset password function, first create a stored procedure:


First determine if the token exists or whether it expires, and if not, find the account and email with token. Then update the password, and finally delete the Changerequestpassword record. Expired are deleted, the change password is also deleted successfully.

Under the Entities directory, create a SecurityEntity.cs:


Modify the controller MemberController.cs add a ActionResult and a jsonresult:

To create a ResetPassword view:


To demonstrate, change your password:



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.