当前位置: 首页>>代码示例>>C#>>正文


C# UserManager.GenerateEmailConfirmationToken方法代码示例

本文整理汇总了C#中UserManager.GenerateEmailConfirmationToken方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.GenerateEmailConfirmationToken方法的具体用法?C# UserManager.GenerateEmailConfirmationToken怎么用?C# UserManager.GenerateEmailConfirmationToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserManager的用法示例。


在下文中一共展示了UserManager.GenerateEmailConfirmationToken方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Register

            public ActionResult Register(RegisteredUser newUser)
            {

                var userStore = new UserStore<IdentityUser>();
                UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
                {
                    UserLockoutEnabledByDefault = true,
                    DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
                    MaxFailedAccessAttemptsBeforeLockout = 3
                };
            var identityUser = new IdentityUser()
                {
                    UserName = newUser.UserName,
                    Email = newUser.Email
                };
                IdentityResult result = manager.Create(identityUser, newUser.Password);

                if (result.Succeeded)
                {
                    CreateTokenProvider(manager, EMAIL_CONFIRMATION);

                    var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
                    var callbackUrl = Url.Action("ConfirmEmail", "Home",
                                                    new { userId = identityUser.Id, code = code },
                                                        protocol: Request.Url.Scheme);

                    string email = "Please confirm your account by clicking this link: <a href=\""
                                    + callbackUrl + "\">Confirm Registration</a>";
                    ViewBag.FakeConfirmation = email;
            }
                return View();
            }
开发者ID:JayOwl,项目名称:Bruteforce-Attack-Prevention,代码行数:32,代码来源:HomeController.cs

示例2: Register

        public ActionResult Register(RegisteredUser newUser)
        {
            // TAKING THE WRONG MODEL AS INPUT???
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
            {
                UserLockoutEnabledByDefault = true,
                DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
                MaxFailedAccessAttemptsBeforeLockout = 3
            };

            var identityUser = new IdentityUser()
            {
                UserName = newUser.UserName,
                Email = newUser.Email
            };

            // this threw an error, but it also worked so what gives???
            IdentityResult result = manager.Create(identityUser, newUser.Password);
            if (result.Succeeded)
            {
                CreateTokenProvider(manager, EMAIL_CONFIRMATION);
                // identityUser.Id use this to create an entry in our accounts table 
                var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
                var callbackUrl = Url.Action("VerifiedEmail", "Accounts",
                                                new { userId = identityUser.Id, code = code },
                                                    protocol: Request.Url.Scheme);

                string email = "Please confirm your account by clicking this link: <a href=\""
                                + callbackUrl + "\">Confirm Registration</a>";


                ViewBag.FakeConfirmation = email;
                UserAccountVMRepo uaRepo = new UserAccountVMRepo();
                uaRepo.CreateAccount(newUser.FirstName, newUser.LastName, identityUser.Id);

                // CREATE WITH CONSUMER ROLE BY DEFAULT
                SecurityEntities context = new SecurityEntities();
                AspNetUser user = context.AspNetUsers
                                 .Where(u => u.UserName == newUser.UserName).FirstOrDefault();
                AspNetRole role = context.AspNetRoles
                                 .Where(r => r.Name == "consumer").FirstOrDefault();

                user.AspNetRoles.Add(role);
                context.SaveChanges();

                MailHelper mailer = new MailHelper();
                string response = mailer.EmailFromArvixe(
                                           new RegisteredUser(newUser.Email, newUser.Subject = "Confirm Email", newUser.Body = email));

                ViewBag.Response = response;
                return View("ConfirmEmail");
            }
            return View();
        }
开发者ID:kpawa,项目名称:Jarvis,代码行数:55,代码来源:AccountsController.cs

示例3: sendConfirmationEmail

        private void sendConfirmationEmail(User user)
        {
            var provider = new MachineKeyProtectionProvider();
            UserManager<User, int> um = new UserManager<User, int>(ur);
            um.UserTokenProvider = new DataProtectorTokenProvider<User, int>(provider.Create("EmailConfirmation"));
            um.EmailService = new EmailService();
            TempData.Add("confirmEmail", "Le hemos enviado un correo electrónico para confirmar su cuenta, comprube la carpeta spam");

            if (Url != null)
            {
                var code = um.GenerateEmailConfirmationToken(user.U_id);
           
                var callbackUrl = Url.Action(
                "ConfirmEmail", "Home",
                new { userId = user.Id, code = code },
                protocol: "http");
                um.SendEmail(user.Id,
                           "Confirma tu correo",
                           "Por favor confirme su correo haciendo click en este <a href=\""
                                                           + callbackUrl + "\">link</a>");
            }
        }
开发者ID:AgoraUS1516G2,项目名称:G14-Anonimizado-,代码行数:22,代码来源:HomeController.cs

示例4: Register

        public ActionResult Register(RegisteredUser newUser)
        {
            CaptchaHelper captchaHelper = new CaptchaHelper();
            string captchaResponse = captchaHelper.CheckRecaptcha();
            if (captchaResponse != "Valid")
            {
                ViewBag.ErrorResponse = "The captcha must be valid";
                return View();

            }

            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
            {
                UserLockoutEnabledByDefault = true,
                DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
                MaxFailedAccessAttemptsBeforeLockout = 3
            };

            var identityUser = new IdentityUser()
            {
                UserName = newUser.UserName,
                Email = newUser.Email
            };
            IdentityResult result = manager.Create(identityUser, newUser.Password);

            if (result.Succeeded)
            {

                if (newUser.UserRole.Equals("Buyer") || newUser.UserRole.Equals("Farm"))
                {
                    //Taking the username on the account successful creation and applying it to the
                    //Farm database to create a Farm table with that username under the 'farmName' field.
                    AccountRepo accountRepo = new AccountRepo();
                    accountRepo.InitializeUserAccount(newUser);
                }

                var authenticationManager
                                  = HttpContext.Request.GetOwinContext().Authentication;
                var userIdentity = manager.CreateIdentity(identityUser,
                                           DefaultAuthenticationTypes.ApplicationCookie);
                authenticationManager.SignIn(new AuthenticationProperties() { },
                                             userIdentity);
                string testVariable = newUser.UserRole;
                AddUserToRole(newUser.UserName, newUser.UserRole);

                CreateTokenProvider(manager, EMAIL_CONFIRMATION);

                var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
                var callbackUrl = Url.Action("ConfirmEmail", "Home",
                                                new { userId = identityUser.Id, code = code },
                                                    protocol: Request.Url.Scheme);

                string emailMessage = "Please confirm your account by clicking this link: <a href=\""
                                    + callbackUrl + "\">Confirm Registration</a>";

                string response = new MailHelper().EmailFromArvixe(new ViewModels.Message(newUser.Email, emailMessage));

                ViewBag.ConfirmationResponse = response;
                TempData["ConfirmationResponse"] = "You have successfully registered for an account. Please verify your account by clicking on the link sent to you in your e-mail.";
                return RedirectToAction("Login");
            }
            ViewBag.ErrorResponse = "There was an error with the input provided";
            return View();
        }
开发者ID:andrewstec,项目名称:phase2_lastday,代码行数:65,代码来源:HomeController.cs

示例5: Register

        public ActionResult Register(RegisteredUser newUser)
        {
            //when user registers in checks model requirements to ensure valid input
            if (ModelState.IsValid)
            {
                CaptchaHelper captchaHelper = new CaptchaHelper();
                string captchaResponse = captchaHelper.CheckRecaptcha();
                ViewBag.CaptchaResponse = captchaResponse;

                // add user to database, lock account until email confirmation
                var userStore = new UserStore<IdentityUser>();
                UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
                {
                    //set account to lock after consecutive failed login attempts
                    UserLockoutEnabledByDefault = true,
                    DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
                    MaxFailedAccessAttemptsBeforeLockout = 3
                };

                var identityUser = new IdentityUser()
                {
                    UserName = newUser.UserName,
                    Email = newUser.Email
                };
                IdentityResult result = manager.Create(identityUser, newUser.Password);

                if (result.Succeeded)
                {
                    samUserRegEntities context = new samUserRegEntities();
                    AspNetUser user = context.AspNetUsers
                        .Where(u => u.UserName == newUser.UserName).FirstOrDefault();
                    AspNetRole role = context.AspNetRoles
                        .Where(r => r.Name == "registered").FirstOrDefault();

                    user.AspNetRoles.Add(role);
                    context.SaveChanges();

                    //creates token to be passed to mail helper to allow email confirmation
                    CreateToken ct = new CreateToken();
                    CreateTokenProvider(manager, EMAIL_CONFIRMATION);

                    var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
                    var callbackUrl = Url.Action("ConfirmEmail", "Home",
                                                    new { userId = identityUser.Id, code = code },
                                                        protocol: Request.Url.Scheme);
                    //send callbackURL to email helper
                    MailHelper mailer = new MailHelper();
                    string email = "Please confirm your account by clicking this link: <a href=\""
                                    + callbackUrl + "\">Confirm Registration</a>";
                    string subject = "Please confirm your email";
                    //try
                    //{
                        mailer.EmailFromArvixe(email, identityUser.Email, subject);
                        ViewBag.FakeConfirmation =
                            "An account confirmation has been sent to your email, please confirm before attempting to login";
                    //}
                    //catch (System.Exception ex)
                    //{
                    //    ViewBag.FakeConfirmation = ex.Message;
                    //}

                }
            }
            return View();
        }
开发者ID:snew1,项目名称:sampleAccountCreation,代码行数:65,代码来源:HomeController.cs

示例6: Register

        public ActionResult Register(RegisteredUser newUser)
        {
            CaptchaHelper captchaHelper = new CaptchaHelper();
            string captchaResponse = captchaHelper.CheckRecaptcha();
            ViewBag.CaptchaResponse = captchaResponse;
            TempData["captcha"] = captchaResponse;
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
            {
                UserLockoutEnabledByDefault = true,
                DefaultAccountLockoutTimeSpan = new System.TimeSpan(0, 10, 0),
                MaxFailedAccessAttemptsBeforeLockout = 3
            };
            var identityUser = new IdentityUser()
            {
                UserName = newUser.UserName,
                Email = newUser.Email
            };
            IdentityResult result = manager.Create(identityUser, newUser.Password);

            if (result.Succeeded && captchaResponse == VALID_CAPTCHA)
            {
                CreateTokenProvider(manager, EMAIL_CONFIRMATION);

                var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
                var callbackUrl = Url.Action("ConfirmEmail", "Home",
                                                new { userId = identityUser.Id, code = code },
                                                    protocol: Request.Url.Scheme);

                string email = "<h3>Please confirm your account by clicking this link:</h3><a href=\""
                                + callbackUrl + "\">Confirm Registration</a>";
                MailHelper mailer = new MailHelper();
                string response = mailer.EmailFromArvixe(newUser, email);
                ViewBag.Response = response;
                TempData["response"] = response;
            }
                return RedirectToAction("Index","Home");
        }
开发者ID:Mariocf93,项目名称:WebSecurity,代码行数:38,代码来源:HomeController.cs

示例7: Register

        public ActionResult Register(RegisteredUser newUser) {
            var userStore         = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore)
            {
                UserLockoutEnabledByDefault = true,
                DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
                MaxFailedAccessAttemptsBeforeLockout = 3
            };

            var identityUser      = new IdentityUser() { UserName = newUser.UserName, 
                                                         Email    = newUser.Email };
            IdentityResult result = manager.Create(identityUser, newUser.Password);

            if (result.Succeeded) {
                CreateTokenProvider(manager, EMAIL_CONFIRMATION);

                var code = manager.GenerateEmailConfirmationToken(identityUser.Id);
                var callbackUrl = Url.Action("ConfirmEmail", "Account",
                                                new { userId = identityUser.Id, code = code },
                                                    protocol: Request.Url.Scheme);

                string link = "Please confirm your account by clicking this link: <a href=\""
                                + callbackUrl + "\">Confirm Registration</a>";
                newUser.ConfirmLink = link;                
                // sending Email Start
                MailHelper mailer = new MailHelper();
                string response = mailer.EmailFromArvixe(
                                           new RegisteredUser(newUser.Email, newUser.UserName,newUser.ConfirmLink ));
                
                if (response != "Failure sending mail."){
                    ViewBag.Success = response;
                }else{
                    ViewBag.Failure = response;
                }

                // sending Email End
            }
            return View();
            }
开发者ID:cj8397,项目名称:2hourVer2,代码行数:39,代码来源:AccountController.cs

示例8: CompleteInfo

        public ActionResult CompleteInfo(ClientInterestViewModel client)
        {
            repo.saveClientInfo(client);

            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);

            CreateTokenProvider(manager, EMAIL_CONFIRMATION);

              var user = manager.FindByName(client.userName);
            var code = manager.GenerateEmailConfirmationToken(user.Id);

            var callbackUrl = Url.Action("ConfirmEmail", "Home",
                                            new { userId = user.Id, code = code },
                                                protocol: Request.Url.Scheme);

            string emailBody = "Please confirm your account by clicking this link: <a href=\""
                            + callbackUrl + "\">Confirm Registration</a>";

            MailHelper mailer = new MailHelper();

            string Subject = "Confirm registration";
            string response = mailer.EmailFromArvixe(
                                       new Message(client.email, Subject, emailBody));

            if (response.IndexOf("Success") >= 0)
            {
             //   ViewBag.Message = "A confirm email has been sent. Please check your email.";
                TempData["Message"] = "A confirm email has been sent. Please check your email.";
                return RedirectToAction("CompleteRegistration");
            }
            else {
                ViewBag.Message = response;
            }

            ClientInterestViewModel newClient = repo.getClientInterest(client.userId);
            return View(newClient);
               // return RedirectToAction("UserProfile", new { userName = client.userName});
        }
开发者ID:rachelyu0102,项目名称:dating-project-ssd,代码行数:39,代码来源:HomeController.cs


注:本文中的UserManager.GenerateEmailConfirmationToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。