public async Task ExecuteAsync(CommandBuilder builder, CommandContext context) { IOption username = builder.Option("-u", "Username"); IOption password = builder.Option("-p", "Password"); await context.OnExecuteAsync(async() => { if (!(username.HasValue() && password.HasValue())) { return(await context.ExitWithHelp()); } // find the user by using the UserService service UserModel user = _repository.GetUser(username.Value()); // check password if (user == null || user.Password != password.Value()) { return(await context.ExitWithErrorAsync("Invalid username or password.")); } // sign-in! ClaimsIdentity identity = new ClaimsIdentity("password"); identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName)); ClaimsPrincipal principal = new ClaimsPrincipal(identity); await context.HttpContext.SignInAsync("Demo", principal); context.HttpContext.User = principal; // initializer terminal after successful login _initializer.Initialize(context.Response, context.HttpContext, true); // exit and show simple message return(await context.ExitAsync($"Hello {user.UserName}!", ResponseMessageType.Success)); }); }
public IEnumerable <BTreeOption <T> > Decendents(bool fromRight = true) { yield return(this); if ((fromRight && right.HasValue(out BTreeOption <T> child)) || (!fromRight && left.HasValue(out child))) { foreach (BTreeOption <T> xChild in child.Decendents(fromRight)) { yield return(xChild); } } if ((fromRight && left.HasValue(out child)) || (!fromRight && right.HasValue(out child))) { foreach (BTreeOption <T> xChild in child.Decendents(fromRight)) { yield return(xChild); } } }
public async Task ExecuteAsync(CommandBuilder builder, CommandContext context) { // options IOption ls = builder.Option("-ls", "Lists all files.", OptionType.NoValue); IOption remove = builder.Option("-rm", "Removes a file by using the file id."); IOption removeAll = builder.Option("-ra", "Removes all files.", OptionType.NoValue); IOption download = builder.Option("-download", "Downloads a file by using the file id."); await context.OnExecuteAsync(async() => { bool succeed = false; // lists all files if (ls.HasValue()) { await ListFiles(context); succeed = true; } // removes a file by using the file id else if (remove.HasValue()) { string id = remove.Value(); await Remove(context, id); succeed = true; } // removes all files else if (removeAll.HasValue()) { await RemoveAll(context); succeed = true; } // downloads a file by using the file id else if (download.HasValue()) { string id = download.Value(); await Download(context, id); succeed = true; } if (!succeed) { return(await context.ExitWithHelpAsync()); } return(await context.ExitAsync()); }); }