Files
server/src/Events/Controllers/EventsController.cs

46 lines
1.4 KiB
C#
Raw Normal View History

2017-12-04 10:12:11 -05:00
using System;
using System.Threading.Tasks;
using Bit.Core;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Events.Models;
using Microsoft.AspNetCore.Authorization;
2017-12-04 10:12:11 -05:00
using Microsoft.AspNetCore.Mvc;
namespace Events.Controllers
{
[Authorize("Application")]
2017-12-04 10:12:11 -05:00
public class EventsController : Controller
{
private readonly CurrentContext _currentContext;
private readonly IEventService _eventService;
private readonly ICipherRepository _cipherRepository;
public EventsController(
CurrentContext currentContext,
IEventService eventService,
ICipherRepository cipherRepository)
{
_currentContext = currentContext;
_eventService = eventService;
_cipherRepository = cipherRepository;
}
[HttpPost("~/cipher/{id}")]
public async Task PostCipher(Guid id, [FromBody]EventModel model)
{
var cipher = await _cipherRepository.GetByIdAsync(id, _currentContext.UserId.Value);
if(cipher != null)
{
await _eventService.LogCipherEventAsync(cipher, model.Type);
}
}
[HttpPost("~/user")]
public async Task PostUser([FromBody]EventModel model)
2017-12-04 10:12:11 -05:00
{
await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type);
2017-12-04 10:12:11 -05:00
}
}
}