예제 #1
0
        public virtual async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Member user;
                user = new User();

                Mapper.Map(model, user);
                var result = await MemberManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // 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
                    var code = await MemberManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = GetCallbackUrl(Actions.ConfirmEmail(user.Id, code));
                    await MemberManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    ViewBag.Message = I18N.T("EmailConfirmation",
                                             "Check your email and confirm your account. You must be confirmed before you can log in.");

                    return(View(MVC.Shared.Views.Info));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #2
0
        public virtual async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await MemberManager.FindByEmailAsync(model.Email);

            if (user != null && !await MemberManager.IsEmailConfirmedAsync(user.Id))
            {
                ModelState.AddModelError("",
                                         I18N.T("Error:EmailNotConfirmed", "You must have a confirmed email to log in."));

                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View(MVC.Shared.Views.Lockout));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction(Actions.SendCode(returnUrl, model.RememberMe)));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
예제 #3
0
        public virtual async Task <ActionResult> ResendConfirmationEmail(string Email)
        {
            var user = await MemberManager.FindByNameAsync(Email);

            //check if user exists
            if (user == null)
            {
                ModelState.AddModelError("Email", "No user could be found with that email address.");
            }
            else
            {
                var code = await MemberManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var callbackUrl = GetCallbackUrl(Actions.ConfirmEmail(user.Id, code));
                await MemberManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                ViewBag.Message = I18N.T("EmailConfirmation",
                                         "Check your email and confirm your account. You must be confirmed before you can log in.");

                return(View());
            }
            return(View());
        }