Exemplo n.º 1
0
 internal void OnLoginFailed(UserEventArgs args)
 {
     if (LoginFailed != null)
     {
         LoginFailed(this, args);
     }
 }
Exemplo n.º 2
0
 internal void OnLoggedIn(UserEventArgs args)
 {
     if (LoggedIn != null)
     {
         LoggedIn(this, args);
     }
 }
Exemplo n.º 3
0
        static void User_LoggedIn(object sender, UserEventArgs e)
        {
            User user = sender as User;
            string info =
                String.Format("Succesfully logged in as {0} using:\n{1}\t as API key;\n{2}\t as secret key;\n{3}\t as publisher key."
                , user.UserName, Service.APIKey, Service.SecretKey, Service.PublisherID);

            Console.WriteLine(info);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Signs a user up for Scribd.  Doing so will log the
        /// current user profile out and replace it with this one.
        /// </summary>
        /// <param name="userName">Username to associate with your Scribd account</param>
        /// <param name="password">Password to associate with your Scribd account</param>
        /// <param name="email">Your email address</param>
        /// <param name="name">Your real name</param>
        /// <returns>True on success</returns>
        public static bool Signup(string userName, string password, string email, string name)
        {
            UserEventArgs _args = new UserEventArgs();

            if (BeforeSignUp != null)
            {
                _args.Success       = false;
                _args.User.UserName = userName;
                _args.User.Name     = name;
            }

            if (!_args.Cancel)
            {
                using (Request _request = new Request())
                {
                    _request.MethodName = "user.signup";
                    _request.Parameters.Add("username", userName);
                    _request.Parameters.Add("password", password);
                    _request.Parameters.Add("email", email);
                    _request.Parameters.Add("name", name);

                    User cachedUser = Service.Instance.InternalUser;
                    Service.Instance.InternalUser = null;

                    using (Response _response = Service.Instance.PostRequest(_request))
                    {
                        Service.Instance.InternalUser = cachedUser;

                        // Parse response
                        User _result = new User();
                        if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                        {
                            XmlNodeList _list = _response.GetElementsByTagName("rsp");
                            if (_list.Count > 0)
                            {
                                foreach (XmlNode _node in _list)
                                {
                                    _result.Name         = _node.SelectSingleNode("name").InnerText.Trim();
                                    _result.SessionKey   = _node.SelectSingleNode("session_key").InnerText.Trim();
                                    _result.UserId       = int.Parse(_node.SelectSingleNode("user_id").InnerText.Trim());
                                    _result.UserName     = _node.SelectSingleNode("username").InnerText.Trim();
                                    _result.m_isLoggedIn = true;

                                    // Notify subscribers of sign-up success.
                                    _args.Success = true;
                                    _args.User    = _result;
                                    if (User.AfterSignUp != null)
                                    {
                                        User.AfterSignUp(null, _args);
                                    }

                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            _args.Success = false;
            if (User.AfterSignUp != null)
            {
                User.AfterSignUp(null, _args);
            }

            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Logs a user into the service.
        /// </summary>
        /// <param name="userName">Username associated with your Scribd account</param>
        /// <param name="password">Password associated with your Scribd account</param>
        /// <param name="verifyOnly">Just verifying credentials, don't change state of 'logged in' user</param>
        /// <param name="newUser">(out) Can be used by called to get the newly created User</param>
        /// <returns>True on success</returns>
        private static bool _Login(string userName, string password, bool verifyOnly, out User newUser)
        {
            UserEventArgs _args = new UserEventArgs();

            if (BeforeLogin != null)
            {
                _args.Success       = false;
                _args.User.UserName = userName;
            }

            newUser = null;

            if (!_args.Cancel)
            {
                using (Request _request = new Request())
                {
                    _request.MethodName = "user.login";
                    _request.Parameters.Add("username", userName);
                    _request.Parameters.Add("password", password);

                    using (Response _response = Service.Instance.PostRequest(_request))
                    {
                        // Parse response
                        User _result = new User();
                        if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                        {
                            XmlNodeList _list = _response.GetElementsByTagName("rsp");
                            if (_list.Count > 0)
                            {
                                foreach (XmlNode _node in _list)
                                {
                                    _result.Name         = _node.SelectSingleNode("name").InnerText.Trim();
                                    _result.SessionKey   = _node.SelectSingleNode("session_key").InnerText.Trim();
                                    _result.UserId       = int.Parse(_node.SelectSingleNode("user_id").InnerText.Trim());
                                    _result.UserName     = _node.SelectSingleNode("username").InnerText.Trim();
                                    _result.m_isLoggedIn = true;

                                    newUser = _result;

                                    _args.Success = true;
                                    _args.User    = _result;

                                    if (!verifyOnly)
                                    {
                                        Service.Instance.InternalUser = _result;
                                        Service.Instance.InternalUser.OnLoggedIn(_args);
                                    }

                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            if (!verifyOnly)
            {
                // ??? It seems wrong to leave any previous 'logged in' user in tact. Code setting 'logged_in' flag to false.
                // but that flag doesn't do anything. Seems like clearing the Service.InternalUser is the right thing to do.
                Service.Instance.InternalUser.m_isLoggedIn = false;
            }

            _args.Success = false;

            // Notify subscribers of failure.
            Service.Instance.InternalUser.OnLoginFailed(_args);

            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Signs a user up for Scribd.  Doing so will log the 
        /// current user profile out and replace it with this one.
        /// </summary>
        /// <param name="userName">Username to associate with your Scribd account</param>
        /// <param name="password">Password to associate with your Scribd account</param>
        /// <param name="email">Your email address</param>
        /// <param name="name">Your real name</param>
        /// <returns>True on success</returns>
        public static bool Signup(string userName, string password, string email, string name)
        {
            UserEventArgs _args = new UserEventArgs();
            if (BeforeSignUp != null)
            {
                _args.Success = false;
                _args.User.UserName = userName;
                _args.User.Name = name;
            }

            if (!_args.Cancel)
            {
                using (Request _request = new Request())
                {
                    _request.MethodName = "user.signup";
                    _request.Parameters.Add("username", userName);
                    _request.Parameters.Add("password", password);
                    _request.Parameters.Add("email", email);
                    _request.Parameters.Add("name", name);

                    User cachedUser = Service.Instance.InternalUser;
                    Service.Instance.InternalUser = null;

                    using (Response _response = Service.Instance.PostRequest(_request))
                    {
                        Service.Instance.InternalUser = cachedUser;

                        // Parse response
                        User _result = new User();
                        if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                        {
                            XmlNodeList _list = _response.GetElementsByTagName("rsp");
                            if (_list.Count > 0)
                            {
                                foreach (XmlNode _node in _list)
                                {
                                    _result.Name = _node.SelectSingleNode("name").InnerText.Trim();
                                    _result.SessionKey = _node.SelectSingleNode("session_key").InnerText.Trim();
                                    _result.UserId = int.Parse(_node.SelectSingleNode("user_id").InnerText.Trim());
                                    _result.UserName = _node.SelectSingleNode("username").InnerText.Trim();
                                    _result.m_isLoggedIn = true;

                                    // Notify subscribers of sign-up success.
                                    _args.Success = true;
                                    _args.User = _result;
                                    if (User.AfterSignUp != null)
                                    {
                                        User.AfterSignUp(null, _args);
                                    }

                                    return true;
                                }
                            }
                        }
                    }
                }
            }

            _args.Success = false;
            if (User.AfterSignUp != null)
            {
                User.AfterSignUp(null, _args);
            }

            return false;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Clear the currently logged in user state.
        /// </summary>
        /// <returns>true means there no currently logged in user.</returns>
        public static bool Logout()
        {
            UserEventArgs _args = new UserEventArgs();

            if (BeforeLogout != null)
            {
                User.BeforeLogout(null, _args);
            }

            if (!_args.Cancel)
            {
                Service.Instance.InternalUser = new User();
                _args.Success = true;
            }
            else
            {
                _args.Success = false;
            }

            if (AfterLogout != null)
            {
                User.AfterLogout(null, _args);
            }

            return _args.Success;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Logs a user into the service.
        /// </summary>
        /// <param name="userName">Username associated with your Scribd account</param>
        /// <param name="password">Password associated with your Scribd account</param>
        /// <param name="verifyOnly">Just verifying credentials, don't change state of 'logged in' user</param>
        /// <param name="newUser">(out) Can be used by called to get the newly created User</param>
        /// <returns>True on success</returns>
        private static bool _Login(string userName, string password, bool verifyOnly, out User newUser)
        {
            UserEventArgs _args = new UserEventArgs();
            if (BeforeLogin != null)
            {
                _args.Success = false;
                _args.User.UserName = userName;
            }

            newUser = null;

            if (!_args.Cancel)
            {
                using (Request _request = new Request())
                {
                    _request.MethodName = "user.login";
                    _request.Parameters.Add("username", userName);
                    _request.Parameters.Add("password", password);

                    using (Response _response = Service.Instance.PostRequest(_request))
                    {
                        // Parse response
                        User _result = new User();
                        if (_response != null && _response.HasChildNodes && _response.ErrorList.Count < 1)
                        {
                            XmlNodeList _list = _response.GetElementsByTagName("rsp");
                            if (_list.Count > 0)
                            {
                                foreach (XmlNode _node in _list)
                                {
                                    _result.Name = _node.SelectSingleNode("name").InnerText.Trim();
                                    _result.SessionKey = _node.SelectSingleNode("session_key").InnerText.Trim();
                                    _result.UserId = int.Parse(_node.SelectSingleNode("user_id").InnerText.Trim());
                                    _result.UserName = _node.SelectSingleNode("username").InnerText.Trim();
                                    _result.m_isLoggedIn = true;

                                    newUser = _result;

                                    _args.Success = true;
                                    _args.User = _result;

                                    if (!verifyOnly)
                                    {
                                        Service.Instance.InternalUser = _result;
                                        Service.Instance.InternalUser.OnLoggedIn(_args);
                                    }

                                    return true;
                                }
                            }
                        }
                    }
                }
            }

            if (!verifyOnly)
            {
                // ??? It seems wrong to leave any previous 'logged in' user in tact. Code setting 'logged_in' flag to false.
                // but that flag doesn't do anything. Seems like clearing the Service.InternalUser is the right thing to do.
            Service.Instance.InternalUser.m_isLoggedIn = false;
            }

            _args.Success = false;

            // Notify subscribers of failure.
            Service.Instance.InternalUser.OnLoginFailed(_args);

            return false;
        }