GetUserByKey() public method

public GetUserByKey ( string key ) : string
key string
return string
示例#1
0
    public static string DeleteKey(string Key)
    {
        string      msg     = "";
        HttpContext context = HttpContext.Current;

        if (context.User.Identity.IsAuthenticated)
        {
            try
            {
                vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager();
                if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name))
                {
                    keyMan.DeleteKey(Key);
                    msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteSuccess"];
                }
                else
                {
                    msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteError"];
                }
            }
            catch
            {
                msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteError"];
            }
        }
        else
        {
            context.Response.StatusCode = 401;
        }

        return(msg);
    }
    public static string DeleteKey(string Key)
    {
        string msg = "";
        HttpContext context = HttpContext.Current;
        if (context.User.Identity.IsAuthenticated)
        {
            try
            {
                vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager();
                if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name))
                {
                    keyMan.DeleteKey(Key);
                    msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteSuccess"];
                }
                else
                {
                    msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteError"];
                }
            }
            catch
            {
                msg = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyDeleteError"];
            }

        }
        else
        {
            context.Response.StatusCode = 401;
        }

        return msg;
    }
示例#3
0
    public static Hashtable UpdateKey(string Key, string Description)
    {
        System.Collections.Hashtable ht = new System.Collections.Hashtable();
        HttpContext context             = HttpContext.Current;

        if (context.User.Identity.IsAuthenticated)
        {
            try
            {
                vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager();
                if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name))
                {
                    vwar.service.host.APIKey currentKey = keyMan.GetKeyByKey(Key);
                    currentKey.Usage = context.Server.HtmlEncode(Description);
                    if (keyMan.UpdateKey(currentKey))
                    {
                        ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateSuccess"];
                        ht["Usage"]   = currentKey.Usage;
                    }
                    else
                    {
                        ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
                    }
                }
                else
                {
                    ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
                }
            }
            catch
            {
                ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
            }
        }
        else
        {
            context.Response.StatusCode = 401;
        }

        return(ht);
    }
    public static Hashtable UpdateKey(string Key, string Description)
    {
        System.Collections.Hashtable ht = new System.Collections.Hashtable();
        HttpContext context = HttpContext.Current;
        if (context.User.Identity.IsAuthenticated)
        {
            try
            {
                vwar.service.host.APIKeyManager keyMan = new vwar.service.host.APIKeyManager();
                if (keyMan.GetUserByKey(Key).Equals(context.User.Identity.Name))
                {
                    vwar.service.host.APIKey currentKey = keyMan.GetKeyByKey(Key);
                    currentKey.Usage = context.Server.HtmlEncode(Description);
                    if (keyMan.UpdateKey(currentKey))
                    {
                        ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateSuccess"];
                        ht["Usage"] = currentKey.Usage;
                    }
                    else
                    {
                        ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
                    }
                }
                else
                {
                    ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
                }
            }
            catch
            {
                ht["Message"] = System.Configuration.ConfigurationManager.AppSettings["ProfilePage_KeyUpdateError"];
            }

        }
        else
        {
            context.Response.StatusCode = 401;
        }

        return ht;
    }
示例#5
0
 public virtual bool CheckKey(string key)
 {
     APIKeyManager KeyManager = new APIKeyManager();
     if (key == null)
     {
         WebOperationContext.Current.OutgoingResponse.Headers[System.Net.HttpResponseHeader.WwwAuthenticate] = "BASIC realm=\"3DR API\"";
         WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Unauthorized;
         // throw new WebFaultException(System.Net.HttpStatusCode.Unauthorized);
         return false;
     }
     if (KeyManager.GetUserByKey(key) == null)
     {
         WebOperationContext.Current.OutgoingResponse.Headers[System.Net.HttpResponseHeader.WwwAuthenticate] = "BASIC realm=\"3DR API\"";
         WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Unauthorized;
         // throw new WebFaultException(System.Net.HttpStatusCode.Unauthorized);
         return false;
     }
     KeyManager.Dispose();
     return true;
 }