using PageAdmin.BLL;
using PageAdmin.Utils;
using PageAdmin.Web.Filter;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.E.Controllers
{
    /// <summary>
    /// 邮件验证码
    /// </summary>
    public class EmailCodeController : Controller
    {

        [ValidateAntiForgeryToken]
        [AjaxOnly]
        [HttpPost]
        public JsonResult Send(FormCollection form)
        {
            string email = form["email"];
            EmailCodeBLL emailCodeBLL = new EmailCodeBLL();
            TipsInfo tipsInfo = emailCodeBLL.Send(email);
            return Json(tipsInfo);
        }

        [AjaxOnly]
        [HttpPost]
        public JsonResult Validate(FormCollection form)
        {
            string email = form["email"];
            string validateName = StringHelper.Format<string>(form["_validateName"]);
            string code = StringHelper.Format<string>(form[validateName]);
            EmailCodeBLL emailCodeBLL = new EmailCodeBLL();
            TipsInfo tipsInfo = emailCodeBLL.Validate(email, code);
            return Json(tipsInfo);
        }
    }
}