public async Task <IHttpActionResult> Post(AccountModelBinding createUserModel) { var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, JoinDate = DateTime.Now.Date, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } var code = await AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); string site; #if DEBUG site = Constants.Site; #else site = String.Format("https://{0}.azurewebsites.net/", Environment.ExpandEnvironmentVariables("%WEBSITE_SITE_NAME%") .ToLower()); #endif var callbackUrl = site + $"account/confirmemail?userId={Uri.EscapeDataString(user.Id)}&code={Uri.EscapeDataString(code)}"; var subject = "Welcome to Smalldebts!"; var plainTextContent = "Please confirm your account by clicking this link:" + callbackUrl; var htmlContent = "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"; var emailSent = _mailProvider.SendEmailAsync( new Email() { Address = "*****@*****.**", Name = "Smalldebts team" }, "Welcome to Smalldebts!", plainTextContent, htmlContent, new Email() { Address = user.Email, Name = user.UserName }); return(Created(callbackUrl, TheModelFactory.Create(user))); }
public async Task <SimpleUser> RegisterUser(string email, string username, string password, string passwordConfirmation) { var m = new AccountModelBinding() { Email = email, Username = username, Password = password, ConfirmPassword = passwordConfirmation }; try { return(await client.InvokeApiAsync <AccountModelBinding, SimpleUser>("accounts", m)); } catch (MobileServiceInvalidOperationException exception) { if (exception.Response.StatusCode == HttpStatusCode.BadRequest) { /* If you have the latest framework */ string content = await exception.Response.Content.ReadAsStringAsync(); if (content.Contains("is already taken.")) { throw new AccountAlreadyTakenException(exception); } if (content.Contains("least 6 characters")) { throw new PasswordTooShortException(exception); } else { throw; } } else { throw; } } }