当前位置: 首页>>代码示例>>C#>>正文


C# OSHttpResponse.AddHeader方法代码示例

本文整理汇总了C#中Aurora.Framework.Servers.HttpServer.OSHttpResponse.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# OSHttpResponse.AddHeader方法的具体用法?C# OSHttpResponse.AddHeader怎么用?C# OSHttpResponse.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Aurora.Framework.Servers.HttpServer.OSHttpResponse的用法示例。


在下文中一共展示了OSHttpResponse.AddHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OKResponse

 private byte[] OKResponse(OSHttpResponse httpResponse)
 {
     httpResponse.AddHeader("X-Handlers-Provided", m_HandlersType);
     httpResponse.StatusCode = (int) HttpStatusCode.OK;
     httpResponse.StatusDescription = "OK";
     return MainServer.BlankResponse;
 }
开发者ID:nathanmarck,项目名称:Aurora-Sim,代码行数:7,代码来源:HeloHandler.cs

示例2: Fill

        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, Hashtable query, OSHttpResponse httpResponse,
            Dictionary<string, object> requestParameters, ITranslator translator)
        {
            var vars = new Dictionary<string, object>();

            string error = "";
            if (requestParameters.ContainsKey("username") && requestParameters.ContainsKey("password"))
            {
                string username = requestParameters["username"].ToString();
                string password = requestParameters["password"].ToString();

                ILoginService loginService = webInterface.Registry.RequestModuleInterface<ILoginService>();
                if (loginService.VerifyClient(UUID.Zero, username, "UserAccount", password, UUID.Zero))
                {
                    UUID sessionID = UUID.Random();
                    UserAccount account = webInterface.Registry.RequestModuleInterface<IUserAccountService>().GetUserAccount(UUID.Zero, username);
                    Authenticator.AddAuthentication(sessionID, account.PrincipalID);
                    if (account.UserLevel > 0)
                        Authenticator.AddAdminAuthentication(sessionID, account.PrincipalID);
                    httpResponse.AddCookie(new System.Web.HttpCookie("SessionID", sessionID.ToString()) { Expires = DateTime.MinValue, Path = "" });

                    httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
                    httpResponse.AddHeader("Location", "/welcomescreen/index.html");

                    return vars;
                }
                else
                    error = "Failed to verify user name and password";
            }

            vars.Add("ErrorMessage", error);
            vars.Add("Login", translator.GetTranslatedString("Login"));
            vars.Add("UserNameText", translator.GetTranslatedString("UserName"));
            vars.Add("PasswordText", translator.GetTranslatedString("Password"));
            vars.Add("ForgotPassword", translator.GetTranslatedString("ForgotPassword"));
            vars.Add("Submit", translator.GetTranslatedString("Submit"));

            return vars;
        }
开发者ID:JAllard,项目名称:Aurora-Sim,代码行数:39,代码来源:login.cs

示例3: Handle

 public override byte[] Handle(string path, Stream requestData, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
 {
     if (WebAPI.EnableCORS)
     {
         if ((new List<string>(httpRequest.Headers.AllKeys)).Contains("origin"))
         {
             string origin = httpRequest.Headers["origin"];
             if (WebAPI.AccessControlAllowOrigin.Contains(origin) || WebAPI.AccessControlAllowOrigin.Contains("*"))
             {
                 httpResponse.AddHeader("Access-Control-Allow-Origin", origin);
                 httpResponse.AddHeader("Access-Control-Allow-Methods", "GET, POST");
                 httpResponse.AddHeader("Access-Control-Allow-Credentials", "true");
                 httpResponse.AddHeader("Access-Control-Allow-Headers", "Authorization");
             }
         }
     }
     if (HttpMethod != "OPTIONS")
     {
         return WebAPI.doAPICall(this, path, requestData, httpRequest, httpResponse);
     }
     else if (!WebAPI.EnableCORS)
     {
         httpResponse.StatusCode = 405;
         httpResponse.StatusDescription = "Method Not Allowed";
     }
     httpResponse.ContentType = "application/json";
     return new byte[0];
 }
开发者ID:SignpostMarv,项目名称:Aurora-WebAPI,代码行数:28,代码来源:WebAPIHandler.cs

示例4: negotiateAuth

        private bool negotiateAuth(OSHttpRequest request, OSHttpResponse response)
        {
            Dictionary<string, string> authorization = authorizationHeader(request);

            switch (APIAuthentication)
            {
                case "Digest":

                    if (authorization != null)
                    {
                        string storednonce;
                        if (
                            authorization.ContainsKey("username") &&
                            authorization.ContainsKey("realm") &&
                            authorization.ContainsKey("uri") &&
                            authorization.ContainsKey("qop") &&
                            authorization.ContainsKey("nonce") &&
                            authorization.ContainsKey("nc") &&
                            authorization.ContainsKey("cnonce") &&
                            authorization.ContainsKey("opaque") &&
                            m_authNonces.TryGetValue(authorization["opaque"], out storednonce) &&
                            authorization["nonce"] == storednonce
                        )
                        {
                            m_authNonces.Remove(authorization["opaque"]);

                            UUID accountID = authUser(request);

                            if (accountID != UUID.Zero)
                            {
                                string password = Utils.MD5String(m_connector.GetAccessToken(accountID).ToString());

                                string HA1 = Util.Md5Hash(string.Join(":", new string[]{
                                    authorization["username"],
                                    Name,
                                    password
                                }));
                                string HA2 = Util.Md5Hash(request.HttpMethod + ":" + authorization["uri"]);
                                string expectedDigestResponse = (authorization.ContainsKey("qop") && authorization["qop"] == "auth") ? Util.Md5Hash(string.Join(":", new string[]{
                                    HA1,
                                    storednonce,
                                    authorization["nc"],
                                    authorization["cnonce"],
                                    "auth",
                                    HA2
                                })) : Util.Md5Hash(string.Join(":", new string[]{
                                    HA1,
                                    storednonce,
                                    HA2
                                }));
                                if (expectedDigestResponse == authorization["response"])
                                {
                                    return true;
                                }
                                else
                                {
                                    MainConsole.Instance.DebugFormat("[WebAPI]: API authentication failed for {0}", authorization["username"]);
                                }
                            }
                        }
                    }
                    string opaque = UUID.Random().ToString();
                    string nonce = UUID.Random().ToString();
                    m_authNonces.Add(opaque, nonce, 5);
                    string digestHeader = "Digest " + string.Join(", ", new string[]{
                            "realm=\"" + Name + "\"",
                            "qop=\"auth\"",
                            "nonce=\"" + nonce + "\"",
                            "opaque=\"" + opaque + "\""
                        });
                    response.AddHeader("WWW-Authenticate", digestHeader);
                    break;
                case "Basic":
                    if (authorization != null && authorization.ContainsKey("username") && authorization.ContainsKey("password"))
                    {
                        UUID accountID = authUser(request);
                        if (accountID != UUID.Zero && authorization["password"] == Utils.MD5String(m_connector.GetAccessToken(accountID).ToString()))
                        {
                            return true;
                        }
                        else
                        {
                            MainConsole.Instance.DebugFormat("[WebAPI]: API authentication failed for {0}", authorization["username"]);
                        }
                    }
                    response.AddHeader("WWW-Authenticate", "Basic realm=\"" + Name + "\"");
                    break;
            }
            response.StatusCode = 401;
            response.StatusDescription = "Unauthorized";
            return false;
        }
开发者ID:SignpostMarv,项目名称:Aurora-WebAPI,代码行数:92,代码来源:WebAPIHandler.cs

示例5: SendHTML500

        public void SendHTML500(OSHttpResponse response)
        {
            // I know this statuscode is dumb, but the client doesn't respond to 404s and 500s
            response.StatusCode = (int)OSHttpStatusCode.SuccessOk;
            response.AddHeader("Content-type", "text/html");

            string responseString = GetHTTP500();
            byte[] buffer = Encoding.UTF8.GetBytes(responseString);

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;
            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[BASE HTTP SERVER]: Error - " + ex);
            }
            finally
            {
                //response.OutputStream.Close();
                try
                {
                    response.Send();
                    //response.FreeContext();
                }
                catch (SocketException e)
                {
                    // This has to be here to prevent a Linux/Mono crash
                    MainConsole.Instance.WarnFormat("[BASE HTTP SERVER] XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
                }
            }
        }
开发者ID:Gnu32,项目名称:Silverfin,代码行数:35,代码来源:BaseHttpServer.cs

示例6: DoHTTPGruntWork

        internal void DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response, OSHttpRequest request)
        {
            //MainConsole.Instance.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response");
            byte[] buffer;
            if (responsedata.Count == 0)
            {
                response.StatusCode = 404;
                buffer = Encoding.UTF8.GetBytes("404");
                response.OutputStream.Write(buffer, 0, buffer.Length);
                response.OutputStream.Close();
                return;
            }
            int responsecode = (int)responsedata["int_response_code"];
            string responseString = (string)responsedata["str_response_string"];
            string contentType = (string)responsedata["content_type"];


            if (responsedata.ContainsKey("error_status_text"))
            {
                response.StatusDescription = (string)responsedata["error_status_text"];
            }
            if (responsedata.ContainsKey("http_protocol_version"))
            {
                response.ProtocolVersion = (string)responsedata["http_protocol_version"];
            }

            if (responsedata.ContainsKey("keepalive"))
            {
                bool keepalive = (bool)responsedata["keepalive"];
                response.KeepAlive = keepalive;

            }

            if (responsedata.ContainsKey("reusecontext"))
                response.ReuseContext = (bool)responsedata["reusecontext"];

            //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this
            //and should check for NullReferenceExceptions

            if (string.IsNullOrEmpty(contentType))
            {
                contentType = "text/html";
            }

            // The client ignores anything but 200 here for web login, so ensure that this is 200 for that

            response.StatusCode = responsecode;

            if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently)
            {
                response.RedirectLocation = (string)responsedata["str_redirect_location"];
                response.StatusCode = responsecode;
            }

            response.AddHeader("Content-Type", contentType);


            if (!(contentType.Contains("image")
                || contentType.Contains("x-shockwave-flash")
                || contentType.Contains("application/x-oar")
                || contentType.Contains("application/vnd.ll.mesh")))
            {
                // Text
                buffer = Encoding.UTF8.GetBytes(responseString);
            }
            else
            {
                // Binary!
                buffer = Convert.FromBase64String(responseString);
            }

            bool sendBuffer = true;

            string ETag = Util.SHA1Hash(buffer.ToString());
            response.AddHeader("ETag", ETag);
            List<string> rHeaders = request.Headers.AllKeys.ToList<string>();
            if (rHeaders.Contains("if-none-match") && request.Headers["if-none-match"].IndexOf(ETag) >= 0)
            {
                response.StatusCode = 304;
                response.StatusDescription = "Not Modified";
                sendBuffer = false;
            }


            try
            {
                if (sendBuffer)
                {
                    response.SendChunked = false;
                    response.ContentLength64 = buffer.Length;
                    response.ContentEncoding = Encoding.UTF8;
                    response.OutputStream.Write(buffer, 0, buffer.Length);
                }
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[HTTPD]: Error - " + ex);
            }
            finally
            {
//.........这里部分代码省略.........
开发者ID:Gnu32,项目名称:Silverfin,代码行数:101,代码来源:BaseHttpServer.cs

示例7: SendHTML500

        public byte[] SendHTML500(OSHttpResponse response)
        {
            // I know this statuscode is dumb, but the client doesn't respond to 404s and 500s
            response.StatusCode = (int)OSHttpStatusCode.SuccessOk;
            response.AddHeader("Content-type", "text/html");

            string responseString = GetHTTP500();
            byte[] buffer = Encoding.UTF8.GetBytes(responseString);

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            return buffer;
        }
开发者ID:samiam123,项目名称:Aurora-Sim,代码行数:15,代码来源:BaseHttpServer.cs

示例8: DoHTTPGruntWork

        internal byte[] DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response)
        {
            //MainConsole.Instance.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response");
            int responsecode = (int)responsedata["int_response_code"];
            string responseString = (string)responsedata["str_response_string"];
            string contentType = (string)responsedata["content_type"];

            if (responsedata.ContainsKey("error_status_text"))
            {
                response.StatusDescription = (string)responsedata["error_status_text"];
            }
            if (responsedata.ContainsKey("http_protocol_version"))
            {
                response.ProtocolVersion = (string)responsedata["http_protocol_version"];
            }

            if (responsedata.ContainsKey("keepalive"))
            {
                bool keepalive = (bool)responsedata["keepalive"];
                response.KeepAlive = keepalive;

            }

            if (responsedata.ContainsKey("reusecontext"))
                response.ReuseContext = (bool)responsedata["reusecontext"];

            // Cross-Origin Resource Sharing with simple requests
            if (responsedata.ContainsKey("access_control_allow_origin"))
                response.AddHeader("Access-Control-Allow-Origin", (string)responsedata["access_control_allow_origin"]);

            //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this
            //and should check for NullReferenceExceptions

            if (string.IsNullOrEmpty(contentType))
            {
                contentType = "text/html";
            }

            // The client ignores anything but 200 here for web login, so ensure that this is 200 for that

            response.StatusCode = responsecode;

            if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently)
            {
                response.RedirectLocation = (string)responsedata["str_redirect_location"];
                response.StatusCode = responsecode;
            }

            response.AddHeader("Content-Type", contentType);

            byte[] buffer;

            if (!(contentType.Contains("image")
                || contentType.Contains("x-shockwave-flash")
                || contentType.Contains("application/x-oar")
                || contentType.Contains("application/vnd.ll.mesh")))
            {
                // Text
                buffer = Encoding.UTF8.GetBytes(responseString);
            }
            else
            {
                // Binary!
                buffer = Convert.FromBase64String(responseString);
            }

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            return buffer;
        }
开发者ID:samiam123,项目名称:Aurora-Sim,代码行数:72,代码来源:BaseHttpServer.cs

示例9: WriteTextureData

        private void WriteTextureData(OSHttpRequest request, OSHttpResponse response, AssetBase texture, string format)
        {
            m_service.Registry.RequestModuleInterface<ISimulationBase>().EventManager.FireGenericEventHandler(
                "AssetRequested", new object[] {m_service.Registry, texture, m_service.AgentID});

            string range = request.Headers.GetOne("Range");
            //MainConsole.Instance.DebugFormat("[GETTEXTURE]: Range {0}", range);
            if (!String.IsNullOrEmpty(range)) // JP2's only
            {
                // Range request
                int start, end;
                if (TryParseRange(range, out start, out end))
                {
                    // Before clamping start make sure we can satisfy it in order to avoid
                    // sending back the last byte instead of an error status
                    if (start >= texture.Data.Length)
                    {
                        response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable;
                    }
                    else
                    {
                        end = Utils.Clamp(end, 0, texture.Data.Length - 1);
                        start = Utils.Clamp(start, 0, end);
                        int len = end - start + 1;

                        //MainConsole.Instance.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);

                        if (len < texture.Data.Length)
                            response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
                        else
                            response.StatusCode = (int)System.Net.HttpStatusCode.OK;

                        response.ContentLength = len;
                        response.ContentType = texture.TypeString;
                        response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length));

                        response.Body.Write(texture.Data, start, len);
                    }
                }
                else
                {
                    MainConsole.Instance.Warn("[GETTEXTURE]: Malformed Range header: " + range);
                    response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                }
            }
            else // JP2's or other formats
            {
                // Full content request
                response.StatusCode = (int)System.Net.HttpStatusCode.OK;
                response.ContentLength = texture.Data.Length;
                response.ContentType = texture.TypeString;
                if (format == DefaultFormat)
                    response.ContentType = texture.TypeString;
                else
                    response.ContentType = "image/" + format;
                response.Body.Write(texture.Data, 0, texture.Data.Length);
            }
        }
开发者ID:Gnu32,项目名称:Silverfin,代码行数:58,代码来源:AssetCAPS.cs

示例10: Redirect

 internal void Redirect(OSHttpResponse httpResponse, string url)
 {
     httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
     httpResponse.AddHeader("Location", url);
     httpResponse.KeepAlive = false;
 }
开发者ID:rjspence,项目名称:YourSim,代码行数:6,代码来源:WebInterface.cs

示例11: GetContentType

 protected string GetContentType(string filename, OSHttpResponse response)
 {
     switch(Path.GetExtension(filename))
     {
         case ".jpeg":
         case ".jpg":
             response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString());
             return "image/jpeg";
         case ".gif":
             response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString());
             return "image/gif";
         case ".png":
             response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString());
             return "image/png";
         case ".tiff":
             response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString());
             return "image/tiff";
         case ".html":
         case ".htm":
         case ".xsl":
             response.AddHeader("Cache-Control", "no-cache");
             return "text/html";
         case ".css":
             //response.AddHeader("Cache-Control", "max-age=" + CLIENT_CACHE_TIME.ToString() + ", public");
             return "text/css";
         case ".js":
             //response.AddHeader("Cache-Control", "max-age=" + CLIENT_CACHE_TIME.ToString() + ", public");
             return "application/javascript";
     }
     return "text/plain";
 }
开发者ID:rjspence,项目名称:YourSim,代码行数:31,代码来源:WebInterface.cs

示例12: SendGenericHTTPResponse

        internal void SendGenericHTTPResponse(Hashtable responsedata, OSHttpResponse response, OSHttpRequest request)
        {
            //MainConsole.Instance.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response");
            byte[] buffer;
            if (responsedata.Count == 0)
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                buffer = Encoding.UTF8.GetBytes("404");
                response.OutputStream.Write(buffer, 0, buffer.Length);
                response.Send();
                return;
            }

            int responsecode = (int)responsedata["int_response_code"];
            string responseString = (string)responsedata["str_response_string"];
            string contentType = (string)responsedata["content_type"];

            if (responsedata.ContainsKey("error_status_text"))
                response.StatusDescription = (string)responsedata["error_status_text"];

            if (responsedata.ContainsKey("keepalive"))
                response.KeepAlive = (bool)responsedata["keepalive"];

            response.ContentType = string.IsNullOrEmpty(contentType) ? "text/html" : contentType;

            response.StatusCode = responsecode;

            if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently)
            {
                response.RedirectLocation = (string)responsedata["str_redirect_location"];
                response.StatusCode = responsecode;
            }

            if (contentType != null && !(contentType.Contains("image")
                                         || contentType.Contains("x-shockwave-flash")
                                         || contentType.Contains("application/x-oar")
                                         || contentType.Contains("application/vnd.ll.mesh")))
            {
                // Text
                buffer = Encoding.UTF8.GetBytes(responseString);
            }
            else
            {
                // Binary!
                buffer = Convert.FromBase64String(responseString);
            }

            bool sendBuffer = true;

            string ETag = Util.SHA1Hash(buffer.ToString());
            response.AddHeader("ETag", ETag);
            List<string> rHeaders = request.Headers.AllKeys.ToList();
            if (rHeaders.Contains("if-none-match") && request.Headers["if-none-match"].IndexOf(ETag) >= 0)
            {
                response.StatusCode = 304;
                response.StatusDescription = "Not Modified";
                sendBuffer = false;
            }


            try
            {
                if (sendBuffer)
                {
                    response.ContentEncoding = Encoding.UTF8;
                    response.OutputStream.Write(buffer, 0, buffer.Length);
                }
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[HTTPD]: Error - " + ex);
            }
            finally
            {
                try
                {
                    response.Send();
                }
                catch (SocketException e)
                {
                    // This has to be here to prevent a Linux/Mono crash
                    MainConsole.Instance.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
                }
                catch (IOException e)
                {
                    MainConsole.Instance.Debug("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e);
                }
            }
        }
开发者ID:nathanmarck,项目名称:Aurora-Sim,代码行数:89,代码来源:BaseHttpServer.cs

示例13: SendHTML500

        private void SendHTML500(OSHttpResponse response)
        {
            // I know this statuscode is dumb, but the client/MSIE doesn't respond to 404s and 500s
            response.StatusCode = (int)HttpStatusCode.OK;
            response.AddHeader("Content-type", "text/html");

            byte[] buffer = Encoding.UTF8.GetBytes(GetHTTP500());

            response.ContentEncoding = Encoding.UTF8;
            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
                response.Send();
            }
            catch (SocketException e)
            {
                // This has to be here to prevent a Linux/Mono crash
                MainConsole.Instance.WarnFormat("[BASE HTTP SERVER] XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
            }
        }
开发者ID:nathanmarck,项目名称:Aurora-Sim,代码行数:20,代码来源:BaseHttpServer.cs

示例14: Fill

        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, Hashtable query, OSHttpResponse httpResponse,
            Dictionary<string, object> requestParameters, ITranslator translator)
        {
            var vars = new Dictionary<string, object>();

            string error = "";
            if (requestParameters.ContainsKey("Submit"))
            {
                string AvatarName = requestParameters["AvatarName"].ToString();
                string AvatarPassword = requestParameters["AvatarPassword"].ToString();
                string FirstName = requestParameters["FirstName"].ToString();
                string LastName = requestParameters["LastName"].ToString();
                string UserAddress = requestParameters["UserAddress"].ToString();
                string UserZip = requestParameters["UserZip"].ToString();
                string UserCity = requestParameters["UserCity"].ToString();
                string UserEmail = requestParameters["UserEmail"].ToString();
                string AvatarScope = requestParameters.ContainsKey("AvatarScope") ? requestParameters["AvatarScope"].ToString() : UUID.Zero.ToString();
                string UserDOBMonth = requestParameters["UserDOBMonth"].ToString();
                string UserDOBDay = requestParameters["UserDOBDay"].ToString();
                string UserDOBYear = requestParameters["UserDOBYear"].ToString();
                string AvatarArchive = requestParameters.ContainsKey("AvatarArchive") ? requestParameters["AvatarArchive"].ToString() : "";
                bool ToSAccept = requestParameters.ContainsKey("ToSAccept") && requestParameters["ToSAccept"].ToString() == "Accepted";

                if (ToSAccept)
                {
                    AvatarPassword = Util.Md5Hash(AvatarPassword);

                    IUserAccountService accountService = webInterface.Registry.RequestModuleInterface<IUserAccountService>();
                    UUID userID = UUID.Random();
                    error = accountService.CreateUser(userID, UUID.Parse(AvatarScope), AvatarName, AvatarPassword, UserEmail);
                    if (error == "")
                    {
                        IAgentConnector con = Aurora.DataManager.DataManager.RequestPlugin<IAgentConnector>();
                        con.CreateNewAgent(userID);
                        IAgentInfo agent = con.GetAgent(userID);
                        agent.OtherAgentInformation["RLFirstName"] = FirstName;
                        agent.OtherAgentInformation["RLLastName"] = LastName;
                        agent.OtherAgentInformation["RLAddress"] = UserAddress;
                        agent.OtherAgentInformation["RLCity"] = UserCity;
                        agent.OtherAgentInformation["RLZip"] = UserZip;
                        agent.OtherAgentInformation["UserDOBMonth"] = UserDOBMonth;
                        agent.OtherAgentInformation["UserDOBDay"] = UserDOBDay;
                        agent.OtherAgentInformation["UserDOBYear"] = UserDOBYear;
                        /*if (activationRequired)
                        {
                            UUID activationToken = UUID.Random();
                            agent.OtherAgentInformation["WebUIActivationToken"] = Util.Md5Hash(activationToken.ToString() + ":" + PasswordHash);
                            resp["WebUIActivationToken"] = activationToken;
                        }*/
                        con.UpdateAgent(agent);

                        if (AvatarArchive != "")
                        {
                            IProfileConnector profileData = Aurora.DataManager.DataManager.RequestPlugin<IProfileConnector>();
                            profileData.CreateNewProfile(userID);

                            IUserProfileInfo profile = profileData.GetUserProfile(userID);
                            profile.AArchiveName = AvatarArchive + ".database";
                            profile.IsNewUser = true;
                            profileData.UpdateUserProfile(profile);
                        }

                        httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
                        httpResponse.AddHeader("Location", "/welcomescreen/index.html");

                        return vars;
                    }
                }
                else
                    error = "You did not accept the Terms of Service agreement.";
            }

            List<Dictionary<string, object>> daysArgs = new List<Dictionary<string, object>>();
            for (int i = 1; i <= 31; i++)
                daysArgs.Add(new Dictionary<string, object> { { "Value", i } });

            List<Dictionary<string, object>> monthsArgs = new List<Dictionary<string, object>>();
            for (int i = 1; i <= 12; i++)
                monthsArgs.Add(new Dictionary<string, object> { { "Value", i } });

            List<Dictionary<string, object>> yearsArgs = new List<Dictionary<string, object>>();
            for (int i = 1900; i <= 2013; i++)
                yearsArgs.Add(new Dictionary<string, object> { { "Value", i } });

            vars.Add("Days", daysArgs);
            vars.Add("Months", monthsArgs);
            vars.Add("Years", yearsArgs);

            List<AvatarArchive> archives = Aurora.DataManager.DataManager.RequestPlugin<IAvatarArchiverConnector>().GetAvatarArchives(true);

            List<Dictionary<string, object>> avatarArchives = new List<Dictionary<string, object>>();
            foreach (var archive in archives)
                avatarArchives.Add(new Dictionary<string, object> { { "AvatarArchiveName", archive.Name }, { "AvatarArchiveSnapshotID", archive.Snapshot } });

            vars.Add("AvatarArchive", avatarArchives);

            
            IConfig loginServerConfig = webInterface.Registry.RequestModuleInterface<ISimulationBase>().ConfigSource.Configs["LoginService"];
            string tosLocation = "";
            if (loginServerConfig != null && loginServerConfig.GetBoolean("UseTermsOfServiceOnFirstLogin", false))
//.........这里部分代码省略.........
开发者ID:JAllard,项目名称:Aurora-Sim,代码行数:101,代码来源:register.cs

示例15: AllowAPICall

        public bool AllowAPICall(string method, OSHttpRequest request, OSHttpResponse response)
        {
            Dictionary<string, string> authorization = authorizationHeader(request);
            if (authorization != null)
            {
                string storednonce;
                if (
                    authorization.ContainsKey("username") &&
                    authorization.ContainsKey("realm") &&
                    authorization.ContainsKey("uri") &&
                    authorization.ContainsKey("qop") &&
                    authorization.ContainsKey("nonce") &&
                    authorization.ContainsKey("nc") &&
                    authorization.ContainsKey("cnonce") &&
                    authorization.ContainsKey("opaque") &&
                    m_authNonces.TryGetValue(authorization["opaque"], out storednonce) &&
                    authorization["nonce"] == storednonce
                )
                {
                    m_authNonces.Remove(authorization["opaque"]);

                    UUID accountID = authUser(request);
                    if (accountID == UUID.Zero)
                    {
                        response.StatusCode = 403;
                        response.StatusDescription = "Forbidden";
                        MainConsole.Instance.DebugFormat("[WebAPI]: {0} is not permitted to use WebAPI", authorization["username"], method);
                    }
                    else
                    {
                        string password = Utils.MD5String(m_connector.GetAccessToken(accountID).ToString());

                        string HA1 = Util.Md5Hash(string.Join(":", new string[]{
                                authorization["username"],
                                Name,
                                password
                            }));
                        string HA2 = Util.Md5Hash(request.HttpMethod + ":" + authorization["uri"]);
                        string expectedDigestResponse = (authorization.ContainsKey("qop") && authorization["qop"] == "auth") ? Util.Md5Hash(string.Join(":", new string[]{
                                HA1,
                                storednonce,
                                authorization["nc"],
                                authorization["cnonce"],
                                "auth",
                                HA2
                            })) : Util.Md5Hash(string.Join(":", new string[]{
                                HA1,
                                storednonce,
                                HA2
                            }));
                        if (expectedDigestResponse == authorization["response"])
                        {
                            if (m_connector.AllowAPICall(accountID, method))
                            {
                                m_connector.LogAPICall(accountID, method);
                                return true;
                            }
                            else if (m_connector.GetRateLimit(accountID, method) == null)
                            {
                                response.StatusCode = 403;
                                response.StatusDescription = "Forbidden";
                                MainConsole.Instance.DebugFormat("[WebAPI]: {0} is not permitted to use API method {1}", authorization["username"], method);
                            }
                            else if (m_connector.RateLimitExceed(accountID, method))
                            {
                                response.StatusCode = 429;
                                response.StatusDescription = "Too Many Requests";
                                MainConsole.Instance.DebugFormat("[WebAPI]: {0} exceeded their hourly rate limit for API method {1}", authorization["username"], method);
                            }
                            else
                            {
                                response.StatusCode = 500;
                                MainConsole.Instance.DebugFormat("[WebAPI]: {0} cannotuse API method {1}, although we're not sure why.", authorization["username"], method);
                            }
                        }
                        else
                        {
                            MainConsole.Instance.DebugFormat("[WebAPI]: API authentication failed for {0}", authorization["username"]);
                        }
                    }
                }
            }
            else
            {
                string opaque = UUID.Random().ToString();
                string nonce = UUID.Random().ToString();
                m_authNonces.Add(opaque, nonce, 5);
                response.StatusCode = 401;
                response.StatusDescription = "Unauthorized";
                string digestHeader = "Digest " + string.Join(", ", new string[]{
                        "realm=\"" + Name + "\"",
                        "qop=\"auth\"",
                        "nonce=\"" + nonce + "\"",
                        "opaque=\"" + opaque + "\""
                    });
                response.AddHeader("WWW-Authenticate", digestHeader);
            }
            return false;
        }
开发者ID:KSLcom,项目名称:Aurora-WebAPI,代码行数:99,代码来源:WebAPIHandler.cs


注:本文中的Aurora.Framework.Servers.HttpServer.OSHttpResponse.AddHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。