public ActionResult UpdateBaseQuota(string state)
        {
            using (var db = new EchoContext())
            {
                IEnumerable <Quota> quotas = db.Quotas.Where(x => x.Quota_Type_Cd.Equals("B"));
                string user_no             = Session["User_No"].ToString();
                foreach (var item in quotas)
                {
                    string fv = Request.Form["Quota_Freq_Val_" + item.Quota_Cd];
                    string dv = Request.Form["Quota_Dur_Val_" + item.Quota_Cd];

                    try
                    {
                        item.Quota_Freq_Val  = Convert.ToByte(fv);
                        item.Quota_Dur_Val   = Convert.ToByte(dv);
                        item.Updated_By      = user_no;
                        item.Updated_Dttm    = DateTime.Now;
                        db.Entry(item).State = EntityState.Modified;
                    }
                    catch
                    {
                        return(View(quotas));
                    }
                }
                db.SaveChanges();
                FreebieEvent.UserUpdateEvent(Permission.base_quota_page_id, "A04");
                return(RedirectToAction("BaseQuota"));
            }
        }
Beispiel #2
0
        public static void AccountCreateEvent(Account new_account, string mobile_no, byte?page_id)
        {
            using (var db = new EchoContext())
            {
                string event_action = "A03";
                string account_no   = null;
                string user_no      = null;
                if (HttpContext.Current.Session["Account_No"] != null)
                {
                    account_no = HttpContext.Current.Session["Account_No"].ToString();
                }
                if (HttpContext.Current.Session["User_No"] != null)
                {
                    user_no = HttpContext.Current.Session["User_No"].ToString();
                }

                EventLog log = new EventLog();
                log.Action_Cd             = event_action;
                log.Identification_Number = new_account.Identification_Number;
                log.Mobile_Number         = mobile_no;
                log.Account_Status_Cd     = new_account.Status_Cd;
                log.Account_No            = new_account.Account_No;
                log.User_No = user_no;
                if (page_id != null)
                {
                    log.Page_Id = page_id;
                }
                db.EventLogs.Add(log);
                db.SaveChanges();
            }
        }
Beispiel #3
0
        public static void UpdateMobile(Account account, string mobile_no, string action, byte?page_id)
        {
            using (var db = new EchoContext())
            {
                string account_no = null;
                string user_no    = null;
                if (HttpContext.Current.Session["Account_No"] != null)
                {
                    account_no = HttpContext.Current.Session["Account_No"].ToString();
                }
                if (HttpContext.Current.Session["User_No"] != null)
                {
                    user_no = HttpContext.Current.Session["User_No"].ToString();
                }

                string   event_action = action;
                EventLog log          = new EventLog();
                log.Account_No    = account.Account_No;
                log.User_No       = user_no;
                log.Mobile_Number = mobile_no;
                log.Action_Cd     = event_action;
                if (page_id != null)
                {
                    log.Page_Id = page_id;
                }

                db.EventLogs.Add(log);
                db.SaveChanges();
            }
        }
Beispiel #4
0
        public ActionResult UpdateStaffAcct(int?user_id, string state)
        {
            if (user_id == null)
            {
                return(HttpNotFound());
            }
            user_id = Convert.ToInt32(user_id);

            User user = db.Users.SingleOrDefault(x => x.User_Id == user_id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            if (string.IsNullOrWhiteSpace(Request.Form["First_Name"]))
            {
                ModelState.AddModelError("First_Name", "กรุณาระบุชื่อ");
            }
            if (string.IsNullOrWhiteSpace(Request.Form["Last_Name"]))
            {
                ModelState.AddModelError("Last_Name", "กรุณาระบุนามสกุล");
            }

            bool can_crud_this_user = Permission.can_update_this_staff(user);

            if (!can_crud_this_user)
            {
                return(HttpNotFound());
            }

            user.First_Name = Request.Form["First_Name"];
            user.Last_Name  = Request.Form["Last_Name"];
            user.Dept_Cd    = Request.Form["Dept_Cd"];
            user.Group_Id   = Convert.ToByte(Request.Form["Group_Id"]);
            user.Status_Cd  = Request.Form["Status_Cd"];

            if (!string.IsNullOrWhiteSpace(Request.Form["PlainPwd"]))
            {
                string pwd = Request.Form["PlainPwd"];
                user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1");
            }

            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                FreebieEvent.UserUpdateEvent(Permission.staff_acct_page_id, "A04");
                //init_dropdown(user);
                return(View("ViewStaffAcct", user));
            }
            else
            {
                init_dropdown(user);
                return(View(user));
            }
        }
Beispiel #5
0
 public static void AddCustomError(string err_str, byte page_id)
 {
     using (var db = new EchoContext())
     {
         string   event_action = "A06";
         EventLog error_log    = new EventLog();
         error_log.Error_Msg = err_str;
         error_log.Action_Cd = event_action;
         error_log.Page_Id   = page_id;
         db.EventLogs.Add(error_log);
         db.SaveChanges();
     }
 }
Beispiel #6
0
 // account login/logout
 public static void AccountEvent(Account account, string action, byte?page_id)
 {
     using (var db = new EchoContext())
     {
         string   event_action = action;
         EventLog log          = new EventLog();
         log.Account_No = account.Account_No;
         log.Action_Cd  = event_action;
         if (page_id != null)
         {
             log.Page_Id = page_id;
         }
         db.EventLogs.Add(log);
         db.SaveChanges();
     }
 }
        public static int ValidateOTP(string phone_number, string otp_pwd)
        {
            /* returning value
             *  0 - pass
             *  1 - failed, try again
             *  2 - failed, start over
             *  3 - expired, start over
             */
            long number = Convert.ToInt64(phone_number);

            using (var db = new EchoContext())
            {
                OTP otp = db.OTPs.SingleOrDefault(x => x.PhoneNumber.Equals(phone_number));

                if (otp == null)
                {
                    return(2);
                }
                if (otp.Counter >= 3)
                {
                    return(2);
                }
                int cmp = DateTime.Compare(DateTime.Now, otp.Expired_Dttm);

                if (cmp > 0)
                {
                    return(3);
                }

                string check_otp = GenerateOTP(otp.Secret, number);
                if (check_otp.Equals(otp_pwd))
                {
                    return(0);
                }
                else
                {
                    otp.Counter        += 1;
                    db.Entry(otp).State = EntityState.Modified;
                    db.SaveChanges();
                    if (otp.Counter >= 3)
                    {
                        return(2);
                    }
                    return(1);
                }
            }
        }
        public ActionResult UpdateActivationLimit(ActivationLimit al)
        {
            using (var db = new EchoContext())
            {
                AdminConfiguration ac      = db.AdminConfigurations.SingleOrDefault();
                string             user_no = Session["User_No"].ToString();
                ac.No_Activation_Limit_Total = Convert.ToInt32(al.no_activation_limit_total);
                ac.No_Activation_Limit_Daily = Convert.ToInt32(al.no_activation_limit_daily);
                ac.Updated_By   = user_no;
                ac.Updated_Dttm = DateTime.Now;

                db.Entry(ac).State = EntityState.Modified;
                db.SaveChanges();
                FreebieEvent.UserUpdateEvent(Permission.activation_page_id, "A04");
                return(RedirectToAction("ActivationLimit"));
            }
        }
Beispiel #9
0
        public static void AccountUpdateEvent(Account account, string new_value, string type, byte?page_id)
        {
            using (var db = new EchoContext())
            {
                string event_action = "A04";
                string account_no   = null;
                string user_no      = null;
                if (HttpContext.Current.Session["Account_No"] != null)
                {
                    account_no = HttpContext.Current.Session["Account_No"].ToString();
                }
                if (HttpContext.Current.Session["User_No"] != null)
                {
                    user_no = HttpContext.Current.Session["User_No"].ToString();
                }


                EventLog log = new EventLog();
                log.Action_Cd = event_action;

                if (type != null)
                {
                    if (type.Equals("Status"))
                    {
                        log.Account_Status_Cd = new_value;
                    }

                    if (type.Equals("Idcard"))
                    {
                        log.Identification_Number = new_value;
                    }
                }


                log.Account_No = account.Account_No;
                log.User_No    = user_no;
                if (page_id != null)
                {
                    log.Page_Id = page_id;
                }

                db.EventLogs.Add(log);
                db.SaveChanges();
            }
        }
        public ActionResult UpdateFreeTrialQuota(TrialQuota tq)
        {
            using (var db = new EchoContext())
            {
                AdminConfiguration ac      = db.AdminConfigurations.SingleOrDefault();
                string             user_no = Session["User_No"].ToString();
                ac.Trial_Limit_Total = Convert.ToInt32(tq.trial_limit_total);
                ac.Trial_Dur_Val     = Convert.ToInt32(tq.trial_dur_val);
                ac.Trial_Enable_Flag = Convert.ToBoolean(tq.trial_enable_flag);
                ac.Updated_By        = user_no;
                ac.Updated_Dttm      = DateTime.Now;

                db.Entry(ac).State = EntityState.Modified;
                db.SaveChanges();
                FreebieEvent.UserUpdateEvent(Permission.free_trial_page_id, "A04");
                return(RedirectToAction("FreeTrialQuota"));
            }
        }
Beispiel #11
0
        public static void UserUpdateEvent(byte page_id, string action)
        {
            using (var db = new EchoContext())
            {
                string user_no = null;
                if (HttpContext.Current.Session["User_No"] != null)
                {
                    user_no = HttpContext.Current.Session["User_No"].ToString();
                }
                EventLog log = new EventLog();
                log.Action_Cd = action;
                log.User_No   = user_no;
                log.Page_Id   = page_id;

                db.EventLogs.Add(log);
                db.SaveChanges();
            }
        }
        //private static EchoContext db = new EchoContext();

        public static void AfterCreateAccount(Account ac, string[] interests)
        {
            using (var db = new EchoContext())
            {
                ac.Created_By   = ac.Account_No;
                ac.Updated_By   = ac.Account_No;
                ac.Created_Dttm = DateTime.Now;
                ac.Updated_Dttm = DateTime.Now;

                //db.Entry(ac).State = EntityState.Modified;

                AccountMobile am = new AccountMobile();
                am.Mobile_Number = ac.First_Mobile_Number;
                am.Account_Id    = ac.Account_Id;
                am.Status_Cd     = FreebieStatus.MobileActive();
                am.Primary_Flag  = true;
                am.Created_By    = ac.Account_No;
                am.Updated_By    = ac.Account_No;
                db.AccountMobiles.Add(am);

                AccountInterest aci = new AccountInterest();
                aci.Account_Id             = ac.Account_Id;
                aci.I01_Food_Dining        = interests.Contains("I01");
                aci.I02_Night_Life         = interests.Contains("I02");
                aci.I03_Entertainment      = interests.Contains("I03");
                aci.I04_Music_Movie        = interests.Contains("I04");
                aci.I05_Sports_Fitness     = interests.Contains("I05");
                aci.I06_Shopping_Fashion   = interests.Contains("I06");
                aci.I07_Health_Beauty      = interests.Contains("I07");
                aci.I08_Travel             = interests.Contains("I08");
                aci.I09_Pets               = interests.Contains("I09");
                aci.I10_Kids_Children      = interests.Contains("I10");
                aci.I11_Home_Living        = interests.Contains("I11");
                aci.I12_Finance_Investment = interests.Contains("I12");
                aci.I13_Technology_Gadget  = interests.Contains("I13");
                aci.I14_Auto               = interests.Contains("I14");
                aci.Created_By             = ac.Account_No;
                aci.Updated_By             = ac.Account_No;
                db.AccountInterests.Add(aci);

                db.SaveChanges();
            }
        }
Beispiel #13
0
        public void ProcessRequest(HttpContext context)
        {
            string             reply_str      = "";
            var                db             = new EchoContext();
            SmsRegistrationLog sms_log        = new SmsRegistrationLog();
            string             sms_log_result = "";

            try
            {
                string keyword   = context.Request.Form["keyword"] == null ? string.Empty : context.Request.Form["keyword"];
                string content   = context.Request.Form["content"] == null ? string.Empty : context.Request.Form["content"];
                string mobile_no = context.Request.Form["mobile_no"] == null ? string.Empty : context.Request.Form["mobile_no"];
                //string msg = context.Request.Form["msg"] == null ? string.Empty : context.Request.Form["msg"];


                sms_log.Mobile_Number = mobile_no;
                sms_log.RQ_Msg        = "-";
                sms_log.RQ_Keyword    = keyword;
                sms_log.RQ_Content    = content;


                int  result = CustomValidate.ValidateNumber(mobile_no);
                bool flag   = true;

                if (result != 1 && result != 4)
                {
                    flag = false;
                    if (result == 2 || result == 3 || result == 5)
                    {
                        reply_str      = System.Configuration.ConfigurationManager.AppSettings["EXIST_NUMBER"];
                        sms_log_result = "Existing number";
                    }

                    if (result == 6)
                    {
                        reply_str      = System.Configuration.ConfigurationManager.AppSettings["NO_ACCTACTIVATION"];
                        sms_log_result = "Maintenance Period";
                    }
                }

                if (flag)
                {
                    if (IsValid(keyword, content))
                    {
                        string[] content_arrs = content.Split(' ');
                        string   gender       = content_arrs[0];
                        string   dob          = content_arrs[1];
                        string[] result_sp    = new string[2];

                        byte day   = Convert.ToByte(dob.Substring(0, 2));
                        byte month = Convert.ToByte(dob.Substring(2, 2));
                        int  year  = Convert.ToInt16(dob.Substring(4, 4));

                        year = year - 543;
                        #region transaction
                        var transactionOptions = new TransactionOptions();
                        transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                        transactionOptions.Timeout        = TransactionManager.MaximumTimeout;
                        Account  account   = new Account();
                        DateTime timestamp = DateTime.Now;
                        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
                        {
                            var db_transaction = new EchoContext();

                            account.Gender_Cd           = gender.ToUpper();
                            account.Day_Of_Birth        = day;
                            account.Month_Of_Birth      = month;
                            account.Year_Of_Birth       = year;
                            account.Channel_Cd          = "SMS";
                            account.Created_By          = System.Configuration.ConfigurationManager.AppSettings["CREATED_BY_SMS"];
                            account.Updated_By          = System.Configuration.ConfigurationManager.AppSettings["CREATED_BY_SMS"];
                            account.First_Mobile_Number = mobile_no;
                            account.Created_Dttm        = timestamp;
                            account.Updated_Dttm        = timestamp;
                            account.Registration_Dttm   = timestamp;

                            var   today = DateTime.Now.Date;
                            Quota q     = db_transaction.Quotas.Where(x => x.Quota_Type_Cd.Equals("B")).Where(x => x.Quota_Cd.Equals("Q0001")).SingleOrDefault();

                            #region account quota used cur
                            AccountQuotaUsedCur aquc = new AccountQuotaUsedCur();
                            aquc.Date                = today.Date;
                            aquc.Account             = account;
                            aquc.Quota_Freq_Used_Val = 0;
                            aquc.Quota_Avail_Flag    = true;
                            aquc.Quota_Dur_Val       = Convert.ToByte(q.Quota_Dur_Val);
                            aquc.Quota_Freq_Val      = Convert.ToByte(q.Quota_Freq_Val);
                            db_transaction.AccountQuotaUsedCurs.Add(aquc);
                            #endregion

                            #region account mobile
                            AccountMobile am = new AccountMobile();
                            am.Account       = account;
                            am.Mobile_Number = mobile_no;
                            am.Primary_Flag  = true;
                            am.Status_Cd     = "AC";
                            am.Updated_By    = System.Configuration.ConfigurationManager.AppSettings["CREATED_BY_SMS"];
                            am.Created_By    = System.Configuration.ConfigurationManager.AppSettings["CREATED_BY_SMS"];
                            db_transaction.AccountMobiles.Add(am);
                            #endregion

                            #region account interest
                            AccountInterest ai = new AccountInterest();
                            ai.Account = account;
                            db_transaction.AccountInterests.Add(ai);
                            #endregion

                            #region account quota
                            AccountQuota aq = new AccountQuota();
                            aq.Account  = account;
                            aq.Quota_Cd = q.Quota_Cd;
                            db_transaction.AccountQuotas.Add(aq);
                            #endregion

                            #region update account activation and set status_cd
                            SqlParameter output = new SqlParameter("acstatus", SqlDbType.Int);
                            output.Direction = ParameterDirection.Output;

                            SqlParameter date = new SqlParameter("today", SqlDbType.Date);
                            date.Value = DateTime.Now;

                            SqlParameter no_acct_total = new SqlParameter("no_acct_limit_total", SqlDbType.Int);

                            int no_acct_limit_total         = 0;
                            AdminConfiguration admin_config = db_transaction.AdminConfigurations.SingleOrDefault();

                            if (admin_config != null)
                            {
                                no_acct_limit_total = admin_config.No_Activation_Limit_Total;
                            }

                            no_acct_total.Value = no_acct_limit_total;
                            string sql_string =
                                "declare @tbt table (acstatus int)" +
                                "UPDATE Account_Activation " +
                                "SET No_Activation = CASE WHEN (No_Activation + 1 > No_Max_Activation or (No_Activation_Acc + 1 > @no_acct_limit_total)) THEN No_Activation ELSE No_Activation + 1 END, " +
                                "No_Activation_Acc = CASE WHEN (No_Activation + 1 > No_Max_Activation or (No_Activation_Acc + 1 > @no_acct_limit_total)) THEN No_Activation_Acc ELSE No_Activation_Acc + 1 END, " +
                                "No_Activation_Pending = CASE WHEN (No_Activation + 1 > No_Max_Activation or (No_Activation_Acc + 1 > @no_acct_limit_total)) THEN No_Activation_Pending + 1 ELSE No_Activation_Pending END, " +
                                "Updated_By = 'WEBSITE', " +
                                "Updated_Dttm = GETDATE() " +
                                "OUTPUT CASE WHEN (deleted.No_Activation + 1 > deleted.No_Max_Activation or deleted.No_Activation_Acc + 1 > @no_acct_limit_total) THEN 1 ELSE 0 END " +
                                " into @tbt " +
                                "WHERE [Date] = @today " +
                                "select @acstatus = acstatus from @tbt";

                            db_transaction.Database.ExecuteSqlCommand(sql_string, no_acct_total, date, output);

                            int sql_result = Convert.ToInt16(output.Value);

                            if (sql_result == 0)
                            {
                                account.Status_Cd       = FreebieStatus.AccountActivated();
                                account.Activation_Dttm = timestamp;
                                reply_str      = System.Configuration.ConfigurationManager.AppSettings["ACD"];
                                sms_log_result = "Register success";
                                string q_str = (Convert.ToByte(q.Quota_Freq_Val) * Convert.ToByte(q.Quota_Dur_Val) * 30).ToString();
                                reply_str = reply_str.Replace("{count}", q.Quota_Freq_Val.ToString());
                                reply_str = reply_str.Replace("{mins}", q.Quota_Dur_Val.ToString());
                                reply_str = reply_str.Replace("{num}", q_str);
                            }
                            else
                            {
                                account.Status_Cd = FreebieStatus.AccountPending();
                                reply_str         = System.Configuration.ConfigurationManager.AppSettings["AP"];
                                sms_log_result    = "Register Pending";
                            }

                            #endregion


                            account.First_Quota_Cd       = q.Quota_Cd;
                            account.First_Quota_Dur_Val  = q.Quota_Dur_Val;
                            account.First_Quota_Freq_Val = q.Quota_Freq_Val;
                            account.Dummy_Flag           = "0";

                            db_transaction.Accounts.Add(account);
                            db_transaction.SaveChanges();
                            scope.Complete();
                        }
                        #endregion
                        #region call_sp
                        result_sp = CallSP.SP_Insert_Interact_Profile(account.Account_Id);
                        if (!result_sp[0].Equals("0"))
                        {
                            using (var new_db = new EchoContext())
                            {
                                SqlParameter date = new SqlParameter("today", SqlDbType.Date);
                                date.Value = DateTime.Now;
                                Account remove_ac = new_db.Accounts.SingleOrDefault(x => x.Account_Id == account.Account_Id);
                                if (remove_ac != null)
                                {
                                    if (remove_ac.Status_Cd.Equals(FreebieStatus.AccountActivated()))
                                    {
                                        string sql_string =
                                            "UPDATE Account_Activation " +
                                            "SET No_Activation = CASE WHEN (No_Activation - 1 < 0 ) THEN 0 ELSE No_Activation - 1 END, " +
                                            "No_Activation_Acc = CASE WHEN (No_Activation_Acc - 1 < 0 ) THEN 0 ELSE No_Activation_Acc - 1 END, " +
                                            "Updated_By = 'WEBSITE', " +
                                            "Updated_Dttm = GETDATE() " +
                                            "WHERE [Date] = @today ";

                                        new_db.Database.ExecuteSqlCommand(sql_string, date);
                                    }
                                    else
                                    {
                                        if (remove_ac.Status_Cd.Equals(FreebieStatus.AccountPending()))
                                        {
                                            string sql_string =
                                                "UPDATE Account_Activation " +
                                                "SET No_Activation_Pending = CASE WHEN (No_Activation_Pending - 1 < 0 ) THEN 0 ELSE No_Activation_Pending - 1 END, " +
                                                "Updated_By = 'WEBSITE', " +
                                                "Updated_Dttm = GETDATE() " +
                                                "WHERE [Date] = @today ";

                                            new_db.Database.ExecuteSqlCommand(sql_string, date);
                                        }
                                    }
                                    AccountQuotaUsedCur remove_aquc = new_db.AccountQuotaUsedCurs.SingleOrDefault(x => x.Account_Id == account.Account_Id);
                                    if (remove_aquc != null)
                                    {
                                        new_db.AccountQuotaUsedCurs.Remove(remove_aquc);
                                    }
                                    new_db.Accounts.Remove(remove_ac);
                                    new_db.SaveChanges();
                                }
                            }
                            reply_str = System.Configuration.ConfigurationManager.AppSettings["NO_ACCTACTIVATION"];
                        }
                        else
                        {
                            FreebieEvent.AccountCreateEvent(account, account.First_Mobile_Number, Permission.f_cust_regis_page_id);
                        }
                        #endregion
                    }
                    else
                    {
                        reply_str      = System.Configuration.ConfigurationManager.AppSettings["WRONG_FORMAT"];
                        sms_log_result = "Wrong input Format";
                    }
                }
            }
            catch (Exception err)
            {
                reply_str      = System.Configuration.ConfigurationManager.AppSettings["NO_ACCTACTIVATION"];
                sms_log_result = "System Error";
                FreebieEvent.AddCustomError(err.Message, Permission.f_cust_regis_page_id);
            }

            Encoding encoding = Encoding.GetEncoding("tis-620");
            string   xml_str  = GetReplyXML(reply_str, encoding);

            sms_log.Result = sms_log_result;
            db.SmsRegistrationLogs.Add(sms_log);
            db.SaveChanges();

            context.Response.ContentType     = "text/xml";
            context.Response.ContentEncoding = encoding;
            context.Response.Write(xml_str);
        }
        public ActionResult AddNumber(string phoneNumber)
        {
            string password = Request.Form["Password"];

            phoneNumber = GetCookie("Acct", "phone_number");
            bool flag = true;

            if (string.IsNullOrEmpty(phoneNumber))
            {
                ViewBag.ValidNumber = false;
                ViewBag.PhoneNumber = "";
                flag = false;
            }

            ViewBag.PhoneNumber = phoneNumber;

            string otp = Request.Form["Password"];

            if (flag && (string.IsNullOrEmpty(otp) || otp.Length < 4))
            {
                ViewBag.ValidNumber  = true;
                ViewBag.Error        = true;
                ViewBag.ErrorMessage = System.Configuration.ConfigurationManager.AppSettings["Validate010"];
                flag = false;
            }

            if (flag)
            {
                int result = OTPHandler.ValidateOTP(phoneNumber, otp);
                switch (result)
                {
                case 0:
                    int account_id = Convert.ToInt32(Session["Account_Id"].ToString());
                    var account    = db.Accounts.SingleOrDefault(x => x.Account_Id == account_id);
                    if (account == null)
                    {
                        return(HttpNotFound());
                    }
                    AccountMobile am           = db.AccountMobiles.Where(x => x.Account_Id.Equals(account.Account_Id)).Where(x => x.Mobile_Number.Equals(phoneNumber)).SingleOrDefault();
                    bool          first_create = false;

                    if (am == null)
                    {
                        am               = new AccountMobile();
                        am.Account_Id    = account.Account_Id;
                        am.Status_Cd     = FreebieStatus.MobileActive();
                        am.Mobile_Number = phoneNumber;
                        am.Primary_Flag  = false;
                        am.Created_Dttm  = DateTime.Now;
                        am.Updated_Dttm  = DateTime.Now;
                        first_create     = true;
                    }

                    if (first_create)
                    {
                        db.AccountMobiles.Add(am);
                    }
                    else
                    {
                        am.Status_Cd       = FreebieStatus.MobileActive();
                        am.Created_Dttm    = DateTime.Now;
                        am.Updated_Dttm    = DateTime.Now;
                        db.Entry(am).State = EntityState.Modified;
                    }


                    OTP otp_request = db.OTPs.SingleOrDefault(x => x.PhoneNumber.Equals(phoneNumber));
                    if (otp_request != null)
                    {
                        db.OTPs.Remove(otp_request);
                    }
                    db.SaveChanges();
                    FreebieEvent.UpdateMobile(account, phoneNumber, "A03", Permission.f_update_number_page_id);
                    RemoveCoookie("Acct");
                    return(RedirectToAction("ViewNumber", "AccInfo"));

                case 1:
                    ViewBag.Error        = true;
                    ViewBag.ValidNumber  = true;
                    ViewBag.ErrorMessage = System.Configuration.ConfigurationManager.AppSettings["Validate007"];
                    ViewBag.ShowPwd      = true;
                    break;

                case 2:
                    ViewBag.ValidNumber = false;
                    ViewBag.PhoneNumber = "";
                    ViewBag.ResetOTP    = System.Configuration.ConfigurationManager.AppSettings["Otp03"];
                    RemoveCoookie("Acct");
                    break;

                case 3:
                    ViewBag.ValidNumber = false;
                    ViewBag.PhoneNumber = "";
                    ViewBag.ResetOTP    = System.Configuration.ConfigurationManager.AppSettings["Otp04"];
                    RemoveCoookie("Acct");
                    break;

                default:
                    break;
                }
            }
            ViewBag.ShowPwd = true;
            return(View());
        }
Beispiel #15
0
        private static string fire(string phone_number, string msg, object log)
        {
            string result = string.Empty;

            System.Type type_of = log.GetType();                                       //ORIGIN

            System.Configuration.ConfigurationManager.AppSettings["SEND_SMS"] = "YES"; //dummy data for DEBUG

            if (System.Configuration.ConfigurationManager.AppSettings["SEND_SMS"].Equals("YES"))
            {
                string postData = "ACCOUNT=" + System.Configuration.ConfigurationManager.AppSettings["MOBILE_ACCOUNT"];
                postData += "&PASSWORD="******"MOBILE_PWD"];
                postData += "&MOBILE=" + phone_number;

                postData += "&MESSAGE=" + msg;

                postData += "&LANGUAGE=" + System.Configuration.ConfigurationManager.AppSettings["MESSAGE_LANGUAGE"];
                postData += "&SENDER=" + System.Configuration.ConfigurationManager.AppSettings["SENDER_NAME"];
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Encoding iso  = Encoding.GetEncoding("ISO-8859-11");
                Encoding utf8 = Encoding.UTF8;
                byte[]   data = encoding.GetBytes(postData);
                data = Encoding.Convert(utf8, iso, data);

                DateTime start_res = DateTime.Now;

                //result = "System.Configuration.ConfigurationManager.AppSettings['SEND_SMS'].Equals('Yes')"; //DEBUG

                try
                {
                    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings["SMS_GATEWAY"]);
                    httpRequest.Method        = "POST";
                    httpRequest.Host          = System.Configuration.ConfigurationManager.AppSettings["SMS_HOST"]; //"203.146.102.26";
                    httpRequest.ContentType   = "application/x-www-form-urlencoded";
                    httpRequest.ContentLength = data.Length;
                    MemoryStream Memstream = new MemoryStream(data);
                    Stream       stream    = httpRequest.GetRequestStream();
                    Memstream.WriteTo(stream);
                    stream.Close();

                    Callback(httpRequest, (response) =>
                    {
                        var res_stream      = new StreamReader(response.GetResponseStream());
                        DateTime end_res    = DateTime.Now;
                        int index           = 0;
                        string[] result_rsp = new string[] { "", "", "", "" };
                        string rsp_str      = "";
                        while (res_stream.Peek() >= 0)
                        {
                            result_rsp[index] = res_stream.ReadLine();
                            index++;
                        }
                        foreach (var txt in result_rsp)
                        {
                            rsp_str += txt + " ";
                        }

                        //saving
                        using (var db = new EchoContext())
                        {
                            if (type_of == typeof(OtpLog))
                            {
                                OtpLog logger        = new OtpLog();
                                logger.Mobile_Number = phone_number;
                                logger.Request_At    = start_res;
                                logger.Response_At   = end_res;
                                logger.Response_Text = rsp_str;
                                db.OtpLogs.Add(logger);
                                db.SaveChanges();
                            }
                            else
                            {
                                if (type_of == typeof(ActivationSmsLog))
                                {
                                    ActivationSmsLog logger = new ActivationSmsLog();
                                    logger.Mobile_Number    = phone_number;
                                    logger.Request_At       = start_res;
                                    logger.Response_At      = end_res;
                                    logger.Response_Text    = rsp_str;
                                    db.ActivationSmsLogs.Add(logger);
                                    db.SaveChanges();
                                }
                            }
                        }
                        res_stream.Close();
                    });
                }
                catch (WebException wex)
                {
                    using (var db = new EchoContext())
                    {
                        if (type_of == typeof(OtpLog))
                        {
                            OtpLog logger = new OtpLog();
                            logger.Mobile_Number = phone_number;
                            logger.Request_At    = start_res;
                            logger.Response_At   = DateTime.Now;
                            logger.Response_Text = wex.Message;
                            db.OtpLogs.Add(logger);
                            db.SaveChanges();
                        }
                        else
                        {
                            if (type_of == typeof(ActivationSmsLog))
                            {
                                ActivationSmsLog logger = new ActivationSmsLog();
                                logger.Mobile_Number = phone_number;
                                logger.Request_At    = start_res;
                                logger.Response_At   = DateTime.Now;
                                logger.Response_Text = wex.Message;
                                db.ActivationSmsLogs.Add(logger);
                                db.SaveChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    FreebieEvent.AddError(ex, 0);
                }
            }
            else
            {
                result = ".AppSettings['SEND_SMS'].Equals('NO')"; //DEBUG
            }

            return(result);//ORIGIN
        }
        public static string RequestOTP(string phone_number)
        {
            var today       = DateTime.Now;
            int limit_daily = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["OTP_ALLOW_PER_DAY_PER_NUMBER"]);
            int interval    = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["INTERVAL_PERIOD_BETWEEN_OTP"]);

            using (var db = new EchoContext()) {
                phone_number = phone_number.Replace("-", "");
                long number = Convert.ToInt64(phone_number);

                OTPRequest otp_request  = db.OTPRequests.Where(x => x.Date.Equals(today.Date)).Where(x => x.PhoneNumber.Equals(phone_number)).SingleOrDefault();
                var        request_time = DateTime.Now;
                if (otp_request == null)
                {
                    bool flag = true;
                    otp_request             = new OTPRequest();
                    otp_request.PhoneNumber = phone_number;
                    otp_request.Count       = 0;

                    OTP    otp        = db.OTPs.SingleOrDefault(x => x.PhoneNumber.Equals(phone_number));
                    string secret_str = Secret();
                    if (otp == null)
                    {
                        otp  = new OTP();
                        flag = false;
                    }

                    otp.Secret       = secret_str;
                    otp.PhoneNumber  = phone_number;
                    otp.Counter      = 0;
                    otp.Expired_Dttm = request_time.AddMinutes(Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["OTPPwdExpired"]));

                    if (flag)
                    {
                        db.Entry(otp).State = EntityState.Modified;
                    }
                    else
                    {
                        db.OTPs.Add(otp);
                    }

                    otp_request.Last_Request_At = request_time;
                    otp_request.PhoneNumber     = phone_number;
                    otp_request.Date            = request_time.Date;
                    otp_request.Count           = 1;

                    db.OTPRequests.Add(otp_request);

                    db.SaveChanges();
                    return(GenerateOTP(secret_str, number));
                }
                else
                {
                    TimeSpan diff = request_time.Subtract(Convert.ToDateTime(otp_request.Last_Request_At));
                    if (diff.TotalMinutes > interval && otp_request.Count < limit_daily)
                    {
                        bool   flag       = true;
                        OTP    otp        = db.OTPs.SingleOrDefault(x => x.PhoneNumber.Equals(phone_number));
                        string secret_str = Secret();
                        if (otp == null)
                        {
                            otp  = new OTP();
                            flag = false;
                        }
                        otp.Secret       = secret_str;
                        otp.PhoneNumber  = phone_number;
                        otp.Counter      = 0;
                        otp.Expired_Dttm = request_time.AddMinutes(Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["OTPPwdExpired"]));

                        if (flag)
                        {
                            db.Entry(otp).State = EntityState.Modified;
                        }
                        else
                        {
                            db.OTPs.Add(otp);
                        }

                        otp_request.Last_Request_At = request_time;
                        otp_request.Count          += 1;

                        db.Entry(otp_request).State = EntityState.Modified;

                        db.SaveChanges();
                        return(GenerateOTP(secret_str, number));
                    }
                    else
                    {
                        if (otp_request.Count >= limit_daily)
                        {
                            return("limit_daily");
                        }

                        return("limit_interval");
                    }
                }
            }
        }