private void SetCompanies(SignInModel model)
 {
     model.Companies = from c in SagradaIdentityService.GetCompanies()
                       select new SelectListItem()
                       {
                           Value = c.Item1.ToString(),
                           Text = c.Item2
                       };
 }
 private void SetLanguage(SignInModel model)
 {
     model.Languages = from c in SagradaIdentityService.GetLanguages()
                       select new SelectListItem()
                       {
                           Value = c.Name,
                           Text = c.DisplayName
                       };
 }
コード例 #3
0
        // shows the signin screen
        public virtual ActionResult SignIn(string returnUrl, bool mobile=false)
        {
            // you can call AuthenticationHelper.GetRelyingPartyDetailsFromReturnUrl to get more information about the requested relying party

            var vm = new SignInModel()
            {
                ReturnUrl = returnUrl,
                ShowClientCertificateLink = ConfigurationRepository.Global.EnableClientCertificateAuthentication
            };
            if (mobile) vm.IsSigninRequest = true;
            return View(vm);
        }
コード例 #4
0
        public ActionResult SignIn(SignInModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (UserRepository.ValidateUser(model.UserName, model.Password))
                {
                    return SetPrincipalAndRedirect(model.UserName, AuthenticationMethods.Password, returnUrl, model.EnableSSO, ConfigurationRepository.Configuration.SsoCookieLifetime);
                }
            }

            ModelState.AddModelError("", "Incorrect credentials or no authorization.");

            ViewBag.ShowClientCertificateLink = ConfigurationRepository.Configuration.EnableClientCertificates;
            return View(model);
        }
コード例 #5
0
        public ActionResult SignIn(SignInModel model)
        {
            if (ModelState.IsValid)
            {
                if (UserRepository.ValidateUser(model.UserName, model.Password))
                {
                    // establishes a principal, set the session cookie and redirects
                    // you can also pass additional claims to signin, which will be embedded in the session token

                    return SignIn(
                        model.UserName,
                        AuthenticationMethods.Password,
                        model.ReturnUrl,
                        model.EnableSSO,
                        ConfigurationRepository.Global.SsoCookieLifetime);
                }
                ModelState.AddModelError("", Resources.AccountController.IncorrectCredentialsNoAuthorization);
            }

            model.ShowClientCertificateLink = ConfigurationRepository.Global.EnableClientCertificateAuthentication;
            return View(model);
        }
        public ActionResult SignIn(SignInModel model)
        {
            SetCompanies(model);
            SetLanguage(model);
            model.ShowClientCertificateLink = ConfigurationRepository.Global.EnableClientCertificateAuthentication;

            if (model.IsPreAutenticated || ModelState.IsValid)
            {
                if (model.IsPreAutenticated)
                {
                    //step 2
                    return SignIn(
                        model.UserName,
                        AuthenticationMethods.Password,
                        model.ReturnUrl,
                        model.EnableSSO,
                        ConfigurationRepository.Global.SsoCookieLifetime
                        , new[]
                        {
                            new Claim(Sagrada.IdentityServer.ClaimTypes.Language,model.Language.Value),
                            new Claim(Sagrada.IdentityServer.ClaimTypes.Company,model.Company.Value),
                            new Claim(Sagrada.IdentityServer.ClaimTypes.Profile,model.Profile.Value)
                        });
                }
                else
                {
                    //step 1 selezione profilo e company
                    if (UserRepository.ValidateUser(model.UserName, model.Password))
                    {

                        model.Profiles = from c in SagradaIdentityService.GetProfiles(model.UserName)
                                         select new SelectListItem()
                                         {
                                             Value = c.Item1.ToString(),
                                             Text = c.Item2
                                         };
                        if (model.Profiles.Count() == 0)
                        {
                            ModelState.AddModelError("", Resources.AccountController.IncorrectCredentialsNoProfile);
                            return View(model);
                        }

                        model.IsPreAutenticated = true;
                        SetCompanies(model);
                        SetLanguage(model);

                        if (model.Profiles.Count() == 1 && model.Companies.Count() == 1)
                        {
                            //step 2
                            return SignIn(
                                model.UserName,
                                AuthenticationMethods.Password,
                                model.ReturnUrl,
                                model.EnableSSO,
                                ConfigurationRepository.Global.SsoCookieLifetime
                                , new[]
                                    {
                                        new Claim(Sagrada.IdentityServer.ClaimTypes.Language,model.Language.Value),
                                        new Claim(Sagrada.IdentityServer.ClaimTypes.Company,model.Companies.First().Value),
                                        new Claim(Sagrada.IdentityServer.ClaimTypes.Profile,model.Profiles.First().Value)
                                    });
                        }

                        return View(model);
                    }


                    //return SignIn(
                    //    model.UserName,
                    //    AuthenticationMethods.Password,
                    //    model.ReturnUrl,
                    //    model.EnableSSO,
                    //    ConfigurationRepository.Global.SsoCookieLifetime);



                    //new[] { c ,c1});
                }
            }

            ModelState.AddModelError("", Resources.AccountController.IncorrectCredentialsNoAuthorization);
            return View(model);
        }