public ClaimsIdentity SSOReturnForScreeners(HttpContextBase context)
        {
            var owinContext = context.GetOwinContext();
            var userManager = owinContext.GetUserManager <SSOUserManager>();
            var authManager = owinContext.Authentication;

            var endpoint = _esiRepository.GetByName(Resources.ScreenerEndpointName);

            var token = ESI.SingleSignOn.GetTokensFromAuthenticationToken(endpoint.ClientId, endpoint.SecretKey,
                                                                          ESI.SingleSignOn.GetAuthorisationCode(context.Request.Url));

            var character = new ESI.Models.Character.Detail(token.AccessToken);

            if (character.GetRolesInCorporation(token.AccessToken).Roles.Contains(Resources.Personnel_Manager))
            {
                var identity = GenerateIdentity(character, token.AccessToken);
                identity.AddClaim(new Claim(ClaimTypes.Role, Enum.GetName(typeof(Role), Role.Screener)));

                authManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
                authManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                authManager.SignIn(
                    new Microsoft.Owin.Security.AuthenticationProperties {
                    IsPersistent = false
                },
                    identity
                    );

                return(identity);
            }
            throw new UnauthorizedAccessException();
        }
        public List <AuthorisedCorporationModel> Resolve(ESI.Models.Character.Detail source, CharacterModel destination, List <AuthorisedCorporationModel> destMember, ResolutionContext context)
        {
            var recruit = _recruitRepository.GetRecruitByCharacterId(source.Id);
            var authorisedCorporations = recruit.TokenShare;
            var idList = new IdList()
            {
                Ids = authorisedCorporations.Select(s => s.CorporationId).ToList()
            };

            if (idList.Ids.Count == 0)
            {
                return(new List <AuthorisedCorporationModel>());
            }
            var result = new List <AuthorisedCorporationModel>();

            idList.GetCorporationNames().CorporationDetail.ToList().ForEach(f => {
                result.Add(new AuthorisedCorporationModel()
                {
                    Id     = f.Id,
                    Name   = f.Name,
                    Status = _recruitRepository.GetCurrentStatus(new CorporationAuthorisationModel()
                    {
                        CorporationId = f.Id,
                        RecruitId     = recruit.CharacterId
                    }).ToString()
                });
            });

            return(result);
        }
        public List <WalletTransactionViewModel> GetWalletTransactions(long id)
        {
            var character   = new ESI.Models.Character.Detail(id);
            var endpoint    = _esiRepository.GetByName("Applicant");
            var accessToken = ESI.SingleSignOn.GetTokensFromRefreshToken(endpoint.ClientId, endpoint.SecretKey,
                                                                         _recruitRepository.GetRefreshTokenForApplicant(id));

            var results = _mapper.Map <List <WalletTransactionViewModel> >(character.GetWalletTransactions(accessToken.AccessToken));

            var clientIdList = new IdList()
            {
                Ids = results.Select(s => s.ClientId).Distinct().ToList()
            };
            var itemIdList = new IdList()
            {
                Ids = results.Select(s => (long)s.ItemTypeId).Distinct().ToList()
            };

            var clientInfo = clientIdList.GetEntityNames();
            var itemInfo   = new List <ItemType>();

            itemIdList.Ids.ForEach(f => itemInfo.Add(new ItemType(f)));

            results.ForEach(f => {
                f.ClientName   = clientInfo.First(w => w.Id == f.ClientId).Name;
                f.ItemTypeName = itemInfo.First(w => w.Id == f.ItemTypeId).Name;
            });

            return(results);
        }
        public ClaimsIdentity SSOReturnForApplicants(HttpContextBase context)
        {
            var owinContext = context.GetOwinContext();
            var userManager = owinContext.GetUserManager <SSOUserManager>();
            var authManager = owinContext.Authentication;

            var endpoint = _esiRepository.GetByName(Resources.ApplicantEndpointName);

            var token = ESI.SingleSignOn.GetTokensFromAuthenticationToken(endpoint.ClientId, endpoint.SecretKey,
                                                                          ESI.SingleSignOn.GetAuthorisationCode(context.Request.Url));

            var character = new ESI.Models.Character.Detail(token.AccessToken);
            var identity  = GenerateIdentity(character, token.AccessToken);

            identity.AddClaim(new Claim(ClaimTypes.Role, Enum.GetName(typeof(Role), Role.Applicant)));

            authManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
            authManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            authManager.SignIn(
                new Microsoft.Owin.Security.AuthenticationProperties {
                IsPersistent = false
            },
                identity
                );

            _recruitRepository.AddOrUpdateToken(token.RefreshToken, character.Id);

            return(identity);
        }
        public List <WalletJournalViewModal> GetWalletJournal(long id)
        {
            var character   = new ESI.Models.Character.Detail(id);
            var endpoint    = _esiRepository.GetByName("Applicant");
            var accessToken = ESI.SingleSignOn.GetTokensFromRefreshToken(endpoint.ClientId, endpoint.SecretKey,
                                                                         _recruitRepository.GetRefreshTokenForApplicant(id));

            return(_mapper.Map <List <WalletJournalViewModal> >(character.GetWalletJournal(accessToken.AccessToken)
                                                                .Where(w => w.ReferenceType == "player_donation" || w.ReferenceType == "corporation_account_withdrawal").ToList()));
        }
        private ClaimsIdentity GenerateIdentity(ESI.Models.Character.Detail character, string token)
        {
            var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);

            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, character.Id.ToString()));
            identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"));

            identity.AddClaim(new Claim(ClaimTypes.Name, character.Name));
            identity.AddClaim(new Claim(ClaimTypes.Hash, token));

            return(identity);
        }
예제 #7
0
        public List <MailSummaryModel> GetMailHeaders(long characterId)
        {
            var character = new ESI.Models.Character.Detail()
            {
                Id = characterId
            };
            var endpoint = _esiRepository.GetByName(Resources.ApplicantEndpointName);

            var token = ESI.SingleSignOn.GetTokensFromRefreshToken(endpoint.ClientId, endpoint.SecretKey,
                                                                   _recruitRepository.GetRefreshTokenForApplicant(characterId));

            return(_mapper.Map <List <MailSummaryModel> >(character.GetMails(token.AccessToken)));
        }
        public SSOApplicationUser CreateUser(string userId)
        {
            var toon = new ESI.Models.Character.Detail(Convert.ToInt64(userId));

            var siteUser = new SSOApplicationUser()
            {
                Id            = userId,
                UserName      = toon.Name,
                CorporationId = toon.CorporationId,
                AllianceId    = toon.AllianceId
            };

            siteUser.GenerateUser();
            return(siteUser);
        }
        public string GetHomeStation(long id)
        {
            var character   = new ESI.Models.Character.Detail(id);
            var endpoint    = _esiRepository.GetByName("Applicant");
            var accessToken = ESI.SingleSignOn.GetTokensFromRefreshToken(endpoint.ClientId, endpoint.SecretKey,
                                                                         _recruitRepository.GetRefreshTokenForApplicant(id));
            var homeLocation = character.GetCloneInformation(accessToken.AccessToken).HomeStation;

            if (homeLocation.Type == "structure")
            {
                return(new Structure(homeLocation.Id, accessToken.AccessToken).Name);
            }
            else
            {
                return(new Station(homeLocation.Id).Name);
            }
        }
        public List <ContactViewModel> GetContacts(long id)
        {
            var character = new ESI.Models.Character.Detail(id);

            var endpoint    = _esiRepository.GetByName("Applicant");
            var accessToken = ESI.SingleSignOn.GetTokensFromRefreshToken(endpoint.ClientId, endpoint.SecretKey,
                                                                         _recruitRepository.GetRefreshTokenForApplicant(id));
            var contacts = character.GetContacts(accessToken.AccessToken);

            var characterContacts   = _mapper.Map <List <CharacterContactModel> >(contacts.Where(w => w.ContactType == "character"));
            var corporationContacts = _mapper.Map <List <CorporationContactModel> >(contacts.Where(w => w.ContactType == "corporation"));
            var allianceContacts    = _mapper.Map <List <AllianceContactModel> >(contacts.Where(w => w.ContactType == "alliance"));

            return(_mapper.Map <List <ContactViewModel> >(characterContacts)
                   .Concat(_mapper.Map <List <ContactViewModel> >(corporationContacts))
                   .Concat(_mapper.Map <List <ContactViewModel> >(allianceContacts)).OrderByDescending(o => o.Standing).ToList());
        }
예제 #11
0
        public MailModel GetMailDetail(MailModel request)
        {
            var character = new ESI.Models.Character.Detail()
            {
                Id = request.OwnerId
            };
            var endpoint = _esiRepository.GetByName(Resources.ApplicantEndpointName);

            var token = ESI.SingleSignOn.GetTokensFromRefreshToken(endpoint.ClientId, endpoint.SecretKey,
                                                                   _recruitRepository.GetRefreshTokenForApplicant(request.OwnerId));
            var recode = character.GetMail(request.Id, token.AccessToken).Body.Replace("<br>", "{br}");

            recode       = Regex.Replace(recode, "<.+?>", string.Empty);
            recode       = recode.Replace("{br}", "<br />");
            request.Body = recode;

            return(request);
        }
        public ApplicantViewModel GetCharacterViewModel(long id)
        {
            var character   = new ESI.Models.Character.Detail(id);
            var endpoint    = _esiRepository.GetByName("Applicant");
            var accessToken = ESI.SingleSignOn.GetTokensFromRefreshToken(endpoint.ClientId, endpoint.SecretKey,
                                                                         _recruitRepository.GetRefreshTokenForApplicant(id));
            var result = new ApplicantViewModel
            {
                Applicant = _mapper.Map <CharacterModel>(character)
            };

            try
            {
                result.Applicant.HomeStation = GetHomeStation(character.Id);
            }
            catch { }
            result.Applicant.EmploymentHistory = _mapper.Map <List <CorporationModel> >(character.GetEmploymentHistory());
            result.Applicant.AccountStatus     = _accountStatusHelper.GetAccountStatus(character.GetTrainingQueue(accessToken.AccessToken));
            result.Applicant.SkillPoints       = character.GetTrainedSkills(accessToken.AccessToken).TotalSkillPoints;

            var idList = new IdList {
                Ids = result.Applicant.EmploymentHistory.Select(s => s.Id).Distinct().ToList()
            };
            var corporationsSummary = idList.GetCorporationNames();

            result.Applicant.EmploymentHistory.ForEach(corporation =>
                                                       corporation.Name = corporationsSummary.CorporationDetail.First(w => w.Id == corporation.Id).Name
                                                       );
            result.Applicant.Corporation = result.Applicant.EmploymentHistory.First(w => w.Id == character.CorporationId);
            result.Applicant.Alliance    = AllianceModel.GetAllianceInfo(character.AllianceId);

            if (id != SSOUserManager.SiteUser.Character.Id)
            {
                result.Applicant.CurrentStatus = _recruitRepository.GetCurrentStatus(new CorporationAuthorisationModel()
                {
                    CorporationId = SSOUserManager.SiteUser.CorporationId, RecruitId = result.Applicant.Id
                });
            }

            return(result);
        }
예제 #13
0
        public ClaimsIdentity GenerateIdentity(string authToken)
        {
            var toon = new ESI.Models.Character.Detail(authToken);
            var corp = new ESI.Models.Corporation.Detail(toon.CorporationId);

            using (var context = new DatabaseContext())
            {
                if (!context.Corporations.Any(s => s.Id == corp.Id) &&
                    (!corp.AllianceId.HasValue || !context.Alliances.Any(s => s.Id == corp.AllianceId)))
                {
                    return(null);
                }
            }

            var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);

            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, toon.Id.ToString()));
            identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"));

            identity.AddClaim(new Claim(ClaimTypes.Name, toon.Name));

            return(identity);
        }