public AuthUserResponseModel Create(AuthUser appUser) { return new AuthUserResponseModel { Url = _urlHelper.Link("GetUserById", new { id = appUser.Id }), Id = appUser.Id, Domain = appUser.Domain, UserName = appUser.UserName, DisplayName = appUser.DisplayName, Roles = _authUserManager.GetRolesAsync(appUser.Id).Result, Claims = _authUserManager.GetClaimsAsync(appUser.Id).Result }; }
public async Task<IHttpActionResult> CreateAuthUser(AuthUserBindingModel newUser) { if(!ModelState.IsValid) { return BadRequest(ModelState); } var user = new AuthUser() { UserName = newUser.UserName, Email = newUser.Email, Domain = newUser.Domain }; //IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, newUser.Password); IdentityResult addUserResult = await this.AuthUserManager.CreateAsync(user, newUser.Password); if (!addUserResult.Succeeded) { return GetErrorResult(addUserResult); } try { string code = await this.AuthUserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code })); await this.AuthUserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); } catch (Exception ex) { Console.WriteLine(ex.Message); } Uri locationHeader = new Uri(Url.Link("GetAuthUserById", new { id = user.Id })); return Created(locationHeader, AuthModelFactory.Create(user)); }