Пример #1
0
        public RESTReplyData admin_get_accounts(RESTRequestData pReq, List <string> pArgs)
        {
            RESTReplyData replyData = new RESTReplyData();  // The HTTP response info
            ResponseBody  respBody  = new ResponseBody();

            if (Accounts.Instance.TryGetAccountWithAuthToken(pReq.AuthToken, out AccountEntity aAccount))
            {
                PaginationInfo     pagination  = new PaginationInfo(pReq);
                AccountFilterInfo  acctFilter  = new AccountFilterInfo(pReq);
                AccountScopeFilter scopeFilter = new AccountScopeFilter(pReq, aAccount);

                respBody.Data = new bodyAccountsReply()
                {
                    accounts = Accounts.Instance.Enumerate(pagination, acctFilter, scopeFilter).Select(acct =>
                    {
                        return(new bodyAccountInfo(acct));
                    }).ToArray()
                };
            }
            else
            {
                Context.Log.Error("{0} GET accounts requested with bad auth", _logHeader);
                respBody.RespondFailure("Bad authorization");
            }
            replyData.SetBody(respBody, pReq);
            return(replyData);
        }
Пример #2
0
        public RESTReplyData user_get(RESTRequestData pReq, List <string> pArgs)
        {
            RESTReplyData replyData = new RESTReplyData();  // The HTTP response info
            ResponseBody  respBody  = new ResponseBody();   // The request's "data" response info

            SessionEntity aSession = Sessions.Instance.GetSession(pReq.SenderKey);

            PaginationInfo pagination = new PaginationInfo(pReq);

            if (Accounts.Instance.TryGetAccountWithAuthToken(pReq.AuthToken, out AccountEntity aAccount))
            {
                AccountFilterInfo  acctFilter  = new AccountFilterInfo(pReq);
                AccountScopeFilter scopeFilter = new AccountScopeFilter(pReq, aAccount);

                respBody.Data = new bodyUsersReply()
                {
                    users = Accounts.Instance.Enumerate(pagination, acctFilter, scopeFilter).Select(acct =>
                    {
                        bodyUser ret = new bodyUser()
                        {
                            username  = acct.Username,
                            accountid = acct.AccountID,
                            images    = acct.Images,
                        };
                        ret.location = BuildLocationInfo(acct);
                        return(ret);
                    }).ToArray()
                };
            }

            // Pagination fills the top level of the reply with paging info
            pagination.AddReplyFields(respBody);

            replyData.SetBody(respBody, pReq);
            return(replyData);
        }