コード例 #1
0
ファイル: UserService.cs プロジェクト: skyronic/splatter
        public bool TryLogin(string login, string password)
        {
            Console.WriteLine ("Logging in");
            LoginParams loginParams = new LoginParams();
            loginParams.login = login;
            loginParams.password = password;
            loginParams.remember = true;
            try
            {
                Tracer trace = new Tracer();
                trace.Attach(userProxy);
                XmlRpcStruct loginResult = userProxy.Login(loginParams);
                trace.Detach(userProxy);
                if((int)loginResult["id"] == 0)
                {
                    Console.WriteLine ("User/pass invalid");
                    return false;
                }

            }
            catch(XmlRpcFaultException ex)
            {
                if(ex.FaultCode == 300)
                {
                    Console.WriteLine ("Username invalid");
                    return false;
                }
                Console.WriteLine ("Some strange error");
                return false;
            }
            catch(Exception ex)
            {
                Console.WriteLine ("Unknown error" + ex.Message);
                return false;
            }

            // If the code reaches here, the login is valid
            Console.WriteLine ("Login succeeded");

            // yum :)
            LoginCookies = userProxy.ResponseCookies;

            CookieDict = new Dictionary<string, string[]>();
            CookieList = new List<string[]>();

            foreach(Cookie c in LoginCookies)
            {
                //CookieDict[c.Name] = new string[] {c.Value, c.Path, c.Domain};
                CookieList.Add(new string[] {c.Name, c.Value, c.Path, c.Domain});
            }

            LoggedIn = true;

            return true;
        }