public Func <HttpContext, object> Get() { return(ctx => { var userService = ctx.RequestServices.GetService <IUserService>(); if (ctx.User.Identity.IsAuthenticated) { var claim = ctx.User.FindFirst("sub"); if (claim != null) { var userId = NaryHelper.ToNary(claim.Value, 36); var authId = ctx.User.FindFirst("authid")?.Value ?? "none"; logger.LogDebug($"Sync user from \"{ctx.User.Identity.AuthenticationType}\" with \"{userId}:{authId}\""); return userService.QueryById(userId, authId); } else { logger.LogError($"Sync user from \"{ctx.User.Identity.AuthenticationType}\" with error"); return null; } } return userService.QueryByUserName("guest", "none"); }); }
public string Create(string name, string prefix, int length, bool autoSave, int?nary) { var value = ""; name += prefix; lock (SyncObj) { var seed = GetSeed(name); if (seed != null && seed.Value.Length != prefix.Length + length) { base.Delete(seed); seed = null; } if (seed == null) { value = $"{prefix}{"1".PadLeft(length, '0')}"; seed = new Sys_Seed(); seed.InitializeId(); seed.Name = name; seed.Value = $"{prefix}{"0".PadLeft(length, '0')}"; seed.DCreate = DateTime.Now; seed.DUpdate = DateTime.Now; base.Insert(seed); } else { var preVal = seed.Value.Substring(prefix.Length).ToUpper(); string curVal = null; if (!nary.HasValue) { if (int.TryParse(preVal, out int result)) { curVal = (++result).ToString(); } else { nary = 36; } } if (!curVal.HasValue()) { curVal = NaryHelper.FromNary(NaryHelper.ToNary(curVal, nary.Value) + 1, nary.Value); } value = prefix + curVal.PadLeft(length, '0'); } if (autoSave) { Save(name, value); } return(value); } }