SealSecurityDefaultResetPasswordScript Field |
Default implementation used when ResetPasswordScript is empty: sends a reset link by email using the notification email device
Namespace: Seal.ModelAssembly: SealLibrary (in SealLibrary.dll) Version: 10.0.1.0+a44cd3a7f03c2bf3cdbd971a878c679e40bed08a
Syntaxpublic const string DefaultResetPasswordScript = "@using Newtonsoft.Json\n@using System.Web\n@{\n SecurityUser user = Model;\n var id = user.WebUserName;\n var request = user.Request;\n var repository = user.Security.Repository;\n var security = user.Security;\n\n //Implementation using Logins defined in the security\n var login = security.Logins.FirstOrDefault(i => i.Id == id);\n if (login == null && id.Contains("@")) login = security.Logins.FirstOrDefault(i => i.Email == id);\n\n if (login == null) throw new Exception($"No login found for '{id}'");\n if (string.IsNullOrEmpty(login.Email)) throw new Exception($"No Email found for '{id}'");\n\n //Generate Token for reset\n var guid = Guid.NewGuid().ToString();\n var vals = new List<string>\n {\n id,\n guid,\n JsonConvert.SerializeObject(DateTime.Now)\n };\n var token = HttpUtility.UrlEncode(CryptoHelper.EncryptWithRSAContainer(string.Join("\r", vals), "Reset" + guid, false));\n\n var url = $"{request.Scheme}://{request.Host}{request.PathBase}?guid={guid}&ptoken={token}";\n var message = repository.TranslateWeb("Please find your link to reset your password (Note that this link is valid 10 minutes):");\n var from = ""; //Default of the device will be used\n var to = login.Email;\n var subject = "Seal Report Password Reset";\n var linkLabel = repository.TranslateWeb("Reset link");\n var body = $"{ message}: <br><b><a href='{url}'>{linkLabel}</a></b><br>";\n\n if (!repository.SendNotificationEmail(from, to, subject, true, body)) throw new Exception("Unable to send email for Reset Password.");\n}\n"Field Value
String
See Also