Beispiel #1
0
        public static Response SignIn(this NancyModule module, CrossoutUser user)
        {
            var claims = new List <Claim>();

            claims.Add(new Claim(CrossoutWebClaimTypes.Identifier, user.AuthId));

            // Add the admin claim if the user is an Administrator
            if (user.IsAdmin)
            {
                claims.Add(new Claim(CrossoutWebClaimTypes.Admin, "true"));
            }

            return(module.SignIn(claims));
        }
Beispiel #2
0
        public dynamic Process(NancyModule nancyModule, AuthenticateCallbackData model)
        {
            if (model.Exception != null)
            {
                throw new NotImplementedException("Login failure", model.Exception);
            }

            CrossoutUser loggedInUser = null;

            if (nancyModule.Context.CurrentUser != null)
            {
                loggedInUser = userRepository.LoadUser(nancyModule.Context.CurrentUser.UserName);
            }

            if (loggedInUser == null)
            {
                UserInformation userInfo = model.AuthenticatedClient.UserInformation;

                var user = userRepository.LoadUser(userInfo.Id);

                if (user == CrossoutUser.EmptyUser)
                {
                    userRepository.SaveUser(new CrossoutUser
                    {
                        AuthEmail    = userInfo.Email,
                        AuthId       = userInfo.Id,
                        AuthName     = userInfo.Name,
                        AuthUsername = userInfo.UserName
                    });
                    user = userRepository.LoadUser(userInfo.Id);
                }
                return(nancyModule.LoginAndRedirect(user.Guid, null, "~/admin"));
            }

            return(nancyModule.AsRedirectQueryStringOrDefault("~/admin"));
        }