コード例 #1
0
        public ActionResult Authenticate(UserLogin UserLogin, bool? RememberMe, string ReturnUrl)
        {
            string identifier = UserLogin.Identifier;
            string host = HttpContext.Request.GetSubDomain();
            PermissionEntity<User> parentUser = null;
            if (!String.IsNullOrEmpty(host))
            {
                parentUser = userManagement.Get(x => x.HomePage.Equals(host));
                if (parentUser.EntityFound)
                {
                    if (parentUser.Entity.StateUser == StateUser.Active)
                    {
                        DateTime birthDate;
                        if (!DateTime.TryParse(UserLogin.Password, out birthDate))
                        {
                            ModelState.AddModelError("_FORM", "Invalid Birth Date");
                            return View("BankLogin", UserLogin);
                        }
                        identifier = parentUser.Entity.ID + "/" + UserLogin.Identifier + ":" + birthDate.ToShortDateString();
                    }
                    else
                    {
                        return View("AccountInactive");
                    }
                }
            }

            User user = null;
            ActionResult redirect = null;
            UserAuthenticationStatus? status = null;

            ViewData["Authenticators"] = userAuthenticators;

            try
            {
                status = userAuthentication.Authenticate(UserLogin.AuthenticationType, identifier, ReturnUrl, out user, out redirect);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("_FORM", ex.Message);
                return !String.IsNullOrEmpty(host) ? View("BankLogin", UserLogin) : View("Login");
            }

            switch (status)
            {
                case UserAuthenticationStatus.RequiresRedirect:
                    if (redirect == null)
                    {
                        ModelState.AddModelError("_FORM", "An unknown error has occurred while attempting to redirect for authentication");
                        break;
                    }

                    return redirect;

                case UserAuthenticationStatus.RequiresConfirmation:
                    if (user == null)
                    {
                        ModelState.AddModelError("_FORM", "An unknown error has occurred while attempting to confirm your user account");
                        break;
                    }

                    return RedirectToAction("Confirm", new { ProviderUserKey = user.ProviderUserKey.Value });

                case UserAuthenticationStatus.Failed:
                    ModelState.AddModelError("_FORM", "Authentication has failed");
                    break;

                case UserAuthenticationStatus.Authenticated:
                    if (user == null)
                    {
                        ModelState.AddModelError("_FORM", "An unknown error has occurred while attempting to log you in");
                        break;
                    }

                    formsAuthentication.SignIn(user.LoginName, RememberMe.HasValue ? RememberMe.Value : false);

                    if (!string.IsNullOrEmpty(ReturnUrl))
                    {
                        return Redirect(ReturnUrl);
                    }

                    return !String.IsNullOrEmpty(host)
                        ? RedirectToAction("Dashboard", "Child")
                        : RedirectToAction("Dashboard", "Leader");
            }

            return !String.IsNullOrEmpty(host) ? View("BankLogin", UserLogin) : View("Login");
        }
コード例 #2
0
        public ActionResult Login(string ReturnUrl)
        {
            ViewData["ReturnUrl"] = ReturnUrl;
            ViewData["Authenticators"] = userAuthenticators;

            string host = HttpContext.Request.GetSubDomain();
            if (!String.IsNullOrEmpty(host))
            {
                var parentUser = userManagement.Get(x => x.HomePage.Equals(host));
                if (parentUser.EntityFound)
                {
                    if (parentUser.Entity.StateUser == StateUser.Active)
                    {
                        var UserLogin = new UserLogin
                                        {
                                            Title = parentUser.Entity.Business
                                        };

                        return View("BankLogin", UserLogin);
                    }
                    return View("AccountInactive");
                }
            }

            // default login screen
            return View();
        }