public async Task <IHttpActionResult> IssueCurrency(IssueCurrencyModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var blockchain = await _blockchainStore.GetBlockchainByChainString(model.Blockchain); var keys = RsaTools.LoadKeysFromFile(blockchain.ChainString); var signature = new BigInteger(model.BlindSignature); if (!RsaTools.VerifySignature(model.Token, signature, keys.Private)) { return(Unauthorized()); } MultichainModel chain; if (!_multichaind.Connections.TryGetValue(model.Blockchain, out chain)) { return(NotFound()); } var txId = await chain.IssueVote(model.WalletId); string words; do { words = string.Join(" ", RandomWordsGenerator.GetRandomWords()); } while (await chain.CheckMagicWordsNotOnBlockchain(words, model.WalletId)); return(Ok(new { TxId = txId, RegistrarAddress = blockchain.WalletId, Words = words })); } catch (RecordNotFoundException) { return(NotFound()); } }
public static async Task SeedTestData(AccountDbContext context, IServiceProvider services) { // exit early if any existing data is present if (context.Users.Any()) { return; } RandomWordsGenerator fn = new RandomWordsGenerator("https://raw.githubusercontent.com/dominictarr/random-name/master/first-names.txt"); RandomWordsGenerator ln = new RandomWordsGenerator("https://raw.githubusercontent.com/arineng/arincli/master/lib/last-names.txt"); RandomStringGenerator phone = new RandomStringGenerator(); var userManager = services.GetRequiredService <UserManager <AppUser> >(); Random random = new Random(); string[] levels = new string[] { "Admin", "Staff", "Customer" }; for (int i = 0; i < 100; i++) { string role = levels[random.Next(levels.Length)]; string firstName = fn.GetWord(); string lastName = ln.GetWord(); AppUser user = new AppUser() { Email = firstName + lastName + "@example.com", UserName = firstName + lastName + "@example.com", FullName = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(firstName) + " " + System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(lastName), PhoneNumber = role.Equals("Admin") || role.Equals("Staff") ? "07" + phone.GenerateRandomString(9, "0123456789") : null }; await userManager.CreateAsync(user, ".Password123"); // auto confirm email addresses for test users var token = await userManager.GenerateEmailConfirmationTokenAsync(user); await userManager.ConfirmEmailAsync(user, token); await userManager.AddToRoleAsync(user, role); } AppUser[] users = { new AppUser { UserName = "******", Email = "*****@*****.**", FullName = "Example Admin User", PhoneNumber = "07" + phone.GenerateRandomString(9, "0123456789") }, new AppUser { UserName = "******", Email = "*****@*****.**", FullName = "Example Staff User", PhoneNumber = "07" + phone.GenerateRandomString(9, "0123456789") }, new AppUser { UserName = "******", Email = "*****@*****.**", FullName = "Robert 'Bobby' Robertson" }, new AppUser { UserName = "******", Email = "*****@*****.**", FullName = "Bethany 'Betty' Roberts" } }; foreach (var user in users) { await userManager.CreateAsync(user, ".Password123"); // auto confirm email addresses for test users var token = await userManager.GenerateEmailConfirmationTokenAsync(user); await userManager.ConfirmEmailAsync(user, token); } await userManager.AddToRoleAsync(users[0], "Admin"); await userManager.AddToRoleAsync(users[1], "Staff"); await userManager.AddToRoleAsync(users[2], "Customer"); await userManager.AddToRoleAsync(users[3], "Customer"); }