Ejemplo n.º 1
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            var IPAddress = Server.HtmlEncode(Request.UserHostAddress);

            ViewBag.IPAddress = IPAddress;
            var subject    = "Forgot Email";
            var instigator = "Login System";
            var system     = "Account Controller";

            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                instigator = user.Email;
                await SMTP.SendNewEmail("*****@*****.**", user.Email, "Basically Prepared", "", "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + $"\">{callbackUrl}</a>.<br />You can also copy and paste the link to your URL if your email does not allow you to clink on links.", "PasswordReset");

                await Logger.CreateNewLog($"Password reset request successful for {instigator} on {IPAddress}.", subject, instigator, system);

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            var IPAddress = Server.HtmlEncode(Request.UserHostAddress);

            ViewBag.IPAddress = IPAddress;
            var subject    = "Account Registration";
            var instigator = "Registration System";
            var system     = "Account Controller";

            if (ModelState.IsValid && ReCaptcha.Validate(ConfigurationManager.AppSettings["ReCaptcha:SecretKey"]))
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    instigator = model.Email;
                    await Logger.CreateNewLog($"Successful registration for {model.Email} on IPAddress {IPAddress}", subject, instigator, system);

                    // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    await SMTP.SendNewEmail("*****@*****.**", model.Email, "Basically Prepared", "", "Confirm Account Create", "Please confirm your account by clicking <a href=\"" + callbackUrl + $"\">{callbackUrl}</a>.<br />You can also copy and paste it to your browser if your email does not allow you to click the link.", "NewAccount");

                    ViewBag.RegisteredEmail = model.Email;
                    return(View("RegistrationSuccessful"));
                }
                AddErrors(result);
            }
            await Logger.CreateNewLog($"Failed registration for {model.Email} on IPAddress {IPAddress}", subject, instigator, system);

            ViewBag.RecaptchaLastErrors = ReCaptcha.GetLastErrors(this.HttpContext);

            ViewBag.publicKey = ConfigurationManager.AppSettings["ReCaptcha:SiteKey"];

            // If we got this far, something failed, redisplay form
            return(View(model));
        }