public IHttpActionResult ChangeEmail(ChangeEmailBindingModel model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var tokenObj = new ParsedTokenHelper().GetParsedToken(Request.Properties); var user = UserManager.FindById(tokenObj.UserId); if (user != null && user.Email == model.NewEmail) { return(BadRequest("Current email is equal to entered.")); } if (UserManager.FindByEmail(model.NewEmail) != null) { return(BadRequest("User with specified email is already registered.")); } var baseUrl = String.Format("{0}://{1}", Request.RequestUri.Scheme, Request.RequestUri.Authority); _iAuthenticationService.ChangeEmail(tokenObj.UserId, model.NewEmail, baseUrl); return(Ok()); } catch (BankClientException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task <IHttpActionResult> ChangeEmail(ChangeEmailBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var thisUser = await UserManager.FindByIdAsync(Int64.Parse(User.Identity.GetUserId())); thisUser.Email = model.Email; await UserManager.UpdateAsync(thisUser); return(Ok()); }
public async Task <HttpResponseMessage> ChangeEmail(ChangeEmailBindingModel model, string userNameId) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var result = await myManager.ChangeEmail(model.Email, userNameId); if (result == null) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "bad email or email doesnt exists")); } return(Request.CreateResponse(HttpStatusCode.OK, "Email changed successfully")); }
// POST api/Account/ChangeEmail public async Task <IHttpActionResult> ChangeEmail(ChangeEmailBindingModel model) { // Get the user var currentUser = await UserManager.FindByIdAsync(this.GetCurrentUserId().Value); var result = await UserManager.SetEmailAsync(currentUser.Id, model.Email, model.ClientAppUrl); var errorResult = GetErrorResult(result); if (errorResult != null) { return(errorResult); } return(Ok(currentUser)); }
// POST api/Account/ChangeEmail public async Task<IHttpActionResult> ChangeEmail(ChangeEmailBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } // Get the user var currentUser = await UserManager.FindByIdAsync(this.GetCurrentUserId().Value); var result = await UserManager.SetEmailAsync(currentUser.Id, model.Email); var errorResult = GetErrorResult(result); if (errorResult != null) { return errorResult; } return Ok(currentUser); }