示例#1
0
        [Api.HttpGet] //(MatchAllBodyParameters = false)]
        public static async Task <IHttpResponse> GetAsync(
            EastFive.Api.SessionToken security,
            IHttpRequest request,
            IAuthApplication application,

            [WorkflowVariable("Session", SessionPropertyName)]
            [WorkflowVariable2("Account", AccountPropertyName)]
            ContentTypeResponse <Whoami> onFound)
        {
            async Task <string> GetName()
            {
                if (!security.accountIdMaybe.HasValue)
                {
                    return(string.Empty);
                }
                return(await application.GetActorNameDetailsAsync(security.accountIdMaybe.Value,
                                                                  (first, last, email) =>
                {
                    return $"{first} {last} [{email}]";
                },
                                                                  () => string.Empty));
            }

            request.TryParseJwt(out System.IdentityModel.Tokens.Jwt.JwtSecurityToken securityToken);
            var whoami = new Whoami()
            {
                session       = security.sessionId.AsRef <Session>(),
                account       = security.accountIdMaybe,
                name          = await GetName(),
                securityToken = securityToken,
            };

            return(onFound(whoami));
        }
示例#2
0
        public static IHttpResponse AllAsync(
            [QueryParameter(Name = "start_time")] DateTime startTime,
            [QueryParameter(Name = "end_time")] DateTime endTime,
            RequestMessage <Authorization> authorizations,
            IAuthApplication application,
            EastFive.Api.SessionToken?securityMaybe,
            MultipartAsyncResponse <Login> onFound)
        {
            var methodLookups = application.LoginProviders
                                .Select(
                (loginProvider) =>
            {
                return(loginProvider.Value.Id.PairWithValue(loginProvider.Value.Method));
            })
                                .ToDictionary();
            var results = authorizations
                          .Where(auth => auth.lastModified <= endTime)
                          .Where(auth => auth.lastModified >= startTime)
                          .StorageGet()
                          .Take(100)
                          .Select(
                async auth =>
            {
                var name = auth.accountIdMaybe.HasValue ?
                           await application.GetActorNameDetailsAsync(auth.accountIdMaybe.Value,
                                                                      (a, b, c) => $"{a} {b}",
                                                                      () => "")
                            :
                           "";
                return(new Login()
                {
                    actorId = auth.accountIdMaybe,
                    authorization = auth.authorizationRef,
                    name = name,
                    method = methodLookups.ContainsKey(auth.Method.id) ?
                             methodLookups[auth.Method.id]
                                :
                             auth.Method.id.ToString(),
                    when = auth.lastModified,
                });
            })
                          .Await();

            return(onFound(results));
        }