Ejemplo n.º 1
0
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if(ModelState.IsValid)
            {
                Tuple<KoalaBlogIdentityObject, SignInStatus, string> result = await Services.SecurityClient.SignInAsync(model.UserName, model.Password, model.RememberMe);

                var identityObj = result.Item1;
                var signInStatus = result.Item2;
                var accessToken = result.Item3;

                switch (signInStatus)
                {
                    case SignInStatus.Succeeded:
                        KoalaBlogSecurityManager.SetAuthCookie(accessToken);
                        KoalaBlogIdentity identity = new KoalaBlogIdentity(identityObj);
                        KoalaBlogPrincipal principal = new KoalaBlogPrincipal(identity);
                        System.Threading.Thread.CurrentPrincipal = principal;
                        return RedirectToLocal(returnUrl);

                    case SignInStatus.NotYetEmailConfirmed:
                        ConfirmEmailViewModel cevModel = new ConfirmEmailViewModel() { UserID = identityObj.UserID, Email = identityObj.Email, IsEmailConfirmed = false };
                        return View("ConfirmEmail", cevModel);

                    case SignInStatus.LockedOut:
                        return View("LockedOut");

                    case SignInStatus.Failure:
                        AddErrors("账号密码错误");
                        break;
                }
            }
            return View(model);
        }
Ejemplo n.º 2
0
 public async Task<ActionResult> ResendRegisterEmailConfirmation(ConfirmEmailViewModel model)
 {
     if(!ModelState.IsValid)
     {
         ViewBag.ErrorMsg = "重发邮件失败";
         return View("Error");
     }
     else
     {
         await SendEmailConfirmationTokenAsync(model.UserID, model.Email, "Confirm your account.", EmailConfirmationType.Register);
         return View("ConfirmEmail", model);
     }
 }
Ejemplo n.º 3
0
        public async Task<ActionResult> ConfirmEmail(string email, string code)
        {
            if(email == null || code == null)
            {
                ViewBag.ErrorMsg = "验证邮件失败,请重新验证";
                return View("Error");
            }

            bool isEmailConfirmed = await Services.SecurityClient.ConfirmEmailAsync(email, code);

            ConfirmEmailViewModel cevModel = new ConfirmEmailViewModel() { Email = email, IsEmailConfirmed = isEmailConfirmed };

            return View(cevModel);
        }