Exemple #1
0
        public ActionResult ForgotPassword([FromBody] ForgotPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(model));
            }

            var user = _userManager.FindByEmailAsync(model.Email).Result;

            if (user == null || !(_userManager.IsEmailConfirmedAsync(user).Result))
            {
                return(NotFound());
            }

            var code = _userManager.GeneratePasswordResetTokenAsync(user);

            var oMailModel = new MailModel
            {
                To      = model.Email,
                Subject = "Forgot Password",
                Body    =
                    "<table><tr>Hi  " + user.Email +
                    ",</tr><tr><br/><br/>Please reset your password by clicking <a href = 'https://" + Request.Scheme + "/Account/ResetPassword?userid=" + user.Id + "&code=" + code + "'> here</a>.<br/><br/><br/>Registration Team</table>"
            };

            Utility.SendMail(oMailModel);
            return(Json("success"));
        }
Exemple #2
0
        public async Task <ActionResult> Register([FromBody] RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(model));
            }

            var user = new ApplicationUser
            {
                UserName    = model.UserName,
                Email       = model.Email,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                CreatedDate = DateTime.Now.ToUniversalTime(),
            };

            var result = await _userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(Json("Failed"));
            }

            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var callbackUrl = Url.Action("VerifyEmail", "Account", new { userId = user.Id, code },
                                         Request.Scheme);
            var oMailModel = new MailModel
            {
                To      = model.Email,
                Subject = "Confirm your account",
                Body    = "Hi " + model.UserName +
                          "<br/><br/> Your registration process is almost complete, all you need to do is click on the confirmation link below to finish activation.<br/>Please confirm your account by clicking <a href=\"" + callbackUrl + ">here </a>.<br/><br/>Regards,<br/>Registration Team"
            };

            Utility.SendMail(oMailModel);
            await _userManager.AddToRoleAsync(user, "User");

            ViewBag.Message = "Success";
            return(Json("success"));
        }