Esempio n. 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // 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);
                    try
                    {
                        ContactMessageController.SendEmailUsingBuildInCredentials("Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>", model.Email, "Link aktywacyjny. Potwierdzenie rejestracji.");
                    }
                    catch
                    {
                        TempData["IsSuccess"]       = "false";
                        TempData["ViewBag.Message"] = "Coś poszło nie tak. Spróbuj ponownie lub skontaktuj się z administratorem strony. ;(";
                        return(View(model));
                    }
                    TempData["IsSuccess"]       = "true";
                    TempData["ViewBag.Message"] = "Wiadomość z linkiem aktywacyjnym wysłano na Twoją pocztę :)";
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Send(Email model)
        {
            if (!ModelState.IsValid)
            {
                TempData["IsSuccess"]       = "false";
                TempData["ViewBag.Message"] = "Przed wysłaniem poprawnie wypełnij pole z adresem email.";
                return(RedirectToAction("Index", "Home", model));
            }

            var numList = new List <int>();

            foreach (var c in model.EmailAddress.ToArray())
            {
                numList.Add((int)c);
            }
            var code = Crypto.Encrypt(model.EmailAddress, key_encrypt);

            try
            {
                var callbackUrl = Url.Action("Validate", "Calculator", new { emailAddress = model.EmailAddress, code = code }, protocol: Request.Url.Scheme);

                var mailTo         = model.EmailAddress;
                var messageContent = "Twój link z jednodniowym dostępem do kalkulatora zysków: " + callbackUrl;
                var mailSubject    = "Twój jednodniowy klucz dostępu do kalkulatora zysków.";

                ContactMessageController.SendEmailUsingBuildInCredentials(messageContent, mailTo, mailSubject);
            }
            catch (Exception)
            {
                TempData["IsSuccess"]       = "false";
                TempData["ViewBag.Message"] = "Wystąpił błąd podczas wysyłania wiadomości :(";
                return(RedirectToAction("Index", "Home"));
            }

            TempData["IsSuccess"]       = "true";
            TempData["ViewBag.Message"] = "Wiadomość z linkiem dostępu do kalkulatora wysłana pomyślnie :)";
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 3
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByEmailAsync(model.Email);

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    TempData["IsSuccess"]       = "false";
                    TempData["ViewBag.Message"] = "Nie odnaleziono użytkownika o wskazanym adresie mailowym ;(";
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View(model));
                }

                // For more information on how to enable account confirmation and password reset please visit http://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);
                try
                {
                    ContactMessageController.SendEmailUsingBuildInCredentials("Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>", model.Email, "Reset Password");
                }
                catch
                {
                    TempData["IsSuccess"]       = "false";
                    TempData["ViewBag.Message"] = "Coś poszło nie tak. Skontaktuj się z administratorem strony. ;(";
                    return(View(model));
                }
                TempData["IsSuccess"]       = "true";
                TempData["ViewBag.Message"] = "Wiadomość z linkiem resetującym wysłano na Twoją pocztę :)";
                return(RedirectToAction("Index", "Home"));
            }

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