2017-12-04 10:12:11 -05:00
|
|
|
|
using System;
|
2017-12-04 10:59:07 -05:00
|
|
|
|
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
|
|
|
|
|
|
{
|
2017-12-04 10:59:07 -05:00
|
|
|
|
[Authorize("Application")]
|
2017-12-04 10:12:11 -05:00
|
|
|
|
public class EventsController : Controller
|
|
|
|
|
|
{
|
2017-12-04 10:59:07 -05:00
|
|
|
|
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
|
|
|
|
{
|
2017-12-04 10:59:07 -05:00
|
|
|
|
await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type);
|
2017-12-04 10:12:11 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|