/// <summary> /// Create an appropriate redirect uri for unauthenticated user email confirm request /// </summary> /// <param name="uh">Hash of unauthenticated user id</param> /// <param name="result">The confirm entity result</param> /// <returns>Redirect Uri</returns> private Uri HandleUnauthEmailConfirmed(string uh, ConfirmEntityResult result) { Uri redirectUri = null; //Mark the unauthenticated user email as confirmed _usersDal.UpdateUserEmail(result.UserId.Value, result.EntityId, true); User user = _usersDal.GetUserByUserId(result.UserId.Value); if (user != null) { //Check if the user's account is already linked and return the appropriate authentication provider info. if (!string.IsNullOrEmpty(user.MsId)) { redirectUri = user.MsId.IndexOf(FbIdPattern, StringComparison.OrdinalIgnoreCase) != -1 ? new Uri(_bingOffersBaseUri, string.Format(UnauthEmailConfirmAccountLinkedPage, Facebook)) : new Uri(_bingOffersBaseUri, string.Format(UnauthEmailConfirmAccountLinkedPage, Microsoft)); } else { Tuple <string, int> confirmationResponse = _usersDal.CreateConfirmationCode(user.Id.ToString(), EntityType.AccountLink, user.Id); redirectUri = new Uri(_bingOffersBaseUri, string.Format(UnauthEmailConfirmAccountNotLinkedPage, uh, confirmationResponse.Item2)); } } Log.Verbose("Email Confirmed and updated for user. User Id={0} ", result.UserId); return(redirectUri); }
public ActionResult Alink(string uh, int c) { Log.Verbose("Start confirming account link code for unauthenticated user. User Id Hash = {0}", uh); Uri redirectUri = new Uri(_bingOffersBaseUri, UnauthAlinkConfirmUserErrorPage); if (string.IsNullOrEmpty(uh)) { Log.Info("Unauthenticated user account link code confirm request failed. Request with invalid parameter. User Hash is null or empty", uh); } else { try { ConfirmEntityResult result = _usersDal.ConfirmEntity(uh, EntityType.AccountLink, c); switch (result.Status) { case ConfirmStatus.CodeConfirmed: redirectUri = HandleUnauthAlinkConfirmed(uh, c, result); break; case ConfirmStatus.CodeWrong: redirectUri = new Uri(_bingOffersBaseUri, string.Format(UnauthAlinkConfirmExpiredCodePage, uh)); Log.Verbose("Unauthenticated user account link code confirm request failed. The user provided wrong code. User Id Hash = {0}", uh); break; case ConfirmStatus.Invalid: redirectUri = new Uri(_bingOffersBaseUri, string.Format(UnauthAlinkConfirmExpiredCodePage, uh)); Log.Verbose("Unauthenticated user email account link code request failed. The confirmation code is expired. User Id Hash = {0}", uh); break; case ConfirmStatus.CodeNotFound: Log.Verbose("Unauthenticated user email account link code request failed. The confirmation code is not found in the system. User Id Hash = {0}", uh); break; } } //Ideally this should not happen. If it happens, just means something is terribly screwed up with this user record catch (UserNotExistsException invalidUserException) { Log.Error(invalidUserException, "Account link code confirmed for the User Id Hash = {0}, but the user could not be located in the system", uh); } catch (Exception exp) { Log.Error(exp, "Unexpected error in confirming unauthenticated user account link code. User Id Hash = {0}", uh); } } return(new RedirectResult(redirectUri.ToString())); }
public ActionResult Email(string uh, int c) { Log.Verbose("Starting Confirming email. User Id Hash = {0}", uh); Uri redirectUri = new Uri(_bingOffersBaseUri, AuthUserInvalidPage); if (string.IsNullOrEmpty(uh)) { Log.Info("Confirm Email Request with invalid paramter. User Hash is null or empty", uh); } else { try { ConfirmEntityResult result = _usersDal.ConfirmEntity(uh, EntityType.AuthenticatedEmailAddress, c); switch (result.Status) { case ConfirmStatus.CodeConfirmed: _usersDal.UpdateUserEmail(result.UserId.Value, result.EntityId, true); Log.Verbose("Email confirmed and updated for user. User Id={0} ", result.UserId); redirectUri = new Uri(_bingOffersBaseUri, string.Format(AuthUserConfirmedPage, result.EntityId)); break; case ConfirmStatus.CodeWrong: redirectUri = new Uri(_bingOffersBaseUri, AuthUserInvalidPage); Log.Verbose("Can't confirm email. The user provided wrong code. User Id Hash = {0}", uh); break; case ConfirmStatus.Invalid: redirectUri = new Uri(_bingOffersBaseUri, AuthUserInvalidPage); Log.Verbose("Can't confirm email. The confirmation code is expired. User Id Hash = {0}", uh); break; case ConfirmStatus.CodeNotFound: Log.Verbose("Can't confirm email. Cannot locate the confirmation request for this user in the system. User Id Hash = {0}", uh); break; } } catch (Exception exp) { Log.Error(exp, "Can't Confirm email. User Id Hash = {0}", uh); redirectUri = new Uri(_bingOffersBaseUri, AuthUserInvalidPage); } } return(new RedirectResult(redirectUri.ToString())); }
/// <summary> /// Create an appropriate redirect uri for unauthenticated user account link confirm request /// </summary> /// <param name="uh">Hash of User Id</param> /// <param name="activationToken">User's Account activation token</param> /// <param name="result">The confirm entity result</param> /// <returns>Redirect uri</returns> private Uri HandleUnauthAlinkConfirmed(string uh, int activationToken, ConfirmEntityResult result) { Uri redirectUri = null; User user = _usersDal.GetUserByUserId(result.UserId.Value); if (user != null) { //Check if the user's account is already linked and return the appropriate authentication provider info. if (!string.IsNullOrEmpty(user.MsId)) { redirectUri = user.MsId.IndexOf(FbIdPattern, StringComparison.OrdinalIgnoreCase) != -1 ? new Uri(_bingOffersBaseUri, string.Format(UnauthAlinkConfirmAccountLinkedPage, Facebook)) : new Uri(_bingOffersBaseUri, string.Format(UnauthAlinkConfirmAccountLinkedPage, Microsoft)); } else { redirectUri = new Uri(_bingOffersBaseUri, string.Format(UnauthAlinkConfirmAccountNotLinkedPage, uh, activationToken)); } } return(redirectUri); }