Example #1
0
        public static async Task <string> StartSession()
        {
            Console.Write("Enter username: "******"Enter password: "******"/api/Users/Login");
            string jsonRequest   = JsonConvert.SerializeObject(loginInput);
            var    stringContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");

            request.Content = stringContent;
            var response = await client.SendAsync(request);

            var responseString = await response.Content.ReadAsStringAsync();

            var    responseJson = JsonConvert.DeserializeObject <LoginOutput>(responseString);
            string userToken    = responseJson.Token;

            return(userToken);
        }
Example #2
0
        public static void CreateNewAccount()
        {
            Console.Write("Enter username: "******"Enter password: "******"/api/Users/Register");
                string jsonRequest   = JsonConvert.SerializeObject(loginInput);
                var    stringContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
                request.Content = stringContent;
                var response       = client.SendAsync(request).GetAwaiter().GetResult();
                var responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                var responseJson   = JsonConvert.DeserializeObject <StatusOutput>(responseString);

                Console.WriteLine(responseJson.message);
                if (responseJson.message == "User created")
                {
                    Console.WriteLine("Login to your newly created account");
                    token = StartSession().GetAwaiter().GetResult();
                    ClientMenu();
                }
                else if (responseJson.message == "User already exists")
                {
                    Console.WriteLine("Please try again with a different username");
                    CreateNewAccount();
                }
                else
                {
                    Console.WriteLine("An error occured while trying to create an account, please try again");
                    CreateNewAccount();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }