コード例 #1
0
        //public async Task<ActionResult> Register(RegisterViewModel model)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        var user = new Uzytkownik { UserName = model.Email, Email = model.Email, Imie=model.Imię,Nazwisko=model.Nazwisko };
        //        user.Email = model.Email;
        //        user.EmailConfirmed = false;
        //        var result = await UserManager.CreateAsync(user, model.Password);
        //        if (result.Succeeded)
        //        {

        //            //  Comment the following line to prevent log in until the user is confirmed.
        //            //  await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

        //            string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Aktywuj konto");
        //            // Uncomment to debug locally
        //            // TempData["ViewBagLink"] = callbackUrl;

        //            ViewBag.Message = "Sprawdz swój email i potwierdz konto zanim się zalogujesz!";

        //            return View("Info");
        //            //return RedirectToAction("Index", "Home");
        //        }
        //        AddErrors(result);

        //        #region region

        //        //string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
        //        //var callbackUrl = Url.Action("ConfirmEmail", "Account",
        //        //   new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
        //        //await UserManager.SendEmailAsync(user.Id, "Potwierdz swoje konto",
        //        //   "Aby aktywować konto proszę kliknąć w link: <a href=\"" + callbackUrl + "\">Potwierdz</a>");

        //        ////////    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
        //        ////////    var callbackUrl = Url.Action(
        //        ////////       "ConfirmEmail", "Account",
        //        ////////       new { userId = user.Id, code = code },
        //        ////////       protocol: Request.Url.Scheme);

        //        ////////    await UserManager.SendEmailAsync(user.Id,
        //        ////////       "Confirm your account",
        //        ////////       "Please confirm your account by clicking this link: <a href=\""
        //        ////////                                       + callbackUrl + "\">link</a>");
        //        ////////    // ViewBag.Link = callbackUrl;   // Used only for initial demo.
        //        ////////    return RedirectToAction("Index", "Home");
        //        ////////}
        //        ////////AddErrors(result);

        //        //if (result.Succeeded)
        //        //{
        //        //    UserManager.AddToRole(user.Id, "Uzytkownik");
        //        //    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

        //        //    // 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.GenerateEmailConfirmationTokenAsync(user.Id);
        //        //    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
        //        //    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

        //        //    return RedirectToAction("Index", "Home");
        //        //}
        //        //AddErrors(result);
        //        #endregion
        //    }

        //    // If we got this far, something failed, redisplay form
        //    return View(model);
        //}
        private async Task <string> SendEmailConfirmationTokenAsync(string userID, string subject)
        {
            string code = await UserManager.GenerateEmailConfirmationTokenAsync(userID);

            var callbackUrl = Url.Action("ConfirmEmail", "Account",
                                         new { userId = userID, code = code }, protocol: Request.Url.Scheme);
            await UserManager.SendEmailAsync(userID, subject,
                                             "Aby aktywować konto proszę kliknąć w link: <a href=\"" + callbackUrl + "\">Potwierdz</a>");


            return(callbackUrl);
        }