コード例 #1
0
        public static bool RegisterShopper(string username, string firstname, string lastname, string email, string password)
        {
            const string endpoint = "auth/shoppers";
            var          client   = new RestClient(URL);
            var          request  = new RestRequest(endpoint, Method.POST);

            string jsonToSend = SerializeUser.ToJson(new UserModel
            {
                Username  = username,
                Password  = password,
                Email     = email,
                Firstname = firstname,
                Lastname  = lastname
            });

            request.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            bool success = false;

            try
            {
                IRestResponse response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    AuthModel authModel = AuthModel.FromJson(response.Content.ToString());
                    //SaveToken(authModel);
                    //SaveRefreshToken(authModel);
                    success = true;
                }
                else
                {
                    // NOK
                    Console.Write(response.ToString());
                }
            }
            catch (Exception error)
            {
                Console.Write(error.ToString());
            }

            return(success);
        }
コード例 #2
0
        public static string Login(string username = "", string password = "")
        {
            const string endpoint = "auth/login";
            var          client   = new RestClient(URL);
            var          request  = new RestRequest(endpoint, Method.POST);

            string jsonToSend = SerializeUser.ToJson(new UserModel
            {
                Username = username,
                Password = password
            });

            request.AddParameter("application/json; charset=utf-8", jsonToSend, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            string result = "";

            try
            {
                IRestResponse response = client.Execute(request);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    //                    string variable = session.GetString("Token");

                    result = response.Content.ToString();
                }
                else
                {
                    // NOK
                    Console.Write(response.ToString());
                }
            }
            catch (Exception error)
            {
                Console.Write(error.ToString());
            }

            return(result);
        }