public async Task <UnifyResponseDto> DeleteMyComment(Guid id) { Comment comment = await _commentAuditBaseRepository.Select.Where(r => r.Id == id).FirstAsync(); if (comment == null) { return(UnifyResponseDto.Error("该评论已删除")); } if (comment.CreateUserId != _currentUser.Id) { return(UnifyResponseDto.Error("无权限删除他人的评论")); } using (IUnitOfWork uow = _unitOfWorkManager.Begin()) { using ICapTransaction trans = uow.BeginTransaction(_capBus, false); await _commentService.DeleteAsync(comment); await _capBus.PublishAsync("NotificationController.Post", new CreateNotificationDto() { NotificationType = NotificationType.UserCommentOnArticle, ArticleId = comment.SubjectId, UserInfoId = (long)_currentUser.Id, CommentId = comment.Id, IsCancel = true }); await trans.CommitAsync(); } return(UnifyResponseDto.Success()); }
public UnifyResponseDto DeleteMyComment(Guid id) { Comment comment = _commentAuditBaseRepository.Select.Where(r => r.Id == id).First(); if (comment == null) { return(UnifyResponseDto.Error("该评论已删除")); } if (comment.CreateUserId != _currentUser.Id) { return(UnifyResponseDto.Error("无权限删除他人的评论")); } _commentService.Delete(comment); return(UnifyResponseDto.Success()); }
private async Task <UnifyResponseDto> BindAsync(string identityType, string name, string openId, long userId) { LinUserIdentity linUserIdentity = await _userIdentityRepository.Where(r => r.IdentityType == identityType && r.Credential == openId).FirstAsync(); if (linUserIdentity == null) { var userIdentity = new LinUserIdentity(identityType, name, openId, DateTime.Now); userIdentity.CreateUserId = userId; await _userIdentityRepository.InsertAsync(userIdentity); return(UnifyResponseDto.Success("绑定成功")); } else { return(UnifyResponseDto.Error("绑定失败,该用户已绑定其他账号")); } }
public async Task <IActionResult> SignInBindCallBack(string provider, string redirectUrl = "", string token = "") { if (string.IsNullOrWhiteSpace(provider)) { return(BadRequest()); } if (!await HttpContext.IsProviderSupportedAsync(provider)) { return(BadRequest()); } if (token.IsNullOrEmpty() || !token.StartsWith("Bearer ")) { return(Redirect($"{redirectUrl}#bind-result?code={ErrorCode.Fail}&message={HttpUtility.UrlEncode("请先登录")}")); } else { token = token.Remove(0, 7); } AuthenticateResult authenticateResult = await _contextAccessor.HttpContext.AuthenticateAsync(provider); if (!authenticateResult.Succeeded) { return(Redirect($"{redirectUrl}#bind-result?code=fail&message={authenticateResult.Failure.Message}")); } var openIdClaim = authenticateResult.Principal.FindFirst(ClaimTypes.NameIdentifier); if (openIdClaim == null || string.IsNullOrWhiteSpace(openIdClaim.Value)) { return(Redirect($"{redirectUrl}#bind-result?code={ErrorCode.Fail}&message={HttpUtility.UrlEncode("未能获取openId")}")); } JwtPayload jwtPayload = (JwtPayload)_jsonWebTokenService.Decode(token); string nameIdentifier = jwtPayload.Claims.FirstOrDefault(r => r.Type == ClaimTypes.NameIdentifier)?.Value; if (nameIdentifier.IsNullOrWhiteSpace()) { return(Redirect($"{redirectUrl}#bind-result?code={ErrorCode.Fail}&message={HttpUtility.UrlEncode("请先登录")}")); } long userId = long.Parse(nameIdentifier); UnifyResponseDto unifyResponseDto; List <string> supportProviders = new List <string> { LinUserIdentity.Gitee, LinUserIdentity.GitHub, LinUserIdentity.QQ }; if (!supportProviders.Contains(provider)) { _logger.LogError($"未知的privoder:{provider},redirectUrl:{redirectUrl}"); unifyResponseDto = UnifyResponseDto.Error($"未知的privoder:{provider}!"); } else { IOAuth2Service oAuth2Service = _componentContext.ResolveNamed <IOAuth2Service>(provider); unifyResponseDto = await oAuth2Service.BindAsync(authenticateResult.Principal, provider, openIdClaim.Value, userId); } return(Redirect($"{redirectUrl}#bind-result?code={unifyResponseDto.Code.ToString()}&message={HttpUtility.UrlEncode(unifyResponseDto.Message.ToString())}")); }