using System.Net;
using System.Net.Http;
using System.Web.Http;
using Qusion.WebApp.Areas.Qusion.Filters;
using Qusion.WebApp.Areas.Qusion.Models.Account;
using WebMatrix.WebData;

namespace Qusion.WebApp.Areas.Qusion.Controllers.Api
{
   [Authorize(Roles="Administrator,Administrators,Radnik,Test")]
    [InitializeSimpleMembership]
    public class AccountController : ApiController
    {
        /// <summary>
        ///   Web API to check user credentials.
        /// </summary>
        /// <param name="model"> </param>
        /// <param name="returnUrl"> </param>
        /// <returns> </returns>
        [HttpPost]
        [AllowAnonymous]
        public HttpResponseMessage Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.Email, model.Password, persistCookie: model.RememberMe))
            {
                return Request.CreateResponse(HttpStatusCode.OK, new {ReturnUrl = returnUrl});
            }

            return Request.CreateResponse(HttpStatusCode.Forbidden);
        }
    }
}