/// <summary> /// 获取所有原料 /// </summary> /// <param name="token"></param> /// <returns></returns> public virtual List <Tat2010> GetMateriels(string token) { using (var db = new Db()) { TsUser tsUser = PermissionService.Proxy.GetTsUserByToken(token); var Materisels = db.GetTable <Tat2010>() .Where(x => x.CCompId.Equals(tsUser.CCompany)) .ToList(); return(Materisels); } }
/// <summary> /// 根据Token获取用户信息 /// </summary> /// <param name="token"></param> /// <returns></returns> public virtual TsUser GetTsUserByToken(string token) { TsUser tsUser = GetDbContext().GetTable <TsUser>() .FirstOrDefault(x => x.CSessionId.Equals(token)); if (tsUser == null) { throw new Exception("Token 错误,用户登录失效或用户不存在!"); } return(tsUser); }
/// <summary> /// 获取所有仓库仓位信息 /// </summary> /// <param name="token"></param> /// <returns></returns> public virtual List <Tat0230> GetStoreHouse(string token) { using (var db = new Db()) { TsUser tsUser = PermissionService.Proxy.GetTsUserByToken(token); var StoreHouses = db.GetTable <Tat0230>() .Where(x => x.CCompId.Equals(tsUser.CCompany)) .ToList(); return(StoreHouses); } }
/// <summary> /// 新增库位 /// </summary> /// <param name="token"></param> /// <param name="StroeHouse"></param> /// <returns></returns> public virtual int InsertStoreHouse(string token, Tat0230 StroeHouse) { using (var db = new Db()) { TsUser tsUser = PermissionService.Proxy.GetTsUserByToken(token); StroeHouse.CCompId = tsUser.CCompany; var Id = SequenceService.Proxy.GenerateLocalId(); StroeHouse.Id = Id; StroeHouse.TimeStamp = DateTime.Now; return(db.Insert(StroeHouse)); } }
/// <summary> /// 根据token获取用户信息 /// </summary> /// <param name="token"></param> /// <returns></returns> public virtual TsUser GetTsUserByToken(string token) { using (var db = new Db()) { TsUser tsUser = db.GetTable <TsUser>() .FirstOrDefault(x => x.CSessionId.Equals(token)); if (tsUser == null) { throw new Exception("Token 错误,用户不存在!"); } return(tsUser); } }
/// <summary> /// 增加原料 /// </summary> /// <param name="Materiel"></param> public virtual int InsertMateriel(string token, Tat2010 Materiel) { using (var db = new Db()) { TsUser tsUser = PermissionService.Proxy.GetTsUserByToken(token); Materiel.CCompId = tsUser.CCompany; var Id = SequenceService.Proxy.GenerateLocalId(); Materiel.Id = Id; Materiel.CMtrlNo = Id; Materiel.TimeStamp = DateTime.Now; return(db.Insert(Materiel)); } }
private async Task LoadSharedKeyAndQrCodeUriAsync(TsUser user) { // Load the authenticator key & QR code URI to display on the form var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); if (string.IsNullOrEmpty(unformattedKey)) { await _userManager.ResetAuthenticatorKeyAsync(user); unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); } SharedKey = FormatKey(unformattedKey); var email = await _userManager.GetEmailAsync(user); AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey); }
/// <summary> /// 用户注册 /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="phone"></param> /// <returns></returns> public virtual void Register(string username, string password, string name, string phone, string email, string compid) { if (GetUserByUserId(username) == null) { TsUser user = new TsUser { Id = username, CPassword = SimpleCipherHelper.Instance.MD5EncryptWithSalt(password, "rvmob"), CPhone = phone, CUsername = name, CCompany = compid, CEnable = "Y" }; GetDbContext().Insert(user); } else { throw new Exception("用户名被占用,请重新输入!"); } }
public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); // Get the information about the user from the external login provider var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { ErrorMessage = "Error loading external login information during confirmation."; return(RedirectToPage("./Login", new { ReturnUrl = returnUrl })); } if (ModelState.IsValid) { var user = new TsUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user); if (result.Succeeded) { result = await _userManager.AddLoginAsync(user, info); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } LoginProvider = info.LoginProvider; ReturnUrl = returnUrl; return(Page()); }
public virtual TsUser InsertOrUpdateUser(TsUser user, List <string> roleids) { using (var db = GetDbContext()) { db.InsertOrReplace(user); db.GetTable <TsUserRole>() .Delete(x => x.CUserId.Equals(user.Id)); if (roleids != null && roleids.Count > 0) { db.BulkCopy(roleids.Select(x => new TsUserRole { Id = SequenceService.Proxy.GenerateLocalId(), CUserId = user.Id, CRoleId = x })); } return(user); } }
public static async Task SeedUsers(UserManager <TsUser> userManager, RoleManager <IdentityRole> roleManager) { if (userManager.FindByEmailAsync("*****@*****.**").Result == null) { TsUser user = new TsUser { UserName = "******", Email = "*****@*****.**" }; IdentityResult result = userManager.CreateAsync(user, "admin123").Result; IdentityResult roleResult = roleManager.CreateAsync(new IdentityRole("Admin")).Result; if (result.Succeeded) { await userManager.AddToRoleAsync(user, "Admin"); } } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new TsUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="user"></param> public virtual void UpdateTsUser(TsUser user) { GetDbContext().Update(user); }
private async Task <bool> IsAdmin(TsUser user) { var roles = await GetUserRoles(user); return(roles.Any(s => s == "Admin")); }
private async Task <IList <string> > GetUserRoles(TsUser user) { return(await _manager.GetRolesAsync(user)); }