public async Task <GroupDto> GetAsync(long id) { LinGroup group = await _groupRepository.Where(r => r.Id == id).FirstAsync(); GroupDto groupDto = _mapper.Map <GroupDto>(group); groupDto.Permissions = await _permissionService.GetPermissionByGroupIds(new List <long>() { id }); return(groupDto); }
public void ResetPassword(int id, ResetPasswordDto resetPasswordDto) { bool userExist = _userRepository.Where(r => r.Id == id).Any(); if (userExist == false) { throw new LinCmsException("用户不存在", ErrorCode.NotFound); } string confirmPassword = LinCmsUtils.Get32Md5(resetPasswordDto.ConfirmPassword); _freeSql.Update <LinUser>(id).Set(a => new LinUser() { Password = confirmPassword }).ExecuteAffrows(); }
public async Task <UnifyResponseDto> UploadTagByJson() { string tagPath = Path.Combine(_hostingEnv.WebRootPath, "json-tag.json"); string text = System.IO.File.ReadAllText(tagPath); JObject json = JsonConvert.DeserializeObject <JObject>(text); foreach (var tag in json["d"]["tags"]) { string tagName = tag["title"].ToString(); bool valid = await _tagAuditBaseRepository.Where(r => r.TagName == tagName).AnyAsync(); if (valid) { Console.WriteLine($"{tagName}已存在,不需要生成"); continue; } FileDto fileDto = this.UploadToQiniu(tag["icon"].ToString()); var tagEntity = new CreateUpdateTagDto() { TagName = tagName, Alias = tag["alias"].ToString(), Status = true, Thumbnail = fileDto.Path }; await _tagService.CreateAsync(tagEntity); } return(UnifyResponseDto.Success()); }
private void UpdateArticleLike(Guid subjectId, int likesQuantity) { Article article = _articleAuditBaseRepository.Where(r => r.Id == subjectId).ToOne(); if (article.IsAudit == false) { throw new LinCmsException("该文章因违规被拉黑"); } //防止数量一直减,减到小于0 if (likesQuantity < 0) { if (article.LikesQuantity < -likesQuantity) { return; } } _articleAuditBaseRepository.UpdateDiy.Set(r => r.LikesQuantity + likesQuantity).Where(r => r.Id == subjectId).ExecuteAffrows(); }
/// <summary> /// 验证密码是否正确,生成Claims,返回用户身份信息 /// </summary> /// <param name="context"></param> /// <returns></returns> public Task ValidateAsync(ResourceOwnerPasswordValidationContext context) { LinUser user = _useRepository.Where(r => r.Username == context.UserName || r.Email == context.UserName).ToOne(); //验证失败 if (user == null) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "用户不存在"); return(Task.CompletedTask); } if (user.Password != LinCmsUtils.Get32Md5(context.Password)) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "请输入正确密码!"); return(Task.CompletedTask); } _useRepository.UpdateDiy.Set(r => new LinUser() { LastLoginTime = DateTime.Now }).Where(r => r.Id == user.Id).ExecuteAffrows(); //subjectId 为用户唯一标识 一般为用户id //authenticationMethod 描述自定义授权类型的认证方法 //authTime 授权时间 //claims 需要返回的用户身份信息单元 context.Result = new GrantValidationResult( user.Id.ToString(), OidcConstants.AuthenticationMethods.Password, _clock.UtcNow.UtcDateTime, new List <Claim>() { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), new Claim(ClaimTypes.Email, user.Email ?? ""), new Claim(ClaimTypes.GivenName, user.Nickname ?? ""), new Claim(ClaimTypes.Name, user.Username ?? ""), new Claim(LinCmsClaimTypes.GroupId, user.GroupId.ToString()), new Claim(LinCmsClaimTypes.IsAdmin, user.IsAdmin().ToString()), new Claim(ClaimTypes.Role, user.IsAdmin()?LinGroup.Admin:user.GroupId.ToString()) }); return(Task.CompletedTask); }
private void PublishUserLikeNotification(CreateUpdateUserLikeDto createUpdateUserLike) { //根据用户点赞类型:文章、评论,得到消息的NotificationRespUserId的值 var createNotificationDto = new CreateNotificationDto() { UserInfoId = _currentUser.Id ?? 0, CreateTime = DateTime.Now, }; switch (createUpdateUserLike.SubjectType) { case UserLikeSubjectType.UserLikeArticle: Article subjectArticle = _articleAuditBaseRepository.Where(r => r.Id == createUpdateUserLike.SubjectId).ToOne(); createNotificationDto.NotificationRespUserId = subjectArticle.CreateUserId; createNotificationDto.NotificationType = NotificationType.UserLikeArticle; createNotificationDto.ArticleId = createUpdateUserLike.SubjectId; break; case UserLikeSubjectType.UserLikeComment: Comment subjectComment = _commentRepository.Where(r => r.Id == createUpdateUserLike.SubjectId).ToOne(); createNotificationDto.NotificationRespUserId = subjectComment.CreateUserId; createNotificationDto.NotificationType = NotificationType.UserLikeArticleComment; createNotificationDto.ArticleId = subjectComment.SubjectId; createNotificationDto.CommentId = createUpdateUserLike.SubjectId; break; } if (createNotificationDto.NotificationRespUserId != 0 && _currentUser.Id != createNotificationDto.NotificationRespUserId) { using ICapTransaction trans = UnitOfWork.BeginTransaction(_capBus, false); _capBus.Publish("NotificationController.Post", createNotificationDto); trans.Commit(); } }
public async Task DeleteUserGroupAsync(long userId) { await _userGroupRepository.Where(r => r.UserId == userId).ToDelete().ExecuteAffrowsAsync(); }