public GenericJwtToken Login([FromBody] LoginRequest loginRequest) { var found = mongoContext.Collection <User>() .AsQueryable() .Where(u => u._id == loginRequest.Username && u.PasswordHash == loginRequest.PasswordHash) .FirstOrDefault(); if (found == null) { return(new GenericJwtToken() { Valid = false, Roles = new List <RoleEnum>() }); } var token = new GenericJwtToken() { Id = found._id, Roles = found.Roles, Valid = true, Name = found.Name, ExpiringDate = DateTime.Now.AddDays(authOptions.TokenExpiringDays) }; // token.Token = jwtObjectEncoder.Encode(token); token = Response.WriteJWTCookie(token); return(token); }
public MongoRepository(MongoContext context) { _context = context; _collection = _context.Collection <TDocument>(); _updateExcludedProperties = new List <string> { "Id", "CreatedAt", "Identity", "Stamps" }; }
/// <summary> /// 启动服务 /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public Task StartAsync(CancellationToken cancellationToken) { var config = RabbitmqContext.Config; if (config == null) { throw new TypeInitializationException("RabbitmqConfig", null); } _channel.BasicQos(0, 1, false); _channel.QueueDeclare(RabbitmqContext.AuditQueueName, true, false, false, null);//声明审计队列 foreach (RabbitmqServiceOptions service in config.Services) { if (!service.IsAudit) { continue; } var exchangeType = service.PatternType.GetExchangeType(); var exchangeName = service.PatternType.GetExchangeName(service.ExchangeName); _channel.ExchangeDeclare(exchangeName, exchangeType); //申明交换机 _channel.QueueBind(RabbitmqContext.AuditQueueName, exchangeName, service.QueueName); //建立队列与交换机的绑定关系 } var consumer = new EventingBasicConsumer(_channel); consumer.Received += (sender, eventArgs) => { var canAck = true; try { IBasicProperties basicProperties = eventArgs.BasicProperties; //消息属性 IDictionary <string, object> headers = eventArgs.BasicProperties.Headers; //头部信息 if (!string.IsNullOrEmpty(eventArgs.Exchange) && (headers == null || !headers.ContainsKey(RabbitmqContext.RetryCountKeyName))) { ConsumerContext context = eventArgs.GetConsumerContext(); //获取消费者消息处理上下文 _mongoDbContext.Collection <ConsumerContext>().InsertOneAsync(context, cancellationToken: cancellationToken); //添加审计记录 } } catch (Exception ex) { canAck = false; _log.Error($"【审计日志】事件参数:{JsonConvert.SerializeObject(eventArgs)}", ex); } //处理应答结果 AnswerHandler(canAck, eventArgs); }; _channel.BasicConsume(RabbitmqContext.AuditQueueName, false, consumer); return(Task.CompletedTask); }
public Animal GetOneAnimal([FromBody] GetAnimalRequest getAnimalRequest) { logger.Warning($"{nameof(GetOneAnimal)}: {getAnimalRequest._id}"); return(mongoContext.Collection <Animal>().GetOneById(getAnimalRequest._id)); }
public OrderRepository(MongoContext mongoContext) { _mongoContext = mongoContext; _orderCollection = mongoContext.Collection <Order>(); }