/// <summary> /// Sends the provided email to the provided user. /// </summary> /// <param name="user">The user being emailed.</param> /// <param name="subject">The subject of the email to send.</param> /// <param name="message">The message of the email to send.</param> public virtual void SendEmail(User user, string subject, string message) { if (user == null) throw new ArgumentNullException("user"); SendEmail(user.Name, user.Email, subject, message); }
/// <summary> /// Updates the user from the form. /// </summary> public bool Update(User user) { AutoNavigate = false; // Get the original user data User originalUser = RetrieveStrategy.New<User>().Retrieve<User>("ID", user.ID); // If the password wasn't added then reset it if (user.Password == null || user.Password == String.Empty) user.Password = originalUser.Password; else user.Password = Crypter.EncryptPassword(user.Password); bool success = base.Update(user); // If the current user edited their username then fix their authentication session if (originalUser.Username == AuthenticationState.Username && user.Username != AuthenticationState.Username) AuthenticationState.Username = user.Username; Result.Display(IsSelf ? Properties.Language.YourAccountUpdated : Properties.Language.UserUpdated); if (success) NavigateAfterUpdate(); return success; }
public void Test_React() { IUser author = new User(); author.ID = Guid.NewGuid(); AuthenticationState.User = (User)author; MockAuthoredEntity entity = CreateStrategy.New<MockAuthoredEntity>(false).Create<MockAuthoredEntity>(); IUser foundAuthor = entity.Author; Assert.IsNotNull(foundAuthor, "No author assigned."); Assert.AreEqual(author.ID.ToString(), foundAuthor.ID.ToString(), "IDs didn't match."); }
/// <summary> /// Sends the provided notification message to the provided notifiable users. /// </summary> /// <param name="entity">The recipients of the notification.</param> /// <param name="entity">The entity involved in the event that users are being notified about.</param> /// <param name="subject">The subject of the email to send to the provided notifiable users.</param> /// <param name="message">The message of the email to send to the provided notifiable users.</param> public virtual void SendNotification(User[] recipients, IEntity entity, string subject, string message) { using (LogGroup logGroup = LogGroup.StartDebug("Sending a notification to the provided recipients.")) { LogWriter.Debug("Recipients: " + recipients.Length.ToString()); foreach (User user in recipients) { if (user != null && user.EnableNotifications) { LogWriter.Debug("To: " + user.Email); string replyTo = "*****@*****.**"; if (Config.Application.Settings.ContainsKey("SystemEmail")) { replyTo = Config.Application.Settings.GetString("SystemEmail"); } else LogWriter.Error("No system email has been set. Notification emails have '*****@*****.**' in the reply field instead."); LogWriter.Debug("Reply to: " + replyTo); try { MailMessage mm = new MailMessage(replyTo, user.Email, PrepareNotificationText(subject, entity), PrepareNotificationText(message, entity)); Emailer.CreateSmtpClient().Send(mm); } catch(FormatException ex) { LogWriter.Error(ex); } catch(SmtpFailedRecipientException ex) { LogWriter.Error(ex); } catch(SmtpException ex) { LogWriter.Error(ex); } } } } }
public virtual bool ExecuteSave(User user) { bool success = false; using (LogGroup logGroup = LogGroup.Start("Saving the new user.", NLog.LogLevel.Debug)) { // TODO: Clean up LogWriter.Debug("Auto navigate: " + AutoNavigate.ToString()); user.Password = Crypter.EncryptPassword(user.Password); success = base.ExecuteSave(user); LogWriter.Debug("Success: " + success.ToString()); if (!success) { LogWriter.Debug("Failed to save (username in use)."); } } return success; }
public void Test_Setup() { using (LogGroup logGroup = LogGroup.StartDebug("Testing the ApplicationInstaller.Setup function.")) { CreateDummyVersionFile(TestUtilities.GetTestApplicationPath(this, "MockApplication")); User admin = new User(); admin.ID = Guid.NewGuid(); admin.Username = "******"; admin.Password = Crypter.EncryptPassword("pass"); admin.Validator = ValidateStrategy.New(admin); ApplicationInstaller installer = new ApplicationInstaller(); installer.ApplicationPath = "/MockApplication"; installer.Administrator = admin; installer.AdministratorRoleName = "Administrator"; installer.PathVariation = "testing"; installer.FileMapper = new MockFileMapper(this); installer.DataProviderInitializer = new MockDb4oDataProviderInitializer(this); installer.EnableTesting = true; installer.Setup(); User foundAdministrator = DataAccess.Data.Reader.GetEntity<User>("ID", admin.ID); DataAccess.Data.Activator.Activate(foundAdministrator); Assert.AreEqual(1, foundAdministrator.Roles.Length, "The administrator user isn't in the administrator role."); } }
private void SendResetEmail(User user, string subject, string message, string applicationUrl) { using (LogGroup logGroup = LogGroup.StartDebug("Sending reset email.")) { string title = Configuration.Config.Application.Title; string resetUrl = applicationUrl.Trim('/') + "/ChangePassword.aspx?p=" + user.Password + "&u=" + user.Email; message = message.Replace("${ResetUrl}", resetUrl); message = message.Replace("${Title}", title); string fromEmail = "*****@*****.**"; if (Config.Application.Settings.ContainsKey("SystemEmail") && Config.Application.Settings.GetString("SystemEmail") != String.Empty) fromEmail = Config.Application.Settings.GetString("SystemEmail"); LogWriter.Debug("To email: " + user.Email); LogWriter.Debug("From email: " + fromEmail); LogWriter.Debug("Subject: " + subject); LogWriter.Debug("Message: " + message); SendEmailStrategy.New(RequireAuthorisation).SendEmail(subject, message, "System", fromEmail, user.Name, user.Email); } }
/// <summary> /// Saves the administrator user and administrator role. /// </summary> /// <param name="administrator">The default administrator user.</param> /// <param name="administratorRole">The administrator role.</param> private void Save(User administrator, UserRole administratorRole) { using (LogGroup logGroup = LogGroup.StartDebug("Saving the provided user and role.")) { if (administrator == null) throw new ArgumentNullException("administrator"); if (administratorRole == null) throw new ArgumentNullException("administratorRole"); AuthenticationState.Username = administrator.Username; if (SaveStrategy.New<User>(false).Save(administrator)) { administratorRole.Users = new User[]{administrator}; SaveStrategy.New<UserRole>(false).Save(administratorRole); } else LogWriter.Debug("User already exists. Skipping save."); } }
/// <summary> /// Creates the administrator role and assigns it to the provided user. /// </summary> /// <param name="administrator">The default administrator to add to the administrator role.</param> /// <returns>The administrator role.</returns> private UserRole CreateAdministratorRole(User administrator) { UserRole administratorRole = null; using (LogGroup logGroup = LogGroup.StartDebug("Creating the administrator role.")) { administratorRole = CreateStrategy.New<UserRole>(false).Create<UserRole>(); administratorRole.ID = Guid.NewGuid(); if (AdministratorRoleName == String.Empty) throw new InvalidOperationException("The AdministratorRoleName property has not been set."); administratorRole.Name = AdministratorRoleName; } return administratorRole; }
/// <summary> /// Sets the user being represented. /// </summary> public Member(User user) { User = user; }