public bool CheckAuthenticationLoginSMS([FromBody] ACCOUNTModel account)
        {
            USERModel user = new USERRepository().GetUSERByIdAccount(account);

            //Xác thực bằng số điện thoại
            return(AUTHENTICATIONRepository.VerifySMSCode(user.sdt, "84", account.ma_code_xac_thuc));;
        }
        public USERModel SaveLoginInfo(int id_account)
        {
            ACCOUNTModel account = new ACCOUNTModel();

            account.id = id_account;
            USERModel user = new USERRepository().GetUSERByIdAccount(account);

            //rememberMe: tự nhớ ho_ten_nguoi_dung của lần trước để tự động đăng nhập hay không?
            bool rememberMe = false;
            var  authTicket = new FormsAuthenticationTicket(
                1,                                                // version
                $"{user.ma_nguoi_dung}_{user.ho_ten_nguoi_dung}", // user name
                DateTime.Now,                                     // created
                DateTime.Now.AddMinutes(480),                     // expires
                rememberMe,                                       // persistent?
                user.ma_role,                                     // can be used to store roles
                "/"
                );

            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
            var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            Response.Cookies.Add(authCookie);
            return(user);
        }
        public bool SendAuthenticationSMS([FromBody] ACCOUNTModel account)
        {
            USERModel user = new USERRepository().GetUSERByIdAccount(account);

            //Xác thực bằng số điện thoại
            return(AUTHENTICATIONRepository.SendVerifySMS(user.sdt, "84"));
        }
        public bool CheckAuthenticationLoginGG([FromBody] ACCOUNTModel account)
        {
            USERModel user = new USERRepository().GetUSERByIdAccount(account);
            TwoFactorAuthenticator TwoFacAuth = new TwoFactorAuthenticator();
            string UserUniqueKey = (user.ma_nguoi_dung + user.ho_ten_nguoi_dung);
            bool   isValid       = TwoFacAuth.ValidateTwoFactorPIN(UserUniqueKey, account.ma_code_xac_thuc);

            return(isValid);
        }
        public string SendAuthenticationGG([FromBody] ACCOUNTModel account)
        {
            USERModel user = new USERRepository().GetUSERByIdAccount(account);
            //Two Factor Authentication Setup
            TwoFactorAuthenticator TwoFacAuth = new TwoFactorAuthenticator();
            string UserUniqueKey = (user.ma_nguoi_dung + user.ho_ten_nguoi_dung);

            var setupInfo = TwoFacAuth.GenerateSetupCode("IOT Manager System", user.ma_nguoi_dung, UserUniqueKey, 200, 200);

            return(setupInfo.QrCodeSetupImageUrl);
        }
        public ACCOUNTModel CheckLogin(ACCOUNTModel account)
        {
            DynamicParameters param = new DynamicParameters();

            param.Add("ten_tai_khoan", account.ten_tai_khoan);
            param.Add("mat_khau", account.mat_khau);

            IEnumerable <ACCOUNTModel> temp = Query <ACCOUNTModel>(@"SELECT DISTINCT id_loai_xac_thuc, id
                                                            FROM dbo.ACCOUNT
                                                            WHERE ten_tai_khoan=@ten_tai_khoan AND mat_khau=@mat_khau AND tinh_trang=1",
                                                                   CommandType.Text, param);

            if (temp.Count() > 0)
            {
                return(temp.First());
            }
            return(null);
        }
        public USERModel GetUSERByIdAccount(ACCOUNTModel account)
        {
            DynamicParameters param = new DynamicParameters();

            param.Add("id", account.id);

            IEnumerable <USERModel> temp = Query <USERModel>(@"SELECT DISTINCT [USER].id, ma_nguoi_dung, ho_ten_nguoi_dung, sdt, cmnd,
		                                                            email, dia_chi, avartar, ngay_sinh, noi_sinh, id_role,ma_role, ten_role
                                                            FROM dbo.ACCOUNT, dbo.[USER], dbo.ROLE
                                                            WHERE id_ma_nguoi_dung = [USER].id AND id_role = ROLE.id
		                                                            AND ACCOUNT.id = @id"        ,
                                                             CommandType.Text, param);

            if (temp.Count() > 0)
            {
                return(temp.First());
            }
            return(null);
        }
        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);
            }
        }
        public ACCOUNTModel CheckLogin([FromBody] ACCOUNTModel account)
        {
            ACCOUNTModel result = new ACCOUNTRepository().CheckLogin(account);

            return(result);
        }
 public bool Update(ACCOUNTModel model)
 {
     throw new NotImplementedException();
 }
 public bool Insert(ACCOUNTModel model)
 {
     throw new NotImplementedException();
 }