protected void SendNewPassword(string Name, string Username, string NewPassword, string Email) { SettingsMailServer settings = MailSettingsHelper.GetSettings(); var client = new SmtpClient { Port = settings.Port, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(settings.Username, settings.Password), Host = settings.Host, EnableSsl = settings.EnableSsl }; var mail = new MailMessage(settings.Username, Email) { Subject = "Restore password", Body = $"<h1>Hello {Name}</h1><p>You have requested a new password for your " + $"<b>{Username}</b> account.</p>" + $"<p>Your new password is: <b>{NewPassword}</b>.</p>", IsBodyHtml = true }; client.Send(mail); }
protected void ResetUserPassword() { string link = null; string fullName = string.Empty; var mailSettings = MailSettingsHelper.GetSettings(); if (mailSettings.Enabled == false) { this.Message = "Mail Server not enabled in the settings."; return; } if (string.IsNullOrEmpty(mailSettings.SiteHost)) { this.Message = "Invalid settings, check site host name / port"; return; } var emailAddress = Utils.GetUserEmailAddress(this.Data); var email = emailAddress.EMail; if (!Utils.IsValidEmail(email)) { this.Message = "Username is not an email address"; return; } var transaction = this.Transaction; transaction.Scope(() => { SystemUser systemUser = this.Data; ResetPassword passwordReseToken = GeneratePasswordResetToken(systemUser); fullName = GetFullName(systemUser); UriBuilder uri = BuildResetPasswordLink(mailSettings, passwordReseToken); link = uri.ToString(); }); transaction.Commit(); SendEmail(link, fullName, email); }
public void Register() { Handle.GET("/signin/app-name", () => new AppName()); Handle.GET("/signin", () => Self.GET("/signin/signinuser")); Handle.GET("/signin/user", () => { MasterPage master = this.GetMaster(); if (master.SignInPage != null) { return(master.SignInPage); } Cookie cookie = CookieHelpers.GetSignInCookie(); SignInPage page = new SignInPage() { Data = null }; Session.Current.Store[nameof(SignInPage)] = page; if (cookie != null) { SystemUser.SignInSystemUser(cookie.Value); master.RefreshSignInState(); } return(page); }); Handle.GET("/signin/signinuser", HandleSignInForm); Handle.GET <string>("/signin/signinuser?{?}", HandleSignInForm); Handle.GET("/signin/profile", () => { MasterPage master = this.GetMaster(); master.RequireSignIn = true; master.Open("/signin/partial/profile-form"); return(master); }); Handle.GET("/signin/generateadminuser", (Request request) => new Response() { Body = "Create the admin user by going to '/signin/signinuser' and " + "pressing the 'Create Admin' button.", }, new HandlerOptions() { SkipRequestFilters = true }); Handle.GET("/signin/createadminuser", () => { MasterPage master = this.GetMaster(); master.RequireSignIn = false; master.Open("/signin/partial/createadminuser"); return(master); }); Handle.GET("/signin/settings", (Request request) => { if (!AuthorizationHelper.TryNavigateTo("/signin/settings", request, out Json page)) { return(page); } return(Db.Scope(() => { var settingsPage = new SettingsPage { Html = "/SignIn/views/SettingsPage.html", Uri = request.Uri, Data = MailSettingsHelper.GetSettings() }; return settingsPage; })); }); // Reset password Handle.GET("/signin/user/resetpassword?{?}", (string query, Request request) => { NameValueCollection queryCollection = HttpUtility.ParseQueryString(query); string token = queryCollection.Get("token"); MasterPage master = this.GetMaster(); if (token == null) { // TODO: master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } // Retrive the resetPassword instance var resetPassword = Db.SQL <ResetPassword>( "SELECT o FROM Simplified.Ring6.ResetPassword o WHERE o.Token=? AND o.Expire>?", token, DateTime.UtcNow).FirstOrDefault(); if (resetPassword == null) { // TODO: Show message "Reset token already used or expired" master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } if (resetPassword.User == null) { // TODO: Show message "User deleted" master.Partial = null; // (ushort)System.Net.HttpStatusCode.NotFound; return(master); } SystemUser systemUser = resetPassword.User; var page = new ResetPasswordPage() { Html = "/SignIn/views/ResetPasswordPage.html", Uri = "/signin/user/resetpassword", ResetPassword = resetPassword, FullName = systemUser.WhoIs?.FullName ?? systemUser.Username //Uri = request.Uri // TODO: }; master.Partial = page; return(master); }); Handle.GET("/signin/user/authentication/settings/{?}", (string userid, Request request) => { if (!AuthorizationHelper.TryNavigateTo("/signin/user/authentication/settings/{?}", request, out Json page)) { return(new Json()); } // Get system user var user = Db.SQL <SystemUser>( "SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid) .FirstOrDefault(); if (user == null) { // TODO: Return a "User not found" page return(new Json()); //return (ushort)System.Net.HttpStatusCode.NotFound; } SystemUser systemUser = SystemUser.GetCurrentSystemUser(); var adminGroup = Db.SQL <SystemUserGroup>( "SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", AuthorizationHelper.AdminGroupName).FirstOrDefault(); // Check if current user has permission to get this user instance if (AuthorizationHelper.IsMemberOfGroup(systemUser, adminGroup)) { if (user.WhoIs is Person) { page = Db.Scope(() => new SystemUserAuthenticationSettings { Html = "/SignIn/views/SystemUserAuthenticationSettings.html", Uri = request.Uri, Data = user, UserPassword = Self.GET("/signin/user/authentication/password/" + user.GetObjectID()) }); return(page); } } return(new Json()); }, new HandlerOptions { SelfOnly = true }); Handle.GET("/signin/user/authentication/password/{?}", (string userid, Request request) => { // Get system user var user = Db.SQL <SystemUser>( "SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid) .FirstOrDefault(); if (user == null) { return(new Json()); } Json page = Db.Scope(() => new SetPasswordPage { Html = "/SignIn/views/SetPasswordPage.html", Data = user }); return(page); }, new HandlerOptions { SelfOnly = true }); }