public async Task<IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } UserProfile user = new UserProfile { UserName = model.UserName, Email = model.Email, EmailConfirmed = false }; IdentityResult identityResult = await UserManager.CreateAsync(user, model.Password); IHttpActionResult createResult = GetErrorResult(identityResult); if (createResult != null) { return createResult; } UserProfile justCreatedUser = await UserManager.FindByNameAsync(model.UserName); IdentityResult roleResult = await UserManager.AddToRoleAsync(justCreatedUser.Id, "User"); IHttpActionResult addRoleResult = GetErrorResult(roleResult); if (addRoleResult != null) { return addRoleResult; } string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Link("ConfirmEmail", new { userId = user.Id, code = code }); var notification = new AccountNotificationModel { Code = code, Url = callbackUrl, UserId = justCreatedUser.Id, Email = justCreatedUser.Email, DisplayName = justCreatedUser.UserName }; string body = ViewRenderer.RenderView("~/Views/Mailer/NewAccount.cshtml", notification); await UserManager.SendEmailAsync(user.Id, "DurandalAuth account confirmation", body); return Ok(); }
public async Task<IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } UserProfile user = new UserProfile { UserName = model.UserName, Email = model.Email }; IdentityResult identityResult = await UserManager.CreateAsync(user, model.Password); IHttpActionResult createResult = GetErrorResult(identityResult); if (createResult != null) { return createResult; } UserProfile justCreatedUser = await UserManager.FindByNameAsync(model.UserName); IdentityResult roleResult = await UserManager.AddToRoleAsync(justCreatedUser.Id, "User"); IHttpActionResult addRoleResult = GetErrorResult(roleResult); if (addRoleResult != null) { return addRoleResult; } return Ok(); }
public async Task<IHttpActionResult> Register(RegisterBindingModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var user = new UserProfile { UserName = model.UserName, Email = model.Email, EmailConfirmed = false }; var identityResult = await this.UserManager.CreateAsync(user, model.Password); var createResult = this.GetErrorResult(identityResult); if (createResult != null) { return createResult; } var justCreatedUser = await this.UserManager.FindByNameAsync(model.UserName); /*var profile = new Profile { UserId = justCreatedUser.Id };*/ var roleResult = await this.UserManager.AddToRoleAsync(justCreatedUser.Id, "User"); var addRoleResult = this.GetErrorResult(roleResult); if (addRoleResult != null) { return addRoleResult; } var code = await this.UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = this.Url.Link("ConfirmEmail", new { userId = user.Id, code }); var notification = new AccountNotificationModel { Code = code, Url = callbackUrl, UserId = justCreatedUser.Id, Email = justCreatedUser.Email, DisplayName = justCreatedUser.UserName }; var body = ViewRenderer.RenderView("~/Views/Mailer/NewAccount.cshtml", notification); await this.UserManager.SendEmailAsync(user.Id, "Home Service account confirmation", body); //return this.Created(this.Request.RequestUri + justCreatedUser.Id, profile); return this.Ok(justCreatedUser.Id); }