private void Prepare(UnsubscribeRequestModel requestModel, UnsubscribeModel unsubscribeModel) { requestModel.Prepare(); requestModel.Validate(); // Get the user. var user = _usersQuery.GetUser(requestModel.UserId.Value); if (user == null) { throw new ValidationErrorsException(new NotFoundValidationError("UserId", requestModel.UserId.Value)); } if (CurrentRegisteredUser == null) { unsubscribeModel.Login.LoginId = _loginCredentialsQuery.GetLoginId(requestModel.UserId.Value); } // Get the category. unsubscribeModel.Category = _settingsQuery.GetCategory(requestModel.Category); if (unsubscribeModel.Category == null) { throw new ValidationErrorsException(new NotFoundValidationError("Category", requestModel.Category)); } }
RegisteredUser IAuthenticationManager.GetUser(HttpContextBase context) { var identity = context.GetRegisteredUserIdentity(); if (identity == null) { return(null); } // Lazy load. var user = identity.User as RegisteredUser; if (user == null) { user = _usersQuery.GetUser(identity.Id); if (user == null) { // Someone is asking for the logged in user but there isn't one. // Just throw them straight out. LogOut(context); return(null); } identity.User = user; } return(user); }
private IRegisteredUser GetUser(string loginId) { if (loginId == null) { throw new ArgumentNullException("loginId"); } loginId = CleanLoginId(loginId); if (loginId.Length == 0) { throw new ArgumentException("The loginId is an empty string.", "loginId"); } var userId = _loginCredentialsQuery.GetUserId(loginId); if (userId != null) { return(_usersQuery.GetUser(userId.Value)); } // If the user can't be found with the loginId try parsing it as their id. userId = ParseUtil.TryParseGuid(loginId); if (userId != null) { var user = _usersQuery.GetUser(userId.Value); if (user != null) { return(user); } } // In those environments where the loginId can be obfuscated use that version, // eg [email protected] instead of [email protected]. if (_obfuscateEmailAddresses && loginId.IndexOf('@') != -1) { userId = _loginCredentialsQuery.GetUserId(MiscUtils.ObfuscateEmailAddress(loginId)); if (userId != null) { return(_usersQuery.GetUser(userId.Value)); } } return(null); }
private IRegisteredUser GetUser(Guid providerId, string externalId) { if (externalId == null) { throw new ArgumentNullException("externalId"); } var userId = _externalCredentialsQuery.GetUserId(providerId, externalId); return(userId != null?_usersQuery.GetUser(userId.Value) : null); }
public ActionResult NewPassword(NewPasswordModel newPassword) { try { // Make sure everything is in order. newPassword.Validate(); // First look for the login id. IRegisteredUser user = null; var userId = _loginCredentialsQuery.GetUserId(newPassword.LoginId); if (userId != null) { user = _usersQuery.GetUser(userId.Value); } else { // Look for an employer treating it as an email address. var employers = _employersQuery.GetEmployers(newPassword.LoginId); if (employers.Count > 1) { ModelState.AddModelError(string.Format("There is more than one user with the specified email address. Please enter one of the usernames or <a href=\"{0}\">contact us</a> for assistance.", SupportRoutes.ContactUs.GenerateUrl())); return(View("NewPasswordSent", newPassword)); } if (employers.Count == 1) { user = employers[0]; } } if (user == null || user.UserType == UserType.Administrator) { ModelState.AddModelError("The user cannot be found. Please try again."); } else { // Now reset the password. var credentials = _loginCredentialsQuery.GetCredentials(user.Id); _loginCredentialsCommand.ResetPassword(user.Id, credentials); return(View("NewPasswordSent", newPassword)); } } catch (UserException ex) { ModelState.AddModelError(ex, new StandardErrorHandler()); } return(View(newPassword)); }
void ISecurityHandler.OnPasswordReset(bool isGenerated, Guid userId, string loginId, string password) { if (!isGenerated) { return; } var contact = _usersQuery.GetUser(userId); if (contact == null) { return; } var reminderEmail = new PasswordReminderEmail(contact, loginId, password); _emailsCommand.TrySend(reminderEmail, null); }
AuthenticationResult ILinkedInAuthenticationCommand.AuthenticateUser(string linkedInId) { var profile = _linkedInQuery.GetProfile(linkedInId); if (profile == null) { return new AuthenticationResult { Status = AuthenticationStatus.Failed } } ; var user = _usersQuery.GetUser(profile.UserId); if (user == null) { return new AuthenticationResult { Status = AuthenticationStatus.Failed } } ; // Only support employers for now. if (user.UserType != UserType.Employer) { return new AuthenticationResult { Status = AuthenticationStatus.Failed } } ; return(new AuthenticationResult { User = user, Status = GetAuthenticationStatus(user), }); }
private void CheckActivation() { if (RequiresActivation && LoggedInUserType == UserType.Member && !LoggedInUserActivated) { // Check whether the status needs to be updated. if (!LoggedInUserCheckStatus) { RedirectWithReturnUrlAndMessage(AccountsRoutes.NotActivated.GenerateUrl()); } // Reset. var user = _usersQuery.GetUser(LoggedInUserId.Value); _authenticationManager.UpdateUser(new HttpContextWrapper(HttpContext.Current), user, false); // Retry. if (!user.IsActivated) { RedirectWithReturnUrlAndMessage(AccountsRoutes.NotActivated.GenerateUrl()); } } }