using ASPSnippets.GoogleAPI;
using EnvigoHiring.Models.Login;
using System.Web.Mvc;

namespace EnvigoHiring.Controllers
{
    public class loginController : Controller
    {
        // GET: login
        public ActionResult Index(string code,string ReturnUrl)

        {
            LoginModel lm = new LoginModel();
            //lm.IsAntiForgery = false;
            if (code != null && code!="")
            {
                //lm.IsAntiForgery = true;
                ReturnUrl = (ReturnUrl == null) ? "" : ReturnUrl;
               
                lm.GetUserprofile(code,ReturnUrl);
                string redirectUrl = (ReturnUrl == null || ReturnUrl == "") ? "/dashboard" : ReturnUrl;
                return Redirect(redirectUrl);
            }

            return View(lm);
        }
        [HttpPost]
        public ActionResult Index(LoginModel lm, string btnSubmit)
        {
            if (ModelState.IsValid)
            {
                if (btnSubmit == "Login With Gmail")
                {
                    lm.IsAntiForgery = true;
                    GoogleConnect.Authorize("profile", "email");
                }
            }
            return View(lm);
        }
        public ActionResult thankyou()
        {
            return View();
        }
    }
}