public string ReceiveForgotPassOTP(string username, int otpType, string phoneNumber)
        {
            try
            {
                NLogManager.LogMessage("ReceiveForgotPassOTP: " + username + "|" + otpType + "|" + phoneNumber);
                if (otpType == 1)
                {
                    if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(phoneNumber))
                    {
                        return("-99");
                    }
                }

                var account = AccountDAO.GetAccountByUsername(username);
                if (!string.IsNullOrEmpty(account.Tel))
                {
                    if (!PhoneDetector.IsValidPhone(phoneNumber))
                    {
                        return("-54");
                    }
                }

                if (!string.IsNullOrEmpty(phoneNumber) && account.Tel != phoneNumber)
                {
                    return("-73");
                }
                else
                {
                    var status = OTP.OTP.GenerateOTP(account.AccountID, phoneNumber);
                    NLogManager.LogMessage("OTP: " + status);
                    if (int.Parse(status) < 0)
                    {
                        return(status);
                    }
                    bool deduct = TransactionDAO.DeductGold(account.AccountID, 1000, "Phí dịch vụ OTP", 2);
                    if (!deduct)
                    {
                        return("-62");
                    }
                    SmsService.SendMessage(phoneNumber, $"Ma xac nhan: " + status);

                    string token = $"{DateTime.Now.Ticks}|{account.AccountID}|{account.Tel}";
                    return(Security.TripleDESEncrypt(ConfigurationManager.AppSettings["OTPKey"], token));
                }
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }
            return("-99");
        }
        public int UpdatePhoneNumber(string phoneNumber, string otp)
        {
            try
            {
                if (!PhoneDetector.IsValidPhone(phoneNumber))
                {
                    return(-54);
                }

                var accountId = AccountSession.AccountID;
                var account   = AccountDAO.GetAccountById(AccountSession.AccountID);

                if (!string.IsNullOrEmpty(account.Tel))
                {
                    string p = account.Tel;

                    if (!OTP.OTP.ValidateOTP(accountId, otp, p))
                    {
                        return(-60);
                    }
                }
                else
                {
                    var    infoApp = OtpDAO.GetCurrentCounter(accountId);
                    string token   = infoApp?.AppT;
                    if (!string.IsNullOrEmpty(infoApp?.AppT))
                    {
                        if (OTPApp.ValidateOTP($"{Security.MD5Encrypt($"{accountId}_{token}")}_{token}", otp))
                        {
                            goto doneOTP;
                        }
                    }

                    if (!OTP.OTP.ValidateOTP(accountId, otp, phoneNumber))
                    {
                        return(-60);
                    }
                }

doneOTP:
                SecurityDAO.UpdatePhoneNumber(AccountSession.AccountID, phoneNumber);

                return(1);
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }
            return(-99);
        }
        public int ReceiveOTP(string phoneNumber = "")
        {
            try
            {
                NLogManager.LogMessage("ReceiveOTP: " + phoneNumber);
                var account = AccountDAO.GetAccountById(AccountSession.AccountID);
                NLogManager.LogMessage("ReceiveOTP: " + JsonConvert.SerializeObject(account));
                //chua dang ky sdt
                if (string.IsNullOrEmpty(account.Tel))
                {
                    if (!PhoneDetector.IsValidPhone(phoneNumber))
                    {
                        NLogManager.LogMessage("FAIL PHONE: " + phoneNumber);
                        return(-54);
                    }
                    //send to phonenumber
                    //this case is for the first time update phone
                    var status = OTP.OTP.GenerateOTP(AccountSession.AccountID, phoneNumber);
                    NLogManager.LogMessage("OTP: " + status);
                    if (int.Parse(status) < 0)
                    {
                        return(int.Parse(status));
                    }
                    bool deduct = TransactionDAO.DeductGold(account.AccountID, 1000, "Phí dịch vụ OTP", 2);
                    NLogManager.LogMessage("DEDUCT OTP STATUS: " + deduct);
                    if (!deduct)
                    {
                        return(-62);
                    }
                    //send the otp to phone
                    SmsService.SendMessage(phoneNumber, $"Ma xac nhan: " + status);

                    return(1);
                }
                else
                {
                    NLogManager.LogMessage("OTP to phone: " + account.Tel);
                    var status = OTP.OTP.GenerateOTP(AccountSession.AccountID, account.Tel);
                    NLogManager.LogMessage("OTP: " + status);
                    if (int.Parse(status) < 0)
                    {
                        return(int.Parse(status));
                    }
                    bool deduct = TransactionDAO.DeductGold(account.AccountID, 1000, "Phí dịch vụ OTP", 2);
                    NLogManager.LogMessage("deduct: " + deduct);
                    if (!deduct)
                    {
                        return(-62);
                    }
                    //send the otp to phone
                    SmsService.SendMessage(account.Tel, $"Ma xac nhan: " + status);

                    return(1);
                }
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
                NLogManager.LogMessage("ERROR ReceiveOTP: " + ex);
            }
            return(-99);
        }