public ActionResult GetUserByEmail(string email) { string message; if (!EmailValidator.IsValidEmailFormat(email)) { Log.Warn("Lookup Request with invalid email. Email is {0}", email); message = string.Format("{0} is an invalid email address", email); } else { User user = this._usersDal.GetUserByExternalId(email, UserExternalIdType.Email); message = user != null && !user.IsSuppressed ? "Found" : "Not Found"; } return(this.RedirectToAction("Index", "Home", new { message })); }
public HttpResponseMessage SubscribeByEmail(SubscribeByEmailRequest request) { if (request == null) { Log.Info("UpdateSubscriptions By email with invalid requestr. request is null"); var errorResponse = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "request is empty"); throw new HttpResponseException(errorResponse); } var email = request.Email; var subscription = request.SubscriptionInfo; Log.Verbose("Start processing subscribe request"); if (!EmailValidator.IsValidEmailFormat(email)) { var errorResponse = Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format("email: {0} is invalid email address", email)); throw new HttpResponseException(errorResponse); } Users.Dal.DataModel.User user; try { user = this.usersDal.CreateOrGetUserByEmail(email, false, this.GetSourceInfo()); } catch (Exception e) { Log.Error(e, "Couldn't subscribe user by email."); throw new HttpResponseException(HttpStatusCode.InternalServerError); } if (user.Info != null && user.MsId != null && user.Info.Location != null) { Log.Warn("Subscribe by email failure. User already exists in the system, need to go in the authenticated state in order to change settings. UserId is: {0}", user.Id); throw new HttpResponseException(HttpStatusCode.Conflict); } this.UpdateSubscriptions(user.Id, new List <LoMo.UserServices.DataContract.Location> { subscription }); return(new HttpResponseMessage(HttpStatusCode.Accepted)); }
public HttpResponseMessage UpdateEmail(string emailAddress) { Log.Info("Start updating user's email address "); var identity = Thread.CurrentPrincipal.Identity as CustomIdentity; if (identity == null) { Log.Error("Update Email - User Identity is null while we are in authenticated context"); throw new HttpResponseException(HttpStatusCode.InternalServerError); } if (!EmailValidator.IsValidEmailFormat(emailAddress)) { Log.Info("Update Email Request with invalid email"); var errorResponse = Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format("email: {0} is invalid email address", emailAddress)); throw new HttpResponseException(errorResponse); } var identityEmail = identity.EmailAddress; var userId = identity.UserId; var user = this._usersDal.GetUserByUserId(userId); if (user.Email == emailAddress) { Log.Verbose("No Operation of update email address. User already have the input email address. User Id={0}", userId); // Create confirmation code entity if confirmation is required or not required. // The creation when confirmation isn't required help us to follow the sequence of update requests that the user done. this._usersDal.CreateConfirmationCode(emailAddress, EntityType.AuthenticatedEmailAddress, userId); return(Request.CreateResponse(HttpStatusCode.Accepted, "SameEmail")); } var emailUser = this._usersDal.GetUserByExternalId(emailAddress, UserExternalIdType.Email); if (user.IsSuppressed || (emailUser != null && emailUser.IsSuppressed)) { Log.Warn("Can't update user email address. User is suppressed or target email is suppressed. User Id={0}; Target Email User Id={1}", user.Id, emailUser.Id); return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } if (emailUser != null && !string.IsNullOrEmpty(emailUser.MsId)) { Log.Warn("Can't update user email address for user. Email address is already in user by other authenticated user. User Id={0}; Target Email User Id={1}", user.Id, emailUser.Id); return(new HttpResponseMessage(HttpStatusCode.Conflict)); } // Create confirmation code entity if confirmation is required or not required. // The creation when confirmation isn't required help us to follow the sequence of update requests that the user done. Tuple <string, int> confiramtionCodeResonse = this._usersDal.CreateConfirmationCode(emailAddress, EntityType.AuthenticatedEmailAddress, userId); string userIdHash = confiramtionCodeResonse.Item1; int confirmationCode = confiramtionCodeResonse.Item2; // Do not send a confirmation mail for email change if one of the following is true // 1. The email address is part of the user identity and already been validated // 2. Email change request is done from the Microsoft Earn site if ((emailAddress == identityEmail) || (IsEarnUser())) { try { Log.Verbose("Start updating user email address. User Id={0}", userId); this._usersDal.UpdateUserEmail(userId, emailAddress, true); Log.Verbose("Completed updating user email address. User Id={0}", userId); return(Request.CreateResponse(HttpStatusCode.Accepted, "EmailChanged")); } catch (Exception e) { Log.Error(e, "Couldn't update user email. User Id={0} ", userId); throw new HttpResponseException(HttpStatusCode.InternalServerError); } } ConfirmationEmailCargo confirmationEmailCargo = new ConfirmationEmailCargo { Id = Guid.NewGuid(), EntityType = EntityType.AuthenticatedEmailAddress, EmailAddress = emailAddress, UserIdHash = userIdHash, ConfirmationCode = confirmationCode }; //queue the email confirmation job this._confirmationJobsQueue.Enqueue(confirmationEmailCargo); return(Request.CreateResponse(HttpStatusCode.Accepted, "EmailConfirmationRequired")); }