Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context, RoleManager <ApplicationRole> roleManager, UserManager <ApplicationUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();

            app.UseAuthorization();

            AccountInitializer.SeedData(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider, userManager, roleManager);

            app.UseStaticFiles();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Beispiel #2
0
        //original version

        /* public string CreateAccount(string password, string path)
         * {
         *  //Generate a private key pair using SecureRandom
         *  var ecKey = Nethereum.Signer.EthECKey.GenerateKey();
         *  //Get the public address (derivied from the public key)
         *  var address = ecKey.GetPublicAddress();
         *
         *  //Create a store service, to encrypt and save the file using the web3 standard
         *  var service = new KeyStoreService();
         *  var encryptedKey = service.EncryptAndGenerateDefaultKeyStoreAsJson(password, ecKey.GetPrivateKeyAsBytes(), address);
         *  var fileName = service.GenerateUTCFileName(address);
         *  //save the File
         *  using (var newfile = File.CreateText(Path.Combine(path, fileName)))
         *  {
         *      newfile.Write(encryptedKey);
         *      newfile.Flush();
         *  }
         *
         *  return fileName;
         * }*/

        //implements IFiber
        public IEnumerator StartWorker()
        {
            Error = null;
            var ks = PlayerPrefs.GetString(KEY_PREFIX + "_key_store", "");

            subject_.OnNext(new Event {
                Type = EventType.InitStart
            });
            worker_ = new AccountInitializer(this, ks, encyption_);
            worker_.Start();
            yield return(this);

            if (Error != null)
            {
                yield return(Error);
            }
        }
Beispiel #3
0
 void Update()
 {
     if (worker_ != null)
     {
         Thread.MemoryBarrier();
         if (worker_.result_ != 0)
         {
             if (worker_.result_ < 0)
             {
                 Error = new System.Exception(
                     "AccountInitializer fails with code:" + worker_.result_);
                                 #if UNITY_EDITOR
                 UnityEditor.EditorApplication.isPlaying = false;
                                 #else
                 Application.Quit();
                                 #endif
             }
             else
             {
                 var ks = worker_.keyStore_;
                 if (!string.IsNullOrEmpty(ks))
                 {
                     PlayerPrefs.SetString(KEY_PREFIX + "_key_store", ks);
                     PlayerPrefs.SetInt(KEY_PREFIX + "_key_store_encyption",
                                        (int)(encyption_ ? Encyption.On : Encyption.Off));
                     PlayerPrefs.Save();
                 }
                 //Get the public address (derivied from the public key)
                 address_ = key_.GetPublicAddress();
                 subject_.OnNext(new Event {
                     Type = EventType.InitSuccess
                 });
                 Debug.Log("wallet address:" + address_ + " pkey:" + key_.GetPrivateKey());
             }
             worker_ = null;
         }
     }
 }
Beispiel #4
0
        public static async Task Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var userManager  = services.GetRequiredService <UserManager <Account> >();
                    var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    var options      = services.GetRequiredService <IOptions <InitialAuthSettings> >();
                    await AccountInitializer.InitializeAsync(userManager, rolesManager, options);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            await host.RunAsync();
        }