예제 #1
0
        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();
            }
예제 #2
0
        public ActionResult ForgotPassword(string email)
        {
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
            var user = manager.FindByEmail(email);
            CreateTokenProvider(manager, PASSWORD_RESET);

            var code = manager.GeneratePasswordResetToken(user.Id);
            var callbackUrl = Url.Action("ResetPassword", "Account",
                                         new { userId = user.Id, code = code },
                                         protocol: Request.Url.Scheme);
            string link = "Please reset your password by clicking <a href=\""
                                     + callbackUrl + "\">here</a>";


            MailHelper mailer = new MailHelper();
            string response = mailer.EmailFromArvixe(
                                       new RegisteredUser(email, PASSWORD_RESET, link));
            if (response != "Failure sending mail.")
            {
                ViewBag.Success = response;
            }
            else {
                ViewBag.Failure = response;
            }

            return View();
        }