Ejemplo n.º 1
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
            var temp = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;

            loginedUser = new USERModel();
            loginedUser.ma_nguoi_dung     = EncryptTo.Encrypt(temp.Split('_')[0]);
            loginedUser.ho_ten_nguoi_dung = temp.Split('_')[1];
        }
Ejemplo n.º 2
0
        public ActionResult CheckAuthenticationGmail(string check)
        {
            //Kiểm tra DB
            var data = EncryptTo.Decrypt(check);

            if (!data.Contains("_"))
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }

            var arr        = data.Split('_');
            var id_account = int.Parse(arr[0]);
            var time       = DateTime.ParseExact(arr[1], "ddMMyyyyHHmmss", CultureInfo.InvariantCulture);

            ACCOUNTModel account = new ACCOUNTRepository().GetById(id_account);

            if (arr[1] == account.thoi_gian_login_gmail)
            {
                if (time < DateTime.Now && DateTime.Now < time.AddMinutes(5))
                {
                    new ACCOUNTRepository().UpdateThoiGianLoginGmail(id_account, null);
                    USERModel user = SaveLoginInfo(id_account);
                    if (user.ma_role == "admin")
                    {
                        return(RedirectToAction("Index", "PageAdmin"));
                    }
                    if (user.ma_role == "employee")
                    {
                        return(RedirectToAction("Index", "PageUser"));
                    }
                }
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }
Ejemplo n.º 3
0
        public bool SendAuthenticationGmail([FromBody] ACCOUNTModel account)
        {
            try
            {
                MailMessage mail  = new MailMessage();
                SmtpClient  smtpC = new SmtpClient("smtp.gmail.com");
                //From address to send email
                mail.From = new MailAddress("*****@*****.**");

                //To address to send email
                USERModel user = new USERRepository().GetUSERByIdAccount(account);
                mail.To.Add(user.email);
                string thoi_gian_login_gmail = DateTime.Now.ToString("ddMMyyyyHHmmss");
                var    hash = $"{account.id}_{thoi_gian_login_gmail}";
                hash = System.Web.HttpUtility.UrlEncode(EncryptTo.Encrypt(hash));
                string href = "http://*****:*****@gmail.com", "0070091994");
                smtpC.EnableSsl   = true;
                smtpC.Send(mail);

                //Lưu vào DB
                new ACCOUNTRepository().UpdateThoiGianLoginGmail(account.id, thoi_gian_login_gmail);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
 public ACCOUNTModel GetAccount([FromBody] USERModel user)
 {
     return(new ACCOUNTRepository().GetByMaUser(EncryptTo.Decrypt(user.ma_nguoi_dung)));
 }
Ejemplo n.º 5
0
 public USERModel GetProfile([FromBody] USERModel user)
 {
     return(new USERRepository().GetByMaUser(EncryptTo.Decrypt(user.ma_nguoi_dung)));
 }