Next Create CommonCode Folder in PizzaRestaurantDrink and then create Email Class inside in CommonCode Folder, add below code(use for sending email) in Email Class.
> Send Email Html Page Code : (Create Template Folder in PizzaRestaurantDrink Layer, create html page ( ForgotPasswordConfirmation.html) and add this below code) :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Account</title>
<style type="text/css">
img {
max-width: 100%;
}
body {
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: none;
width: 100% !important;
height: 100%;
line-height: 1.6em;
}
body {
background-color: #f6f6f6;
}
@media only screen and (max-width: 640px) {
body {
padding: 0 !important;
}
h1 {
font-weight: 800 !important;
margin: 20px 0 5px !important;
}
h2 {
font-weight: 800 !important;
margin: 20px 0 5px !important;
}
h3 {
font-weight: 800 !important;
margin: 20px 0 5px !important;
}
h4 {
font-weight: 800 !important;
margin: 20px 0 5px !important;
}
h1 {
font-size: 22px !important;
}
h2 {
font-size: 18px !important;
}
h3 {
font-size: 16px !important;
}
.container {
padding: 0 !important;
width: 100% !important;
}
.content {
padding: 0 !important;
}
.content-wrap {
padding: 10px !important;
}
.invoice {
width: 100% !important;
}
}
</style>
</head>
<body itemscope itemtype="http://schema.org/EmailMessage" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em; background-color: #f6f6f6; margin: 0;" bgcolor="#f6f6f6">
<table class="body-wrap" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; background-color: #f6f6f6; margin: 0;" bgcolor="#f6f6f6">
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td>
<td class="container" width="600" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; display: block !important; max-width: 600px !important; clear: both !important; margin: 0 auto;" valign="top">
<div class="content" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; max-width: 600px; display: block; margin: 0 auto; padding: 20px;">
<table class="main" width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9;" bgcolor="#fff">
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="alert alert-warning" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; color: #fff; font-weight: 500; text-align: center; border-radius: 3px 3px 0 0; background-color: #3c8dbc; margin: 0; padding: 20px;" align="center" bgcolor="#FF9F00" valign="top">
Reset Password
</td>
</tr>
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-wrap" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 20px;" valign="top">
<table width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
Hello, <strong style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">{UserName}</strong>
</td>
</tr>
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
Please click bellow button for create new password.
</td>
</tr>
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="">
<a href="{ConfirmationLink}" class="btn btn-primary" style="background-color: #3c8dbc; border: none;color: white; padding: 10px 41px;text-align: center;text-decoration: none;display: inline-block; font-size: 16px;margin: 4px 2px;cursor: pointer;">Reset Password Link </a>
</td>
</tr>
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
<br /><b>Thanks & Regards,</b><br />
Code With Ilyasoft<br />
</td>
</tr>
</table>
</td>
</tr>
</table><div class="footer" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;">
<table width="100%" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="aligncenter content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; vertical-align: top; color: #999; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top"></td>
</tr>
</table>
</div>
</div>
</td>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td>
</tr>
</table>
</body>
</html>
Next add ResetPassword method in user Controller, show in below code:
> Reset Password Action Code :
public ActionResult ResetPassword(string recoverycode)
{
var forgotpassword = new ForgotPasswordMV();
var userrecovery = Db.UserPasswordRecoveryTables.Where(p => p.RecoveryCode == recoverycode && p.RecoveryCodeExpiryDateTime > DateTime.Now && p.RecoveryStatus == true).FirstOrDefault();
if (userrecovery == null)
{
return RedirectToAction("Login");
}
var user = Db.UserTables.Find(userrecovery.UserID);
forgotpassword.UserID = userrecovery.UserID;
forgotpassword.UserName = user.UserName;
forgotpassword.EmailAddress = user.EmailAddress;
return View(forgotpassword);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ResetPassword(ForgotPasswordMV forgotPasswordMV)
{
using (var transaction = Db.Database.BeginTransaction())
{
try
{
if (ModelState.IsValid)
{
var user = Db.UserTables.Find(forgotPasswordMV.UserID);
if (user != null)
{
if (forgotPasswordMV.NewPassword != forgotPasswordMV.ConfirmPassword)
{
ModelState.AddModelError("ConfirmPassword", "Not Match!");
return View(forgotPasswordMV);
}
var userrecovery = Db.UserPasswordRecoveryTables.Where(u => u.UserID == forgotPasswordMV.UserID && u.RecoveryStatus == true);
foreach (var item in userrecovery)
{
item.RecoveryStatus = false;
item.OldPassword = user.Password;
Db.Entry(item).State = System.Data.Entity.EntityState.Modified;
Db.SaveChanges();
}
user.Password = forgotPasswordMV.NewPassword;
Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
Db.SaveChanges();
transaction.Commit();
return RedirectToAction("Login");
}
else
{
ModelState.AddModelError(string.Empty, "Please Try-Again!");
return View(forgotPasswordMV);
}
}
ModelState.AddModelError(string.Empty, "Fill Field's Properly!");
}
catch
{
ModelState.AddModelError(string.Empty, "Please Try Again later.");
}
}
return View(forgotPasswordMV);
}
> ResetPassword View Code :
@model PizzaRestaurantDrink.Models.ForgotPasswordMV
@{
ViewBag.Title = "Account";
}
<!-- Breadcrumb Start -->
<div class="bread-crumb">
<div class="container">
<div class="matter">
<h2>Account</h2>
<ul class="list-inline">
<li class="list-inline-item"><a href="@Url.Content("~/Home/Index")">HOME</a></li>
</ul>
</div>
</div>
</div>
<!-- Breadcrumb End -->
<!-- Reset Password Form Start -->
<div class="login">
<div class="container">
<div class="row justify-content-center">
<div class="col-sm-12 commontop text-center">
<h4>Account Recovery</h4>
<div class="divider style-1 center">
<span class="hr-simple left"></span>
<i class="icofont icofont-ui-press hr-icon"></i>
<span class="hr-simple right"></span>
</div>
</div>
<div class="col-lg-10 col-md-12">
<div class="row">
<div class="col-sm-12 col-md-6">
<div class="loginnow">
<h5>Reset Password</h5>
@using (Html.BeginForm("ResetPassword", "User", FormMethod.Post, new { @enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.UserID)
@Html.HiddenFor(model => model.UserName)
@Html.HiddenFor(model => model.EmailAddress)
<div class="form-group">
<i class="icofont icofont-lock"></i>
@Html.EditorFor(model => model.NewPassword, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter New Password" } })
@Html.ValidationMessageFor(model => model.NewPassword, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<i class="icofont icofont-lock"></i>
@Html.EditorFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "form-control", @placeholder = "Confirm Password" } })
@Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<div class="links">
<a class="float-right sign" href="@Url.Content("~/User/Login")">Login</a>
</div>
</div>
<div class="form-group">
<input type="submit" value="Reset Password" class="btn btn-theme btn-md btn-wide" />
</div>
}
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="loginto loginnow">
<h5>Login via social accounts</h5>
<ul class="list-unstyled text-center">
<li><a href="#" target="_blank"><i class="icofont icofont-social-facebook"></i> Login with Facebook</a></li>
<li><a href="#" target="_blank"><i class="icofont icofont-social-google-plus"></i> Login with Google+</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Reset Password End -->
Comments
Post a Comment