public async Task <UserCredential> ValidateUserCredentials(string username, string password) { if (string.IsNullOrEmpty(username)) { throw new CallerException("No Username"); } if (string.IsNullOrEmpty(password)) { throw new CallerException("No Password"); } var credential = await UserCredentialLogic.GetUserCredential(username); await Validate(credential, password); credential.Clean(); return(credential); }
public async Task ResetPassword(string username) { var userCredentialLogic = new UserCredentialLogic(AuthContext); var credential = await userCredentialLogic.GetUserCredential(username); if (credential == null) { credential = await FindAndCreateCredentialFromResetText(username); } await ResetPassword(userCredentialLogic, credential); }
public async Task ResetPassword(int userId) { var userCredentialLogic = new UserCredentialLogic(AuthContext); var userLogic = new UserLogic(Cache, UserContext); var credential = await userCredentialLogic.GetUserCredential(userId); if (credential == null) { var user = await userLogic.GetUserWithoutRelated(userId); var userLoginLogic = new UserLoginLogic(AuthContext); credential = await userLoginLogic.CreateEmptyLogin(userId, user.Username); } await ResetPassword(userCredentialLogic, credential); }
public async Task <UserCredential> FindAndCreateCredentialFromResetText(string resetEntry) { var userLoginLogic = new UserLoginLogic(AuthContext); var searchLogic = new SearchLogic(Cache, UserContext); var userLogic = new UserLogic(Cache, UserContext); UserSearch usernameSearch = new UserSearch { SearchText = resetEntry, SearchUsername = true, Operator = SearchOperator.Equals, PageSize = 1 }; // Search by username Page <UserSearchResponse> result = await searchLogic.Search(usernameSearch); if (result != null && result.Records.Count > 0) { var userResult = result.Records.FirstOrDefault(); return(await userLoginLogic.CreateEmptyLogin(userResult.UserId, userResult.SearchFieldValue)); } UserSearch emailSearch = new UserSearch { SearchText = resetEntry, ProfilePropertyName = "email", Operator = SearchOperator.Equals, PageSize = 1 }; // Search by email Page <UserSearchResponse> emailResult = await searchLogic.Search(emailSearch); if (emailResult != null && emailResult.Records.Count > 0) { if (emailResult.TotalRecordCount > 1) { // Should this be friendly? What can we even do if this happens? // We could only check email if it marked unique throw new CallerException("Multiple users have this email"); } var emailUserResult = emailResult.Records.FirstOrDefault(); var user = await userLogic.GetUserWithoutRelated(emailUserResult.UserId); var userCredentialLogic = new UserCredentialLogic(AuthContext); var credential = await userCredentialLogic.GetUserCredential(user.Username); if (credential != null) { return(credential); } return(await userLoginLogic.CreateEmptyLogin(user.UserId, user.Username)); } return(null); }