Example #1
0
        public ActionResult ForgotPassword(string key)
        {
            if (String.IsNullOrWhiteSpace(key))
            {
                return(View());
            }

            var userDetail = _userManagement.IsValidEmail(key)
                ? _userManagement.FindUserByEmail(key)
                : _userManagement.FindUserByUserName(key);

            if (userDetail == null)
            {
                TempData["errorMessage"] = "Invalid username or email address";
                return(View());
            }
            else
            {
                var result = _userManagement.SetResetPasswordForUser(userDetail.UserId);
                if (result.Success)
                {
                    var resetPasswordCode = result.Value.ToString();

                    var
                        emailBody =
                        "<html xmlns='http://www.w3.org/1999/xhtml' xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'><meta name='viewport' content='width=device-width'>	<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings>  <o:AllowPNG/>  <o:PixelsPerInch>96</o:PixelsPerInch> </o:OfficeDocumentSettings></xml><![endif]--></head><body style='min-width: 100%;-webkit-text-size-adjust: 100%;-ms-text-size-adjust: 100%;margin: 0;padding: 0;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;text-align: left;line-height: 19px;font-size: 14px;background-color: rgb(244,244,244);padding-top: 10px;width: 100% !important;'><center style='width: 100%;min-width: 580px;'><table style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='email-container' style='word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 0;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;border-collapse: collapse !important;'><table class='twelve columns' style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 580px;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='email-header' style='word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 0px 0px 10px;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;background-color: #ef5350;padding-right: 10px;padding-left: 10px;padding-top: 10px;padding-bottom: 18px;border-top-right-radius: 5px;border-top-left-radius: 5px;border-collapse: collapse !important;'><table class='body container' style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;height: 100%;width: 580px;margin: 0;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;line-height: 19px;font-size: 14px;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='sync-inc wrapper' style='word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 2px 10px 10px;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;position: relative;border-collapse: collapse !important;'><h6 style='color: white;font-family: &quot;Segoe UI&quot;,sans-serif !important;font-weight: 500;padding: 0;margin: 0;text-align: left;line-height: 1.3;word-break: normal;font-size: 20px;font-style: normal;'><a href='"
                        + GlobalAppSettings.SystemSettings.BaseUrl + "/accounts/login' style='color: white;text-decoration: none;'>"
                        + GlobalAppSettings.SystemSettings.OrganizationName + "</a></h6></td></tr></tbody></table><table class='twelve columns' style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 580px;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='wrapper last' style='word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 50px 0px 10px 273px;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;position: relative;border-collapse: collapse !important;'><img src='"
                        + GlobalAppSettings.SystemSettings.BaseUrl + "/Content/Images/Application/"
                        + GlobalAppSettings.SystemSettings.MainScreenLogo + "' style='outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;width: auto;max-width: 100%;float: none;clear: both;margin: 0 auto;'></td></tr><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='welcome wrapper last' style='word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 0px 0px 17px;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;position: relative;border-collapse: collapse !important;'><h6 style='color: white;font-family: &quot;Segoe UI&quot;,sans-serif;font-weight: lighter;padding: 0;margin: 0;text-align: center;line-height: 1.3;word-break: normal;font-size: 20px;'>RESET YOUR LOST PASSWORD</h6></td></tr></tbody></table></td></tr></tbody></table><table class='twelve columns' style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 580px;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='message-body' style='word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;padding: 0px 0px 10px;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;background-color: white;padding-right: 10px;padding-left: 10px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;border-collapse: collapse !important;'><table class='twelve columns' style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 580px;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='activation-msg' style='padding-top: 20px;padding-left: 4px; padding-bottom: 7px; word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto; vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;border-collapse: collapse !important;'><p style='margin-bottom: 4px;margin: 0;color: #353535;font-family: &quot;Segoe UI&quot;,sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 12px;'>Hello "
                        + userDetail.DisplayName + ",</p></td></tr></tbody></table><table class='twelve columns' style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 580px;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='activation-msg' style='padding-top: 5px;padding-left: 4px; padding-bottom: 18px; word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto; vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;border-collapse: collapse !important;'><p style='margin-bottom: 4px;margin: 0;color: #353535;font-family: &quot;Segoe UI&quot;,sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 12px;'>We have received a request to reset the password for your grout account. Please click Reset to set a new password.</p></td></tr></tbody></table><table style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td style='padding-left: 4px;padding-bottom: 0px; padding-top: 0px; word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;border-collapse: collapse !important;'><table class='block-grid five-up' style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;width: 100%;max-width: 580px;'><tbody><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='activate-btn center' style='border-radius: 3px; padding: 0px;'><div><!--[if mso]><v:roundrect xmlns:v='urn:schemas-microsoft-com:vml' xmlns:w='urn:schemas-microsoft-com:office:word' href='"
                        + GlobalAppSettings.SystemSettings.BaseUrl + "/accounts/forgot-password/change-password?userid="
                        + userDetail.UserId + "&recoverycode="
                        + resetPasswordCode + "' style='height:28px;v-text-anchor:middle;width:100px;' arcsize='11%' stroke='f' fillcolor='#ef5350'><w:anchorlock/><center><![endif]--><a href='"
                        + GlobalAppSettings.SystemSettings.BaseUrl + "/accounts/forgot-password/change-password?userid="
                        + userDetail.UserId + "&recoverycode="
                        + resetPasswordCode + "'style='background-color:#ef5350;border-radius:3px;color:#ffffff;display:inline-block; font-family: &quot;Segoe UI&quot;,sans-serif; font-size:14px;font-weight:500;line-height:28px;text-align:center;text-decoration:none;width:100px;-webkit-text-size-adjust:none;'>RESET</a><!--[if mso]></center></v:roundrect><![endif]--></div></td></tr></tbody></table></td></tr></tbody></table><table class='twelve columns' style='border-spacing: 0;border-collapse: collapse;padding: 0;vertical-align: top;text-align: left;margin: 0 auto;width: 580px;'><tr style='padding: 0;vertical-align: top;text-align: left;'><td class='signature' style='padding-left: 4px;padding-bottom: 0px; padding-top: 18px; word-break: break-word;-webkit-hyphens: auto;-moz-hyphens: auto;hyphens: auto;vertical-align: top;text-align: left;color: #222222;font-family: &quot;Helvetica&quot;, &quot;Segoe UI&quot;, sans-serif;font-weight: normal;margin: 0;line-height: 19px;font-size: 14px;border-collapse: collapse !important;'><p style='margin-bottom: 6px;color: #353535;font-family: &quot;Segoe UI&quot;,sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 12px;margin-top: 0px;'>Regards,</p><p style='margin: 0;margin-bottom: 10px;color: #353535;font-family: &quot;Segoe UI&quot;,sans-serif;font-weight: normal;padding: 0;text-align: left;line-height: 19px;font-size: 12px;'>"
                        + GlobalAppSettings.SystemSettings.OrganizationName + " </p></td></tr></table></td></tr></tbody></table></td></tr></tbody></table></center></body></html>";

                    GlobalAppSettings.SendCustomMail(userDetail.Email, emailBody, GlobalAppSettings.SystemSettings.OrganizationName + ": Reset password");

                    TempData["message"] = "An email with instructions on how to change your password has been sent to " + userDetail.Email;
                    return(Redirect("/accounts/forgot-password/code-confirmation?userId=" + userDetail.UserId));
                }
                else
                {
                    TempData["errorMessage"] = "Internal server error. Please try again.";
                    return(View());
                }
            }
        }