public override string ResetPassword(string username, string answer) { if (!EnablePasswordReset) { throw new NotSupportedException(); } using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByName(ApplicationName, username); if (user == null) { throw new UserNotFoundException(username); } if (RequiresQuestionAndAnswer && user.ValidatePasswordAnswer(answer, PasswordAttemptWindow, MaxInvalidPasswordAttempts) == false) { transaction.Commit(); throw new MembershipPasswordException(); } else { string newPassword = System.Web.Security.Membership.GeneratePassword(MinRequiredPasswordLength, MinRequiredNonAlphanumericCharacters); user.ChangePassword(newPassword); transaction.Commit(); return(newPassword); } } }
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { try { using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByName(ApplicationName, username); if (user == null) { throw new UserNotFoundException(username); } if (user.CheckPassword(password) == false) { throw new UserNotFoundException(username); } user.ChangePasswordQuestionAnswer(newPasswordQuestion, newPasswordAnswer); transaction.Commit(); } return(true); } catch (Exception ex) { LogException(ex, "ChangePasswordQuestionAndAnswer"); return(false); } }
public override void UpdateUser(MembershipUser user) { using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User dbUser = dataStore.FindByName(ApplicationName, user.UserName); if (dbUser == null) { throw new UserNotFoundException(user.UserName); } //Check email if (RequiresUniqueEmail) { if (string.IsNullOrEmpty(user.Email)) { throw new EmailNotValidException(user.Email); } IList <User> emailUsers = dataStore.FindByEmail(ApplicationName, user.Email); if (emailUsers.Count > 0 && emailUsers[0].Id != dbUser.Id) { throw new EmailDuplicatedException(user.Email); } } dbUser.Comment = user.Comment; dbUser.Email = user.Email; dbUser.Enabled = user.IsApproved; transaction.Commit(); } }
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { var membershipUsers = new MembershipUserCollection(); using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); var paging = new PagingInfo(pageSize, pageIndex); IList <User> users = dataStore.FindAll(ApplicationName, paging); totalRecords = (int)paging.RowCount; foreach (User u in users) { Person p = PersonManager.GetPersonByUserId(u.Id); if (p != null) { membershipUsers.Add(UserToMembershipUser(u)); } } } return(membershipUsers); }
public override User GetUserByName(string userName) { using (var transaction = new TransactionScope(_configuration)) { var uDS = new UserDataStore(transaction); return(uDS.FindByName(_applicationName, userName)); } }
public override User GetUser(string userId) { using (var transaction = new TransactionScope(_configuration)) { var uDS = new UserDataStore(transaction); return(uDS.FindByKey(userId)); } }
public override User GetUserByPersonId(string personId) { using (var transaction = new TransactionScope(_configuration)) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByPerson(_applicationName, personId); return(user); } }
public override void UpdateUser(User user) { using (var transaction = new TransactionScope(_configuration)) { var uDS = new UserDataStore(transaction); uDS.Update(user); transaction.Commit(); } }
public override int GetNumberOfUsersOnline() { var onlineSpan = new TimeSpan(0, System.Web.Security.Membership.UserIsOnlineTimeWindow, 0); using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); return(dataStore.NumbersOfLoggedInUsers(ApplicationName, onlineSpan)); } }
public override string GetUserNameByEmail(string email) { using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); IList <User> users = dataStore.FindByEmail(ApplicationName, email); if (users.Count == 0) { return(null); } return(users[0].Name); } }
public override IList <User> GetAllUsers() { using (var transaction = new TransactionScope(_configuration)) { var dataStore = new UserDataStore(transaction); IList <User> users = dataStore.FindAllEnabled(); if (users == null || users.Count == 0) { return(null); } transaction.Commit(); return(users); } }
public override bool ValidateUser(string username, string password) { using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User dbUser = dataStore.FindByName(ApplicationName, username); if (dbUser == null) { return(false); //throw new UserNotFoundException(username); } bool valid = dbUser.LogOn(password, PasswordAttemptWindow, MaxInvalidPasswordAttempts); transaction.Commit(); return(valid); } }
public override bool UnlockUser(string userName) { using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByName(ApplicationName, userName); if (user == null) { throw new UserNotFoundException(userName); } user.Unlock(); transaction.Commit(); } return(true); }
public override bool DeleteUser(string username, bool deleteAllRelatedData) { try { using (var transaction = new TransactionScope(_mConfiguration)) { if (deleteAllRelatedData) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByName(ApplicationName, username); var userInRoleStore = new UserInRoleDataStore(transaction); IList <UserInRole> userInRoles = userInRoleStore.FindForUser(ApplicationName, user); foreach (UserInRole ur in userInRoles) { ur.Deleted = true; userInRoleStore.Update(ur); } } var dataStore1 = new UserDataStore(transaction); User user1 = dataStore1.FindByName(ApplicationName, username); if (user1 == null) { throw new UserNotFoundException(username); } // Rename the user before deleting, this will allow a new user with the same name. user1.Name = user1.Name + DateTimeHelper.GetCurrentTimestamp(); user1.Deleted = true; dataStore1.Update(user1); transaction.Commit(); } return(true); } catch (UserNotDeletedException ex) { LogException(ex, "DeleteUser"); return(false); } }
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) { using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByKey((string)providerUserKey); if (user == null) { return(null); } if (userIsOnline) { user.LastActivityDate = DateTime.Now; } transaction.Commit(); return(UserToMembershipUser(user)); } }
public override MembershipUser GetUser(string username, bool userIsOnline) { using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); User user = dataStore.FindByName(ApplicationName, username); if (user == null) { return(null); } if (userIsOnline) { user.LastActivityDate = DateTime.Now; } transaction.Commit(); return(UserToMembershipUser(user)); } }
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { var membershipUsers = new MembershipUserCollection(); using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); var paging = new PagingInfo(pageSize, pageIndex); IList <User> users = dataStore.FindByNameLike(ApplicationName, usernameToMatch, paging); totalRecords = (int)paging.RowCount; foreach (User u in users) { membershipUsers.Add(UserToMembershipUser(u)); } } return(membershipUsers); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="email"></param> /// <param name="passwordQuestion"></param> /// <param name="passwordAnswer"></param> /// <param name="isApproved"></param> /// <param name="providerUserKey">Not used</param> /// <param name="status"></param> /// <returns></returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { try { //Validate password ValidatePassword(username, password, true); using (var transaction = new TransactionScope(_mConfiguration)) { var dataStore = new UserDataStore(transaction); //Check name if (dataStore.FindByName(ApplicationName, username) != null) { status = MembershipCreateStatus.DuplicateUserName; return(null); } //Check email if (RequiresUniqueEmail) { if (string.IsNullOrEmpty(email)) { status = MembershipCreateStatus.InvalidEmail; return(null); } if (dataStore.FindByEmail(ApplicationName, email).Count > 0) { status = MembershipCreateStatus.DuplicateEmail; return(null); } } var user = new User(ApplicationName, username); user.Email = email; user.ChangePassword(password); user.ChangePasswordQuestionAnswer(passwordQuestion, passwordAnswer); user.Enabled = isApproved; dataStore.Insert(user); transaction.Commit(); status = MembershipCreateStatus.Success; return(UserToMembershipUser(user)); } } catch (CodeInvalidCharsException ex) //this exception is caused by an invalid user Name { LogException(ex, "CreateUser"); status = MembershipCreateStatus.InvalidUserName; return(null); } catch (MembershipPasswordException ex) { LogException(ex, "CreateUser"); status = MembershipCreateStatus.InvalidPassword; return(null); } catch (Exception ex) { LogException(ex, "CreateUser"); status = MembershipCreateStatus.ProviderError; return(null); } }