Ejemplo n.º 1
0
        private static int DisplayMenu(User user)
        {
            var index = 1;
            Console.WriteLine("Mobile Api Client");
            Console.WriteLine();
            if (user == null || user.Token == null)
            {
                Console.WriteLine(index++ + ". Login");
                Console.WriteLine(index + ". Register");
            }
            else
            {
                Console.WriteLine(index++ + ". Get All Text");
                Console.WriteLine(index++ + ". Get Text");
                Console.WriteLine(index++ + ". Create Text");
                Console.WriteLine(index++ + ". Update Text");
                Console.WriteLine(index++ + ". Delete Text");
                Console.WriteLine(index + ". Exit");
            }

            var result = Console.ReadLine();

            return Convert.ToInt32(result);
        }
Ejemplo n.º 2
0
        public bool Login(string user, string password)
        {
            // hash password
            var data = Encoding.ASCII.GetBytes(password);
            var sha1 = new SHA1CryptoServiceProvider();
            var sha1Password = sha1.ComputeHash(data);

            var client = new RestClient(_url);
            var request = new RestRequest("login", Method.POST);
            request.AddParameter("username", user);
            request.AddParameter("password", Convert.ToBase64String(sha1Password));

            var response = client.Execute<User>(request);
            Console.WriteLine(response.Content);

            User = response.Data;
            return User.Token != null;
        }