Example #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 ?? ""}");
     }
 }
Example #2
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));
        }