/// <summary>Creates a Person in the DB. The Person object has no knowledge of ASP.Net Identity. The Person's Guid will be /// the same as the ID of the IdentityUser's Id, which is a Guid stored as a string.</summary> /// <param name="userGuid">The guid that the identity system will use to refer to this Person.</param> /// <param name="db">The databse context.</param> /// <returns>Awaitable, waiting the save on the database.</returns> private async Task CreatePerson(Guid userGuid, QbDbContext db) { // The update and create dates are auto-initialised. var person = new Person { Id = userGuid }; db.People.Add(person); await db.SaveChangesAsync(); }
public ImportController(QbDbContext db) { _db = db; }
public SuppliersController(QbDbContext context) { _context = context; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, QbDbContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitializer.Initialize(context); }
public BagsController(QbDbContext context, IHostingEnvironment hostingEnvironment) { _context = context; _hostingEnvironment = hostingEnvironment; }
public CategoriesController(QbDbContext context) { _context = context; }
/// <summary>Initialise with a dbContext, per request and a logger for errors.</summary> /// <param name="db">Database context, should last per request.</param> /// <param name="loggerFactory">ASP Core logger.</param> /// <param name="userManager">ASP Identity user manager.</param> public SyncController(QbDbContext db, ILoggerFactory loggerFactory, OpenIddictUserManager <QbUser> userManager) { _db = db; _userManager = userManager; _logger = loggerFactory.CreateLogger <SyncController>(); }
public async Task <IActionResult> Register(string username, string password, string phonenumber, [FromServices] ISmsSender smsSender, [FromServices] QbDbContext db) { var pars = new[] { username, password, phonenumber }; if (pars.Any(string.IsNullOrWhiteSpace)) { return(Res.JsonErrorResult("missing_field", 400, "One or more of required fields missing or empty: username, password, phonenumber.")); } var exists = null != await _userManager.FindByNameAsync(username); if (exists) { return(Res.JsonErrorResult("exists", 400, "Username already exists.")); } var user = new QbUser { UserName = username, PhoneNumberConfirmed = false }; var res = await _userManager.CreateAsync(user, password); if (res.Succeeded) { user = await _userManager.FindByNameAsync(username); // Creates a full user with all edit abilities for own information. var userGuid = new Guid(user.Id); // Create a Person with the same guid as the identity user. await CreatePerson(userGuid, db); var phoneToken = await _userManager.GenerateChangePhoneNumberTokenAsync(user, phonenumber); // Ignore used for manual admin verified user. if (phonenumber.ToLowerInvariant() != "ignore") { if (!await smsSender.SendSms($"QB sign-up code:{phoneToken}", phonenumber)) { return (Res.JsonErrorResult("invalid_phone", 400, "User created but sms failed, try re-requesting code by changing phonenumber.")); } } return(Res.PlainUtf8($"User {username} successfully created, needs verification.")); } return(Res.JsonErrorResult("identity_error", 400, res.PrettyErrors())); }