Ejemplo n.º 1
0
 public override Response Authenticate(
     INancyModule nancyModule,
     IUserMapper userMapper,
     IConfiguration configuration,
     IUserRepository userRepositoryNotUsed,
     UserCredentials userCredentialsNotUsed,
     IViewRenderer viewRendererNotUsed,
     IModuleStaticWrappers moduleStaticWrappers)
 {
     try
     {
         var userAndClaims = AuthenticateAndAuthorizeUser(HttpContext.Current.ApplicationInstance.User, configuration);
         var names         = userAndClaims.Item1.Split(',').Reverse().ToArray();
         var userName      = string.Join(" ", names);
         if (names.Length < 2)
         {
             names = new[] { "", userName }
         }
         ;
         var guid = userMapper.AddUser(userName, names[0], names[1], userAndClaims.Item2);
         return(moduleStaticWrappers.LoginAndRedirect(nancyModule, guid, null, ModuleStaticWrappers.DefaultFallbackRedirectUrl));
     }
     catch (Exception ex)
     {
         ex.Log();
         return($"Login from Active Directory Failed<br><br>{ex.Message}<br><br>{ex.InnerException?.Message ?? ""}");
     }
 }
Ejemplo n.º 2
0
 public virtual Response Authenticate(
     INancyModule nancyModule,
     IUserMapper userMapper,
     IConfiguration configuration,
     IUserRepository userRepository,
     UserCredentials userCredentials,
     IViewRenderer viewRenderer,
     IModuleStaticWrappers moduleStaticWrappers)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 3
0
        public FormsAuthenticationModule(
            IUserMapper userMapper,
            IConfiguration configuration,
            IUserRepository userRepository,
            IViewRenderer viewRenderer,
            IModuleStaticWrappers moduleStaticWrappers)
        {
            Get[AuthenticationRedirectUrl.Url] = p => View[AuthenticationRedirectUrl.Url];

            Post[AuthenticationRedirectUrl.Url] = p => userMapper.Authenticate(
                this,
                userMapper,
                configuration,
                userRepository,
                this.Bind <UserCredentials>(),
                viewRenderer,
                moduleStaticWrappers);
        }
Ejemplo n.º 4
0
        public override Response Authenticate(
            INancyModule nancyModule,
            IUserMapper userMapper,
            IConfiguration configuration,
            IUserRepository userRepository,
            UserCredentials userCredentials,
            IViewRenderer viewRenderer,
            IModuleStaticWrappers moduleStaticWrappers)
        {
            var validUser = userRepository.Authenticate(userCredentials.User, userCredentials.Password);

            if (validUser == null)
            {
                nancyModule.Context.ViewBag.AuthenticationError = Constants.AuthenticationError;
                return(viewRenderer.RenderView(nancyModule.Context, AuthenticationRedirectUrl.Url));
            }

            var guid = userMapper.AddUser(userCredentials.User, validUser.FirstName, validUser.LastName, validUser.Claims);

            validUser.LastLogin = DateTime.UtcNow;
            userRepository.UpdateUser(validUser);
            return(moduleStaticWrappers.LoginAndRedirect(nancyModule, guid, null, ModuleStaticWrappers.DefaultFallbackRedirectUrl));
        }
 public ActiveDirectoryAuthenticateModule(IUserMapper userMapper, IConfiguration configuration, IModuleStaticWrappers moduleStaticWrappers)
 {
     Get[AuthenticationRedirectUrl.Url] = p => userMapper.Authenticate(this, userMapper, configuration, null, null, null, moduleStaticWrappers);
 }
Ejemplo n.º 6
0
 public IndexModule(IModuleStaticWrappers moduleStaticWrappers)
 {
     Get["/"]       = parameters => View["index"];
     Get["/logout"] = p => moduleStaticWrappers.LogoutAndRedirect(this, "~/");
 }