public async Task <IHttpActionResult> RegisterStandard(RegisterStandardModel model) { if (!ModelState.IsValid) { var message = "Internal Server Error. Please try again later."; if (ModelState.Values.FirstOrDefault() != null && ModelState.Values.FirstOrDefault().Errors.FirstOrDefault() != null) { message = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; } return(BadRequest(message)); } if (SvcContainer.UserSvc.IsEmailUsed(model.Email)) { return(BadRequest("Email address already in use")); } if (SvcContainer.UserSvc.IsUserNameUsed(model.UserName)) { return(BadRequest("Username already in use")); } var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); //IdentityResult result = UserManager.Create(user, model.Password); if (!result.Succeeded) { //var message = "Internal Server Error. Please try again later."; return(BadRequest(result.Errors.FirstOrDefault())); } string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); //var callbackUrl = Url.Link("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //string callbackUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + // "/#/account/confirm-email?userId=" + user.Id + "&code=" + code + ""; string callbackUrl = "http://quizzocake.com" + "/#/account/confirm-email?userId=" + user.Id + "&code=" + code + ""; string unsubscribeUrl = "http://quizzocake.com"; await UserManager.SendEmailAsync(user.Id, "Please Confirm Your QuizzOCake Account", ConfirmEmailBody(model, callbackUrl, unsubscribeUrl)); var userModel = SvcContainer.UserSvc.CreateNewStandardUser(user.Id, model.UserName, model.Email, model); return(Ok(userModel)); }
private string ConfirmEmailBody(RegisterStandardModel model, string callbackUrl, string unsubscribeUrl) { var companyName = "<span style='color:#ff6666;'>Quizz</span><span style='color:#3c2d1a;'>O</span><span style='color:#d2691e;'>Cake</span>"; var emailBody = "<div style='font-family:sans-serif; background-color:#f1f1f1; padding:30px;'>" + "<div style='max-width:600px; margin: 0px auto; background-color:#e53d0e; height:52px;'>" + "<div style='max-width:600px;'>" + "<div style='font-weight:700; background-color:white; display:inline-block; margin: 6px 0px 6px 6px; padding:10px 20px;'>" + companyName + "</div>" + "</div>" + "</div>" + "<div style='max-width:600px; margin: 0px auto; background-color:white;'>" + "<div style='padding:20px;'>" + "<div style='color:#5bc0de; font-weight:bolder; font-size:large;'>" + "Welcome to the " + companyName + " learning community, " + model.FirstName + "!" + "</div>" + "<p>To finish setting up your account, please verify your email address(" + model.Email + ") by clicking this button:</p>" + "<div style='width:160px; height:22px; margin:auto; background-color:#f07a18; text-align:center; padding:10px 20px; border-radius:5px;'>" + "<a style='text-decoration:none; font-weight:bold; font-size:18px; color:white;' href=\"" + callbackUrl + "\">Confirm My Email</a>" + "</div>" + "<p>With your " + companyName + " account, you will be able to:</p>" + "<ul>" + "<li>Create and Publish Quizzes, Flashcards, and Reviewer Notes</li>" + "<li>Search For and Take Available Quizzes</li>" + "<li>Register Quizzlings(Children or Dependents), Assign Quizzes, Monitor Their Progress and Activities</li>" + "<li>Open or Enroll in Quizzrooms, Our Virtual Classrooms</li>" + "<li>Connect with Quizzmates</li>" + "<li>And Many More…</li>" + "</ul>" + "<p>If you have any questions, please email us at " + "<a href='mailto:[email protected]?Subject=Question' target='_top'>" + "*****@*****.**" + "</a></p>" + "<p>Cheers,<br/>The " + companyName + " Team</p>" + "<hr style='background-color: lightgray; height: 1px; border: 0;' />" + "<p style='color:gray; font-size:x-small'>" + "You received this email because you registered on quizzocake.com with the email address " + model.Email + "." + "You can manage your notifications by clicking <a href=\"" + unsubscribeUrl + "\">unsubscribe</a>." + "</p>" + "</div>" + "</div>" + "</div>"; return(emailBody); }
public async Task <IHttpActionResult> ForgotPassword([FromBody] ForgotPasswordModel model) { string code; string callbackUrl; string unsubscribeUrl; string messageTitle; string messageBody; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string mainUserId; string subUserId; if (SvcContainer.UserSvc.GetMainUserId(model.EmailOrUserName, out mainUserId, out subUserId) == false) { return(NotFound()); } var mainUser = await UserManager.FindByIdAsync(mainUserId); var subUser = await UserManager.FindByIdAsync(subUserId); if (mainUser == null || subUser == null) { return(BadRequest()); } if (mainUser.EmailConfirmed == false) { code = await UserManager.GenerateEmailConfirmationTokenAsync(mainUser.Id); callbackUrl = "http://quizzocake.com" + "/#/account/confirm-email?userId=" + mainUser.Id + "&code=" + code + ""; //callbackUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + // "/#/account/confirm-email?userId=" + mainUser.Id + "&code=" + code + ""; unsubscribeUrl = "http://quizzocake.com"; var user = Uow.Users.GetAll() .Where(u => u.LocalAuthUserId == mainUser.Id) .Include(u => u.Profile) .FirstOrDefault(); var registeredUser = new RegisterStandardModel { Email = user.Email, FirstName = user.Profile.FirstName }; messageTitle = "Please Confirm Your QuizzOCake Account"; messageBody = ConfirmEmailBody(registeredUser, callbackUrl, unsubscribeUrl); } else { string userName = model.EmailOrUserName.Contains("@") ? mainUser.UserName : model.EmailOrUserName; code = await UserManager.GeneratePasswordResetTokenAsync(subUser.Id); callbackUrl = "http://quizzocake.com" + "/#/account/reset-password?userName="******"&code=" + code + ""; unsubscribeUrl = "http://quizzocake.com"; //callbackUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + // "/#/account/reset-password?userName="******"&code=" + code + ""; messageTitle = "QuizzOCake Password Reset"; messageBody = ForgotPasswordEmailBody(userName, callbackUrl, unsubscribeUrl); } await UserManager.SendEmailAsync(mainUser.Id, messageTitle, messageBody); return(Ok()); }