Exemplo n.º 1
0
 /// <summary>
 /// Login a user using their username and password.
 /// </summary>
 /// <param name="UserName"></param>
 /// <param name="Password"></param>
 /// <returns>Return false if any errors shows up</returns>
 public bool LoginAsUser(string UserName, string Password)
 {
     try
     {
         string request;
         if (SSL)
         {
             request = base_Url + "user/generate_auth_cookie?username="******"&password="******"user/generate_auth_cookie?insecure=cool&username="******"&password="******"ok" || auth.status == null || auth.status == "")
         {
             return(false);
         }
         this.user_data        = auth.user;
         this.user_data.avatar = "http:" + this.user_data.avatar;
         this.user_data.FixGravatar();
         this.oauth = auth;
         return(true);
     }
     catch (Exception e)
     {
         if (allowPrint)
         {
             Console.Write(e.Message);
         }
         throw;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Register a user and authorize
 /// </summary>
 /// <param name="username">A username requested by client</param>
 /// <param name="email">User email</param>
 /// <param name="displayname">A display name to be set on wordpress</param>
 /// <returns>Return false if any errors shows up</returns>
 public bool RegisterUser(string username, string email, string displayname)
 {
     try
     {
         this.nounce = setRegistration();
         if (isNounceSet())
         {
             string request;
             if (SSL)
             {
                 request = base_Url + "user/register?username="******"&email=" + email + "&nonce=" + getNounce() + "&display_name=" + displayname + "&notify=both";
             }
             else
             {
                 request = base_Url + "user/register?insecure=cool&username="******"&email=" + email + "&nonce=" + getNounce() + "&display_name=" + displayname + "&notify=both";
             }
             string   jObj   = GetResponse(request);
             Register regObj = JsonConvert.DeserializeObject <Register>(jObj);
             if (regObj.cookie == null || regObj.cookie == "" || regObj.status.ToLower() != "ok")
             {
                 return(false);
             }
             if (SSL)
             {
                 request = base_Url + "user/get_currentuserinfo&cookie=" + regObj.cookie;
             }
             else
             {
                 request = base_Url + "user/get_currentuserinfo?insecure=cool&cookie=" + regObj.cookie;
             }
             jObj = GetResponse(request);
             oAuth auth = JsonConvert.DeserializeObject <oAuth>(jObj);
             if (auth.status.ToLower() != "ok" || auth.status == null || auth.status == "")
             {
                 return(false);
             }
             this.user_data        = auth.user;
             this.user_data.avatar = "http:" + this.user_data.avatar;
             this.user_data.FixGravatar();
             this.oauth = auth;
             return(true);
         }
     }
     catch (Exception e)
     {
         if (allowPrint)
         {
             Console.Write(e.Message);
         }
         throw;
     }
     return(false);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Authrize a cookie. First will check if it is valid
 /// </summary>
 /// <param name="cookie">Cookie ID</param>
 /// <returns>Will return true if everything goes fine</returns>
 public bool AuthCookie(string cookie)
 {
     try
     {
         if (!ValidateCookie(cookie))
         {
             return(false);
         }
         string request;
         if (SSL)
         {
             request = base_Url + "user/get_currentuserinfo/?cookie=" + cookie;
         }
         else
         {
             request = base_Url + "user/get_currentuserinfo/?insecure=cool&cookie=" + cookie;
         }
         string jObj = GetResponse(request);
         oAuth  auth = JsonConvert.DeserializeObject <oAuth>(jObj);
         if (auth.status.ToLower() != "ok" || auth.status == null || auth.status == "" || string.IsNullOrEmpty(auth.status))
         {
             return(false);
         }
         this.user_data        = auth.user;
         this.user_data.avatar = "http:" + this.user_data.avatar;
         this.user_data.FixGravatar();
         this.oauth = auth;
         return(true);
     }
     catch (Exception e)
     {
         if (allowPrint)
         {
             Console.Write(e.Message);
         }
         throw;
     }
 }