public User(IAppUser user) { FirstName = user.FirstName; LastName = user.LastName; Email = user.Email; Password = user.Password; }
public UserModel(IAppUser user) { UserId = user.UserId; FirstName = user.FirstName; LastName = user.LastName; Password = user.Password; Email = user.Email; Roles = user.Roles; }
public async Task SignInAsync(IAppUser user) { if (!string.IsNullOrWhiteSpace(user.UserName)) { var claims = new List<Claim> { new Claim(ClaimTypes.Name, user.UserName), new Claim(ClaimTypes.Email, user.Email), new Claim(ClaimTypes.Sid,user.Id.ToString()) }; var identity = new ClaimsIdentity(claims, "Basic", "name", "role"); await Context.Authentication.SignInAsync("Cookies", new ClaimsPrincipal(identity)); } }
/// <summary> /// 更新实体 /// </summary> /// <param name="entity">实体对象</param> /// <param name="user">操作人</param> /// <returns></returns> public virtual Result Update(T entity, IAppUser user, Action Cb = null) { var error = ValidateUpdate(entity, user); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.AuthFail(error)); } entity.BeforeUpdate(user); var row = db.Update <T>(entity); if (row > 0) { Cb?.Invoke(); return(ResultUtil.Success()); } else { return(ResultUtil.Fail()); } }
/// <summary> /// Asynchronously determines whether the user is in the named role. /// </summary> /// <param name="user">user as IAppUser</param> /// <param name="roleName">roleName as string name of role</param> /// <returns>returns true or false</returns> public async Task <bool> IsInRoleAsync(IAppUser user, string roleName) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } if (string.IsNullOrWhiteSpace(roleName)) { throw new ArgumentNullException("roleName"); } var role = await _roleRepository.FindByNameAsync(roleName); if (role == null) { throw new InvalidOperationException("role not found"); } return(await _userRoleRepository.IsInRoleAsync(user.Id, role.Id)); }
/// <summary> /// Initializes a new instance of the <see cref="PermissionEvaluator" /> class. /// </summary> /// <param name="user">The user.</param> /// <param name="resourceId">The resource type identifier.</param> /// <param name="permissionStore">The permission store.</param> /// <param name="adminRoleName">Name of the admin role.</param> public PermissionEvaluator(IAppUser user, long resourceId, IPermissionStore permissionStore, string adminRoleName = "Admin") { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (permissionStore == null) { throw new ArgumentNullException(nameof(permissionStore)); } User = user; this.resourceId = resourceId; this.permissionStore = permissionStore; this.adminRoleName = adminRoleName; if (user.Roles != null) { userRoles = user.Roles.Values.ToDictionary(c => c.RoleNumber); } }
public Result Delete(int id, IAppUser user) { try { var entity = _db.Load <AssetCate>(id); if (entity == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "请求的数据不存在")); } var childrenCount = _db.GetCount <AssetCate>(MySearchUtil.New() .AndEqual("ParentId", id) .AndEqual("IsDel", false)); if (childrenCount > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "下属类别不为空,禁止删除")); } var assetsCount = _db.GetCount <Asset>(MySearchUtil.New() .AndEqual("AssetCateId", id) .AndEqual("IsDel", false)); if (assetsCount > 0) { return(ResultUtil.Do(ResultCodes.验证失败, "下属资产不为空,禁止删除")); } var row = _db.Remove <AssetCate>(id); if (row > 0) { AssetCateUtil.Clear(); return(ResultUtil.Success()); } return(ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); } catch (Exception ex) { return(ResultUtil.Exception(ex)); } }
public async Task <RegisterUserResult> RegisterUserAsync(IAppUser appUser) { RegisterUserResult registerUserResult = new RegisterUserResult(); registerUserResult.User = null; if (!String.IsNullOrEmpty(appUser.Password) && appUser.Password.Length < _appSettings.Password_MinLength) { registerUserResult.State = RegisterUserState.PasswordTooSmall; return(registerUserResult); } if (String.IsNullOrEmpty(appUser.Email) || !this._emailValidatorService.IsValid(appUser.Email)) { registerUserResult.State = RegisterUserState.InvalidEmail; return(registerUserResult); } // TODO: Check if it's a temporary email or a spam email. if (await _appUserStore.EmailExistsAsync(appUser.Email)) { registerUserResult.State = RegisterUserState.EmailExists; return(registerUserResult); } appUser.UserName = StringUtils.GenerateRandomString(8); appUser.Email = this._sanitizerService.SanitizeHTML(appUser.Email); appUser.Password = await _passwordService.HashPasswordAsync(appUser.Password); await _appUserStore.CreateAsync(appUser as AppUser); appUser.Id = await _appUserStore.GetLastInsertedUserId(); registerUserResult.State = RegisterUserState.Success; registerUserResult.User = appUser; return(registerUserResult); }
public BaseController(IUserProvider UserProvider) { System.Web.HttpContext currentContext = System.Web.HttpContext.Current; //add to session if (currentContext.Session[AppConstants.UserKey] == null) { //Get User Details to add to the session IAppUser appUser = UserProvider.GetUserContext(currentContext.User.Identity.Name); currentContext.Session[AppConstants.UserKey] = appUser; } //get from session add to property if (currentContext.Session[AppConstants.UserKey] != null) { AppUser = (IAppUser)currentContext.Session[AppConstants.UserKey]; } ResolveUnity(AppUser.Region); }
/// <summary> /// Asynchronously adds a claim to a user. /// </summary> /// <param name="user">user as IAppUser</param> /// <param name="claim">user as Claim</param> public async Task AddClaimAsync(IAppUser user, Claim claim) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } if (claim == null) { throw new ArgumentNullException("claim"); } //to do необходимо подменить параметр на инжектор //to do можно ли так приводить (_userClaimRepository as IRepositoryBase <IUserClaim>).Add(new UserClaim { UserId = user.Id, ClaimType = claim.Type, ClaimValue = claim.Value }); await _uow.SaveChangesAsync(); }
public static async Task <bool> SignInAsync(this HttpContext httpContext, IAppUser appUser) { var claims = new List <Claim>() { new Claim(ClaimTypes.Name, appUser.UserName) }; claims.Add(new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(appUser))); var identity = new ClaimsIdentity(claims, ApiAuthSchemes.DefaultAuthScheme); var principal = new ClaimsPrincipal(identity); var authProperties = new AuthenticationProperties { AllowRefresh = true, ExpiresUtc = DateTimeOffset.Now.AddDays(365), IsPersistent = true, }; await httpContext.SignInAsync(ApiAuthSchemes.DefaultAuthScheme, principal, authProperties); return(principal.Identity.IsAuthenticated); }
/// <summary> /// Asynchronously removes a role from a user. /// </summary> /// <param name="user">user as IAppUser</param> /// <param name="roleName">roleName as string name of role</param> public async Task RemoveFromRoleAsync(IAppUser user, string roleName) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } if (string.IsNullOrWhiteSpace(roleName)) { throw new ArgumentNullException("roleName"); } var role = await _roleRepository.FindByNameAsync(roleName); if (role == null) { throw new InvalidOperationException("role not found"); } //to do можно ли так приводить ? (_userRoleRepository as IRepositoryBase <IUserRole>).Remove(r => r.UserId == user.Id && r.RoleId == role.Id); await _uow.SaveChangesAsync(); }
public Result Delete(T t, IAppUser user) { try { if (t == null) { return(ResultUtil.Do(ResultCodes.数据不存在, 0, "请求的数据不存在")); } var error = ValidDelete(t, user); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.Do(ResultCodes.验证失败, 0, error)); } var row = db.Remove <T>(t.Id); return(row > 0 ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); } catch (Exception ex) { return(ResultUtil.Exception(ex)); } }
/// <summary> /// 配置盘点明细 /// </summary> /// <param name="stockId">盘点ID</param> /// <param name="assetIds">要盘点的资产ID数组</param> /// <param name="user">记录创建人</param> /// <returns></returns> public Result SetItems(int stockId, int[] assetIds, IAppUser user) { var sql = "SELECT AssetId FROM Asset_StockItem WHERE StockId=@Id AND IsDel=0"; var ids = db.FetchBySql <int>(sql, new { Id = stockId }).ToList(); var realIds = ids.Any() ? assetIds.Where(id => !ids.Contains(id)).ToList() : assetIds.ToList(); if (realIds.Count == 0) { return(ResultUtil.Do(ResultCodes.数据不存在, "所选资产已存在")); } sql = @" INSERT INTO [Asset_StockItem] ( StockId,IsFinish,AssetId,AssetCode,AssetName,DeptId,DeptName,AccountId,AccountName,Position, CheckAt,CheckBy,Checkor,CheckResult,CheckMethod,Remark,IsDel,CreateAt,CreateBy,Creator,UpdateAt,UpdateBy,Updator, FinancialCode,Healthy,[State]) SELECT @StockId,0,Id,Code,Name,DeptId,DeptName,AccountId,AccountName,Position,null,null,null,0,null,'',0, GETDATE(),@UserId,@UserName,GETDATE(),@UserId,@UserName,FinancialCode,Healthy,State FROM [AssetView] WHERE IsDel=0 AND Id IN @Ids"; var rows = db.Execute(sql, new { StockId = stockId, Ids = realIds, UserId = user.Id, UserName = user.Name }); return(rows > 0 ? ResultUtil.Success(rows) : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库操作失败")); }
public override Result <int> Create(Stock t, IAppUser user) { t.IsFinish = false; var error = ValidCreate(t, user); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.Do(ResultCodes.验证失败, 0, error)); } t.BeforeCreate(user); //KeyValuePairList sqls = new KeyValuePairList(); //sqls.Add(db.GetCommonInsertSql<Stock>(), t); //sqls.Add("UPDATE Asset_Stock SET IsFinish=1,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE IsFinish=0", new //{ // UserId = user.Id, // UserName = user.Name //}); //sqls.Add("UPDATE Asset_StockItem SET IsFinish=1,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE IsFinish=0", new //{ // UserId = user.Id, // UserName = user.Name //}); //var result = db.ExecuteTran(sqls); var id = db.Create(t); const string sql = @" INSERT INTO [Asset_StockItem] ( StockId,IsFinish,AssetId,AssetCode,AssetName,DeptId,DeptName,AccountId,AccountName,Position, CheckAt,CheckBy,Checkor,CheckResult,CheckMethod,Remark,IsDel,CreateAt,CreateBy,Creator,UpdateAt,UpdateBy,Updator) SELECT @StockId,0,Id,Code,Name,DeptId,DeptName,AccountId,AccountName,Position,null,null,null,0,null,'',0, GETDATE(),@UserId,@UserName,GETDATE(),@UserId,@UserName FROM [AssetView] WHERE Code<>'' AND Code IS NOT NULL AND IsDel=0 AND [State]<>'报废'"; db.Execute(sql, new { StockId = id, UserId = user.Id, UserName = user.Name }); return(id > 0 ? ResultUtil.Success(0) : ResultUtil.Do(ResultCodes.数据库操作失败, 0)); }
public static void ShowCurrentUserProperties(IAppNetworkProviderService networkProvider) { using (var form = new CurrentUserPropertiesDemo()) { UserProperties up = new UserProperties(); IAppUser user = networkProvider.GetServer().Context(); up.Name = user.GetName(); up.FirstName = user.GetFirst_Name(); up.Group = user.GetGroup(); up.LastName = user.GetLast_Name(); up.Email = user.GetEmail(); up.ChangePasswordAtNextLogon = user.GetChangePasswordAtNextLogon(); up.CannotChangePassword = user.GetCannotChangePassword(); up.PasswordExpired = user.GetPasswordExpired(); up.Disabled = user.GetDisabled(); up.LockedOut = user.GetLockedOut(); up.RemainingLockOutMinutes = user.GetRemainingLockOutMinutes(); up.PasswordChangedAt = user.GetPasswordChangedAt(); up.LockedOutToDateTime = user.GetLockedOutToDateTime(); form.SetObject(up); form.StartPosition = FormStartPosition.CenterParent; form.ShowDialog(); } }
public Result <int> Update(AssetCate cate, IAppUser user) { try { var error = Validate(cate); if (!string.IsNullOrWhiteSpace(error)) { return(ResultUtil.Do(ResultCodes.验证失败, 0, error)); } if (cate.ParentId == cate.Id) { return(ResultUtil.Do(ResultCodes.验证失败, 0, "不能将自身设置为上级")); } var children = AssetCateUtil.GetSelfAndChildrenIds(cate.Id); if (children.Contains(cate.ParentId)) { return(ResultUtil.Do(ResultCodes.验证失败, 0, "不能将上级分类指定为其下属")); } cate.BeforeUpdate(user); var row = _db.Update(cate); if (row > 0) { AssetCateUtil.Clear(); return(ResultUtil.Success(cate.Id)); } return(ResultUtil.Do(ResultCodes.数据库操作失败, 0, "数据写入失败")); } catch (Exception ex) { return(ResultUtil.Exception(ex, 0)); } }
public override string ValidCreate(ServiceApplication entity, IAppUser user) { if (entity.DeptId <= 0) { return("申请部门不能为空"); } if (string.IsNullOrWhiteSpace(entity.AccountName)) { return("申请人不能为空"); } if (!ValidDate(entity.RequireCompleteAt)) { return("要求办结时间不合法"); } if (!ValidDate(entity.ApplyAt)) { return("申请日期不合法"); } return(string.Empty); }
private void SetRedisData(IAppUser user) { const string keyBySubjectId = "IdentityServer/OpenId/subjectId/{0}"; // <== contains the full data const string keyByUsername = "******"; // <== contains a link to the SubjectId const string keyByProviderAndUserid = "IdentityServer/OpenId/provider/{0}/userId/{1}"; // <== contains a link to the SubjectId var userStr = JsonConvert.SerializeObject(user, _jsonSerializerSettings); var subjectIdStorageKey = string.Format(keyBySubjectId, user.SubjectId); // add user to Redis store var rdb = _redis.GetDatabase(); var foundUser = rdb.StringGet(string.Format(keyByProviderAndUserid, user.ProviderName, user.ProviderSubjectId)); if (foundUser.HasValue) { _logger.LogWarning($"This data should not be already in redis. {string.Format(keyByProviderAndUserid, user.ProviderName, user.ProviderSubjectId)}"); } // Add the parameter , _dataExpireIn if we want to expire the data. I don't know the impact if we do it. // Documentation is not clear about how this code is called. Probably it would be better to have a job running to update the claims in redis. rdb.StringSet(subjectIdStorageKey, userStr); rdb.StringSet(string.Format(keyByUsername, user.Username), subjectIdStorageKey); // Might cause issue... or hack... rdb.StringSet(string.Format(keyByProviderAndUserid, user.ProviderName, user.ProviderSubjectId), subjectIdStorageKey); }
/// <summary> /// 设置数据字典,如果键已存在则更新该记录,键不存在则新建记录 /// </summary> /// <param name="k">键</param> /// <param name="v">值</param> /// <param name="user">操作人</param> /// <returns></returns> public Result Set(string k, string v, IAppUser user) { var entity = db.Load <DataItemEntity>(MySearchUtil.New() .AndEqual("IsDel", false) .AndEqual("K", k.Trim())); if (entity == null) { entity = new DataItemEntity { K = k.Trim(), V = v.Trim() }; return(Create(entity, user, () => { DataItemUtil.Clear(); })); } else { entity.V = v; return(Update(entity, user)); } }
public override string ValidDelete(Asset entity, IAppUser user) { return(string.Empty); }
public override string ValidCreate(Asset entity, IAppUser user) => ValidUpdate(entity, user);
public Result Recovery(int assetId, DateTime recoveryAt, string pics, string newPosition, string remark, IAppUser user) { var asset = LoadDto(assetId); if (asset == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "请求的资产不存在")); } if (recoveryAt < DateTime.Parse("1900-1-1")) { return(ResultUtil.Do(ResultCodes.验证失败, "回收日期不得小于1900-1-1")); } var log = new AssetLog { AssetId = asset.Id, AssetName = asset.Name, AssetCode = asset.Code, FromAccountId = asset.AccountId, FromAccountName = asset.AccountName, FromDeptId = asset.DeptId, FromDeptName = asset.DeptName, TargetAccountId = 0, TargetAccountName = "", TargetDeptId = 0, TargetDeptName = "", Type = "回收", OperateAt = recoveryAt, Remark = remark + "\n回收后位置:" + newPosition, Pics = pics }; log.BeforeCreate(user); var sqls = new KeyValuePairList { { "UPDATE Asset_Asset SET [State]='闲置',Position=@Position,DeptId=0,AccountId=0,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id", new { Id = log.AssetId, UserID = user.Id, UserName = user.Name, Position = newPosition } }, { db.GetCommonInsertSql <AssetLog>(), log } }; var row = db.ExecuteTran(sqls); return(row ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); }
public Result Return(int loanId, DateTime returnAt, IAppUser user) { var loan = db.Load <Loan>(loanId); if (loan == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "借出记录不存在")); } if (loan.IsReturn) { return(ResultUtil.Do(ResultCodes.验证失败, "此借出记录已归还,请勿重复操作")); } var state = loan.FromDeptId == 0 ? "闲置" : "使用中"; var log = new AssetLog { AssetId = loan.AssetId, AssetCode = loan.AssetCode, AssetName = loan.AssetName, TargetAccountId = loan.FromAccountId, TargetAccountName = loan.FromAccountName, TargetDeptId = loan.FromDeptId, TargetDeptName = loan.FromDeptName, FromAccountId = loan.TargetAccountId, FromAccountName = loan.TargetAccountName, FromDeptId = loan.TargetDeptId, FromDeptName = loan.TargetDeptName, Type = "归还", OperateAt = loan.LoanAt, Pics = loan.Pics }; log.BeforeCreate(user); var sqls = new KeyValuePairList { { "UPDATE Asset_Asset SET [State]=@State,DeptId=@DeptId,Position=@Position,AccountId=@AccountId,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id", new { Id = loan.AssetId, State = state, DeptId = loan.FromDeptId, AccountId = loan.FromAccountId, UserID = user.Id, UserName = user.Name, Position = loan.FromPosition } }, { "UPDATE Asset_Loan SET IsReturn=1,ReturnAt=@ReturnAt,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id", new { Id = loanId, UserId = user.Id, UserName = user.Name, ReturnAt = returnAt } }, { db.GetCommonInsertSql <AssetLog>(), log } }; var row = db.ExecuteTran(sqls); return(row ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); }
public Result Loan(int assetId, int targetDeptId, int targetAccountId, DateTime loanAt, DateTime expectedReturnAt, string pics, string newPositon, string remark, IAppUser user) { // 验证参数 if (assetId <= 0) { return(ResultUtil.Do(ResultCodes.验证失败, "指定了无效的资产id")); } if (targetDeptId <= 0) { return(ResultUtil.Do(ResultCodes.验证失败, "指定了无效的部门id")); } if (loanAt < DateTime.Parse("1900-1-1") || expectedReturnAt < DateTime.Parse("1900-1-1")) { return(ResultUtil.Do(ResultCodes.验证失败, "借出和预计归还日期必须大于1900-1-1")); } if (loanAt > expectedReturnAt) { return(ResultUtil.Do(ResultCodes.验证失败, "预计归还日期必须大于等于借出日期")); } var loan = new Loan(); var asset = LoadDto(assetId); if (asset == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "资产不存在或已删除")); } if (asset.State == "借出" || asset.State == "报废") { return(ResultUtil.Do(ResultCodes.验证失败, "该资产已借出或已报废,禁止借出操作")); } if (targetAccountId > 0) { var accountService = new AccountService(); var account = accountService.Load(targetAccountId); if (account == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "目标使用人不存在或已删除")); } var dept = DeptUtil.Get(account.DeptId); if (dept == null) { throw new Exception("无法找到员工所属部门。员工ID:" + account.Id.ToString() + ";部门ID:" + account.DeptId.ToString()); } loan.TargetAccountId = targetAccountId; loan.TargetAccountName = account.Name; loan.TargetDeptId = targetDeptId; loan.TargetDeptName = dept.Name; } else { var dept = DeptUtil.Get(targetDeptId); if (dept == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "目标部门不存在或已删除")); } loan.TargetAccountId = 0; loan.TargetAccountName = ""; loan.TargetDeptId = dept.Id; loan.TargetDeptName = dept.Name; } loan.AssetId = asset.Id; loan.AssetCode = asset.Code; loan.AssetName = asset.Name; loan.FromAccountId = asset.AccountId; loan.FromAccountName = asset.AccountName; loan.FromDeptId = asset.DeptId; loan.FromDeptName = asset.DeptName; loan.LoanAt = loanAt; loan.ExpectedReturnAt = expectedReturnAt; loan.IsReturn = false; loan.ReturnAt = null; loan.Pics = pics; var log = new AssetLog { AssetId = loan.AssetId, AssetCode = loan.AssetCode, AssetName = loan.AssetName, FromAccountId = loan.FromAccountId, FromAccountName = loan.FromAccountName, FromDeptId = loan.FromDeptId, FromDeptName = loan.FromDeptName, TargetAccountId = loan.TargetAccountId, TargetAccountName = loan.TargetAccountName, TargetDeptId = loan.TargetDeptId, TargetDeptName = loan.TargetDeptName, Type = "借出", OperateAt = loan.LoanAt, Pics = loan.Pics }; loan.BeforeCreate(user); log.BeforeCreate(user); var sqls = new KeyValuePairList { { "UPDATE Asset_Asset SET [State]='借出',Position=@Position,DeptId=@DeptId,AccountId=@AccountId,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id", new { Id = log.AssetId, Position = newPositon, UserId = user.Id, UserName = user.Name, AccountId = log.TargetAccountId, DeptId = log.TargetDeptId } }, { db.GetCommonInsertSql <Loan>(), loan }, { db.GetCommonInsertSql <AssetLog>(), log } }; var row = db.ExecuteTran(sqls); return(row ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); }
public Result Scrap(int assetId, DateTime operateAt, string pics, string remark, IAppUser user) { var asset = LoadDto(assetId); if (asset == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "资产不存在或已删除")); } if (asset.State == "借出") { return(ResultUtil.Do(ResultCodes.验证失败, "该资产处于借出状态,禁止报废")); } var log = new AssetLog { AssetId = asset.Id, AssetName = asset.Name, AssetCode = asset.Code, FromAccountId = asset.AccountId, FromAccountName = asset.AccountName, FromDeptId = asset.DeptId, FromDeptName = asset.DeptName, TargetAccountId = 0, TargetAccountName = "", TargetDeptId = 0, TargetDeptName = "", Type = "报废", OperateAt = operateAt, Remark = remark, Pics = pics }; log.BeforeCreate(user); var sqls = new KeyValuePairList { { "UPDATE Asset_Asset SET [State]='报废',UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id", new { Id = log.AssetId, UserId = user.Id, UserName = user.Name } } }; log.BeforeCreate(user); sqls.Add(db.GetCommonInsertSql <AssetLog>(), log); var row = db.ExecuteTran(sqls); return(row ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); }
protected virtual bool ValidaLoginAutomatico(IAppUser u, string token) { return ObtemTokenParaLoginAutomatico(u, false, false).Equals(token); }
/// <summary> /// Fors the specified user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> public IOnUserPermission For(IAppUser user) { return(new OnUserPermissionImp(user, permissionStore, secProv)); }
public UserController(IAppUser appUser) { this.appUser = appUser; }
public zTestPageViewModel(IServiceMapper serviceMapper, IAppUser appUser) : base(serviceMapper, appUser) { FakePostFeeds.Init(); }
public static IAppOperator SaveAppOperator(IAppUser user) { return(App.GetService <T>().SaveAppOperator(user)); }
/// <summary> /// Gera um token (uma string) que pode ser usada para login automático, /// e salva no registro do usuário especificado. /// </summary> /// <param name="u">O usuário para gerar ou obter o hash</param> /// <param name="novo">Se <c>true</c>, cria um novo hash, senão, retorna o hash já salvo</param> /// <param name="apenasHash">Se <c>true</c>, retorna apenas o hash, sem criar o token</param> protected virtual string ObtemTokenParaLoginAutomatico(IAppUser u, bool novo, bool apenasHash) { if (novo) { Log.InfoFormat("Gerado novo token de login automático para o usuário #{0} ({1})", u.Id, u.Login); u.AutoLoginHash = GeraHashParaLoginAutomatico(); u.Save(); } var hash = CriptografaSenha(u.AutoLoginHash + ":" + u.Login + ":" + u.Password); return (apenasHash ? (hash) : (u.Id + ":" + hash)); }
public Result <int> Maintain(Maintain entity, IAppUser user) { var service = new MaintainService(); return(service.Create2(entity, user)); }
/// <summary> /// 转移资产 /// </summary> public Result Move(AssetLog log, string newPosition, IAppUser user) { var asset = LoadDto(log.AssetId); if (asset == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "指定的资产不存在或已删除")); } switch (asset.State) { case "报废": return(ResultUtil.Do(ResultCodes.数据不存在, "指定的资产已报废,禁止操作")); case "借出": return(ResultUtil.Do(ResultCodes.数据不存在, "指定的资产已借出,禁止操作")); } log.AssetCode = asset.Code; log.AssetName = asset.Name; if (log.OperateAt < DateTime.Parse("1900-1-1")) { return(ResultUtil.Do(ResultCodes.验证失败, "调配日期无效")); } DeptDto targetDept; if (log.TargetAccountId > 0) { var accountService = new AccountService(); var targetAccount = accountService.Load(log.TargetAccountId); if (targetAccount == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "目标用户不存在")); } targetDept = DeptUtil.Get(targetAccount.DeptId); if (targetDept == null) { throw new Exception("用户所在的部门信息不存在,请联系管理员"); } log.TargetAccountId = targetAccount.Id; log.TargetAccountName = targetAccount.Name; log.TargetDeptId = targetDept.Id; log.TargetDeptName = targetDept.Name; } else { targetDept = DeptUtil.Get(log.TargetDeptId); if (targetDept == null) { return(ResultUtil.Do(ResultCodes.数据不存在, "目标部门不存在")); } else { log.TargetDeptId = targetDept.Id; log.TargetDeptName = targetDept.Name; log.TargetAccountId = 0; log.TargetAccountName = ""; } } log.Type = "调配"; var sql = new KeyValuePairList { { "UPDATE Asset_Asset SET DeptId=@DeptId,@Position=@Position,AccountId=@AccountId,UpdateAt=GETDATE(),UpdateBy=@UserId,Updator=@UserName WHERE Id=@Id", new { Id = log.AssetId, Position = newPosition, DeptId = log.TargetDeptId, AccountId = log.TargetAccountId, UserId = user.Id, UserName = user.Name } } }; log.BeforeCreate(user); sql.Add(db.GetCommonInsertSql <AssetLog>(), log); var row = db.ExecuteTran(sql); return(row ? ResultUtil.Success() : ResultUtil.Do(ResultCodes.数据库操作失败, "数据库写入失败")); }
public UserRepository(IAppUser userInfo, AppDbContext dbContext) : base(userInfo, dbContext) { }
protected virtual void LimpaTokenAutoLogin(IRailsEngineContext ctx, IAppUser u) { Log.Info("Limpando cookie e token de auto-login para o usuário"); DefineCookieAutoLogin(null, DateTime.Today.AddDays(-10)); if (u != null) { u.AutoLoginHash = null; u.Save(); } }