public async Task <IActionResult> CreateAdminAsync([FromBody] CreateAdmin command) { var adminTuple = await _adminService.AddAsync(command); var adminDto = _mapper.Map <AdminDto>(adminTuple.Admin); adminDto.Login = adminTuple.Login; return(Created($"{Request.Host}{Request.Path}/{adminTuple.Admin.Id}", adminDto)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCookiePolicy(); //app.UseHangfireDashboard(); // app.UseHangfireServer(); app.UseStaticFiles(); //app.UseSession(); //app.Run(async (context) => //{ // await context.Response.WriteAsync("Hello World!"); //}); app.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "areas", pattern: "{area:exists}/{controller=Dashboard}/{action=Index}/{id?}"); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); //app.UseMvc(routes => //{ // routes.MapRoute( // name: "areas", // template: "{area:exists}/{controller=Dashboard}/{action=Index}/{id?}"); // routes.MapRoute( // name: "default", // template: "{controller=Home}/{action=Index}/{id?}"); //} //); CreateAdmin.CreateAdminAccount(app.ApplicationServices, Configuration).Wait(); }
public async Task <(Admin Admin, string Login)> AddAsync(CreateAdmin command) { var login = RandomStringGenerator.GenerateUnique(); var loginHash = _hashManager.CalculateDataHash(_hashManager.CalculateDataHash(login).ToString()); if (await _context.Admins.ExistsInDatabaseAsync(command.Nick, loginHash) == true) { throw new CorruptedOperationException("Admin already exists."); } _hashManager.CalculatePasswordHash(command.Password, out var passwordHash, out var salt); var restoreKey = PasswordGenerator.GenerateRandomPassword(); var admin = new Admin(command.Nick, loginHash, salt, passwordHash, restoreKey); await _context.Admins.AddAsync(admin); await _context.SaveChangesAsync(); return(admin, login); }
public async Task <IActionResult> Create([FromBody] CreateAdmin command) { await _adminIdentityService.CreateAdmin(command.Email); return(Ok()); }