Exemple #1
0
		public override async Task ExecuteAsync()
		{
			RenderTitle();
			Console.CursorVisible = true;

			var username = InputHelpers.InputNonEmptyString("Username: "******"First Name: ");
			var lastName = InputHelpers.InputString("Last Name: ");
			var password = "******";
			var confirmPassword = "******";

			while (password != confirmPassword || password.Trim().Length < 3)
			{
				password = InputHelpers.InputPassword("Password: "******"Confirm Password: "******"Error: Password and Confirmation Password are mismatched.");
					Console.WriteLine();
				}

				if (password.Trim().Length < 3)
				{
					Console.WriteLine();
					Console.WriteLine("Error: Password must contain at least 3 characters.");
					Console.WriteLine();
				}
			}

			var signUpMsg = await Context.HttpClient.PostAsJsonAsync(new Uri(Context.ApiUri, "account/signup"), new { username, firstName, lastName, password });

			Console.WriteLine();

			if (signUpMsg.StatusCode == HttpStatusCode.BadRequest)
			{
				OutputHelpers.Notify("Error: Username is registered.");
			}
			else if (signUpMsg.IsSuccessStatusCode)
			{
				OutputHelpers.Notify("Your account has been created.");
			}
			else
			{
				OutputHelpers.Notify("Error: Unknown. Please try again later.");
			}

			if (Context.CommandStack.Count > 0)
				await Context.CommandStack.Pop().ExecuteAsync();
		}
Exemple #2
0
        public override async Task ExecuteAsync()
        {
            RenderTitle();
            Console.CursorVisible = true;

            var username = InputHelpers.InputNonEmptyString("Username: "******"Password: "******"account/signin"), new { username, password });

            Console.WriteLine();

            if (signInMsg.StatusCode == HttpStatusCode.Unauthorized)
            {
                OutputHelpers.Notify("Error: Username or password are incorrect.");

                if (Context.CommandStack.Count > 0)
                {
                    await Context.CommandStack.Pop().ExecuteAsync();
                }
            }
            else if (signInMsg.IsSuccessStatusCode)
            {
                var tokenInfo = await signInMsg.Content.ReadAsAsync <TokenInfo>();

                await Context.SetTokenAsync(tokenInfo.Token);
            }
            else
            {
                OutputHelpers.Notify("Error: Unknown. Please try again later.");

                if (Context.CommandStack.Count > 0)
                {
                    await Context.CommandStack.Pop().ExecuteAsync();
                }
            }
        }