Example #1
0
    public string LoginToViziAppsFromGoogleApps(Hashtable State, string username)
    {
        try
        {
            string sql = "SELECT * FROM customers WHERE username='******' AND account_type like '%google_apps%'";
            DB db = new DB();
            DataRow[] rows = db.ViziAppsExecuteSql(State, sql);
            if (rows.Length == 0)
            {
                db.CloseViziAppsDatabase(State);
                return "The username is incorrect.";
            }
            DataRow row = rows[0];
            if (row["status"].ToString() == "inactive")
            {
                db.CloseViziAppsDatabase(State);
                return "Your account is inactive. Contact ViziApps to re-activate your account.";
            }

            //check expiration date
            string expiration_date = row["expiration_date"].ToString();
            if (expiration_date.Length > 0)
            {
                DateTime expiration = DateTime.Parse(expiration_date);
                if (expiration < DateTime.Now.ToUniversalTime())
                {
                    sql = "UPDATE customers SET status='inactive' WHERE customer_id='" + row["customer_id"].ToString() + "'";
                    db.ViziAppsExecuteNonQuery(State, sql);
                    db.CloseViziAppsDatabase(State);
                    return "Your account has expired.";
                }
            }

            State["CustomerID"] = row["customer_id"].ToString();

            string account_type = GetAccountType(row["account_type"].ToString());
            State["AccountType"] = account_type;
            State["CustomerEmail"] = row["email"].ToString();

            Hashtable UsersList = (Hashtable)HttpRuntime.Cache["UsersList"];
            if (UsersList == null)
            {
                //this shouldn't happen so report this now and go on
                String error = "Application Cache UsersList has been set to null";
                string NOW = GetCurrentDateTimeUTCMySqlFormat();

                sql = "INSERT INTO error_log SET log_id=UUID(), timestamp='" + NOW + "',username='******',app='no app selectred',error='" + error + "',stacktrace='no stack trace'";
                db.ViziAppsExecuteNonQuery(State, sql);
                db.CloseViziAppsDatabase(State);

                HttpRuntime.Cache["UsersList"] = new Hashtable();
                UsersList = (Hashtable)HttpRuntime.Cache["UsersList"];
            }

            string force_1_user_sessions = row["force_1_user_sessions"].ToString();
            bool one_user_allowed = force_1_user_sessions == "1" || force_1_user_sessions.ToLower() == "true";
            if (UsersList[username] != null)
            {
                Hashtable UserTable = (Hashtable)UsersList[username];
                //check if only 1 user is allowed
                if (one_user_allowed && State["PageRequestIPAddress"] != null && UserTable["PageRequestIPAddress"].ToString() != State["PageRequestIPAddress"].ToString())
                    return "The account is already in use.";
                UserTable["PageRequestIPAddress"] = State["PageRequestIPAddress"].ToString();
                UserTable["SessionID"] = State["SessionID"];
            }
            else
            {
                Hashtable UserTable = new Hashtable();
                UserTable["PageRequestIPAddress"] = State["PageRequestIPAddress"].ToString();
                UserTable["SessionID"] = State["SessionID"];
                UsersList[username] = UserTable;
            }

            //initialize configurations
            State["CustomerStatus"] = row["status"].ToString();
            State["Password"] = "";
            State["Username"] = username;
            SetLoggedIn(State);

            TimeZones zone_util = new TimeZones();
            zone_util.GetDefaultTimeZone(State);

            IncrementNLogins(State);
            LogLastUsed(State);

            string agreed_to_eula = row["agreed_to_eula"].ToString();

            if (username.ToLower() == "admin")
                return "admin";

            else if (agreed_to_eula == "1" || agreed_to_eula.ToLower() == "true")
            {
                return "OK";
            }

            else
                return "agree_to_EULA";

        }
        catch (Exception ex)
        {
            LogError(State, ex);
            return "Internal error in login process.";
        }
    }
    protected void UpdateProfile_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        Message.Text = "";

        PasswordTextBox.Text = Request.Form.Get("PasswordTextBox");
        ConfirmPasswordBox.Text = Request.Form.Get("ConfirmPasswordBox");
        CompanyTextBox.Text = Request.Form.Get("CompanyTextBox");
        RoleTextBox.Text = Request.Form.Get("RoleTextBox");
        FirstNameTextBox.Text = Request.Form.Get("FirstNameTextBox");
        LastNameTextBox.Text = Request.Form.Get("LastNameTextBox");
        StreetTextBox.Text = Request.Form.Get("StreetTextBox");
        CityTextBox.Text = Request.Form.Get("CityTextBox");
        StateList.Text = Request.Form.Get("StateList");
        PostalCodeTextBox.Text = Request.Form.Get("PostalCodeTextBox");
        CountryTextBox.Text = Request.Form.Get("CountryTextBox");
        PhoneTextbox.Text = Request.Form.Get("PhoneTextbox");
        EmailTextBox.Text = Request.Form.Get("EmailTextBox");
        string force_1_user_sessions = Request.Form.Get("Force1UserSessions");
        Force1UserSessions.Checked = force_1_user_sessions == "on" ? true : false;

        //validation
        if (CompanyTextBox.Text.Length > 0 && !Check.ValidateName(Message, CompanyTextBox.Text))
        {
            return;
        }
        if (RoleTextBox.Text.Length > 0 && !Check.ValidateString(Message, RoleTextBox.Text))
        {
            return;
        }
        if (FirstNameTextBox.Text.Length > 0 && !Check.ValidateName(Message, FirstNameTextBox.Text))
        {
            return;
        }
        if (LastNameTextBox.Text.Length > 0 && !Check.ValidateName(Message, LastNameTextBox.Text))
        {
            return;
        }
        if (StreetTextBox.Text.Length > 0 && !Check.ValidateText(Message, StreetTextBox.Text))
        {
            return;
        }
        if (CityTextBox.Text.Length > 0 && !Check.ValidateName(Message, CityTextBox.Text))
        {
            return;
        }
        if (PostalCodeTextBox.Text.Length > 0 && !Check.ValidateZipcode(Message, PostalCodeTextBox.Text))
        {
            return;
        }
        if (CountryTextBox.Text.Length > 0 && !Check.ValidateName(Message, CountryTextBox.Text))
        {
            return;
        }
        if (!Check.ValidatePhone(Message, PhoneTextbox.Text))
        {
            return;
        }
        if (!Check.ValidateEmail(Message, EmailTextBox.Text))
        {
            return;
        }

        StringBuilder sql = null;
        DB db = new DB();
        string username = null;
        if (State["Username"].ToString() != "admin")
        {
            username =  State["Username"].ToString();
        }
        else
        {
            username =  State["ServerAdminUsername"].ToString();
        }

        if (PasswordTextBox.Text.Length > 0 || ConfirmPasswordBox.Text.Length > 0)
        {
            if (PasswordTextBox.Text == ConfirmPasswordBox.Text)
            {
                if (!Check.ValidatePassword(Message, PasswordTextBox.Text))
                {
                    return;
                }
                sql = new StringBuilder("UPDATE customers SET password='******'");
                sql.Append(" WHERE username='******'");
                db.ViziAppsExecuteNonQuery(State, sql.ToString());

                sql = new StringBuilder("SELECT email from customers WHERE username='******'");
                string to_email = db.ViziAppsExecuteScalar(State, sql.ToString());

                Email email = new Email();
                StringBuilder body = new StringBuilder("\nYour ViziApps password has been changed.\n\n");

                body.Append("If you did not change it, contact our support team at [email protected] right away. ");
                body.Append("\n\n - The ViziApps Team \n");

                email.SendEmail(State,   HttpRuntime.Cache["TechSupportEmail"].ToString(), to_email, "", "", "ViziApps Notice", body.ToString(), "",false);
            }
            else
            {
                Message.Text = "New password and confirmation password do not match. Your account information has not been updated";
                return;
            }
        }

        sql = new StringBuilder("UPDATE customers SET ");
        sql.Append("company='" + util.MySqlFilter(CompanyTextBox.Text) + "'");
        sql.Append(",role='" + util.MySqlFilter(RoleTextBox.Text) + "'");
        sql.Append(",first_name='" + util.MySqlFilter(FirstNameTextBox.Text) + "'");
        sql.Append(",last_name='" + util.MySqlFilter(LastNameTextBox.Text) + "'");
        sql.Append(",street_address='" + util.MySqlFilter(StreetTextBox.Text) + "'");
        sql.Append(",city='" + util.MySqlFilter(CityTextBox.Text) + "'");
        if (StateList.SelectedValue.IndexOf("->") < 0)
            sql.Append(",state='" + StateList.SelectedValue + "'");
        else
            sql.Append(",state=''");

        sql.Append(",postal_code='" + PostalCodeTextBox.Text + "'");
        sql.Append(",country='" + util.MySqlFilter(CountryTextBox.Text) + "'");
        sql.Append(",phone='" + PhoneTextbox.Text + "'");
        sql.Append(",email='" + EmailTextBox.Text + "'");
        sql.Append(",default_time_zone_delta_hours='" + TimeZoneList.SelectedValue + "'");
        force_1_user_sessions = force_1_user_sessions == "on" ? "1" : "0";
        sql.Append(",force_1_user_sessions=" + force_1_user_sessions);
        sql.Append(" WHERE username='******'");
        db.ViziAppsExecuteNonQuery(State, sql.ToString());
        db.CloseViziAppsDatabase(State);

        TimeZones zone_util = new TimeZones();
        zone_util.GetDefaultTimeZone(State);

        //Update with CheddarGetter the CreditCardDetails if the Checkbox for CreditCardUpdate is checked.
        if (Update_CC_Details_CheckBox.Checked)
        {
            if (UpdateCheddarGetterWithCC() == true)
                Message.Text = "Your account profile has been updated. ";
            else
                Message.Text = "There was a problem updating your credit card info. Please contact [email protected] for assistance.";
        }
        else
            Message.Text = "Your account profile has been updated. ";
        //End CC Update
    }
Example #3
0
    public string LoginToViziApps(Hashtable State, string username, string password)
    {
        try
        {
            string sql = "SELECT * FROM customers WHERE username='******'";
            DB db = new DB();
            DataRow[] rows = db.ViziAppsExecuteSql(State, sql);
            if (rows.Length == 0)
            {
                db.CloseViziAppsDatabase(State);
                return "Either the username or the password is incorrect.";
            }
            DataRow row = rows[0];
            if (row["status"].ToString() == "inactive")
            {
                db.CloseViziAppsDatabase(State);
                return "Your account is inactive. Contact ViziApps to re-activate your account.";
            }

            string db_password = row["password"].ToString();
            if (db_password == password)
            {
                //check expiration date
                string expiration_date = row["expiration_date"].ToString();
                if (expiration_date.Length > 0)
                {
                    DateTime expiration = DateTime.Parse(expiration_date);
                    if (expiration < DateTime.Now.ToUniversalTime())
                    {
                        sql = "UPDATE customers SET status='inactive' WHERE customer_id='" + row["customer_id"].ToString() + "'";
                        db.ViziAppsExecuteNonQuery(State, sql);
                        db.CloseViziAppsDatabase(State);
                        return "Your account has expired.";
                    }
                }

                State["CustomerID"] = row["customer_id"].ToString();
                Util util = new Util();

                string[] account_type_list = GetAccountType(row["account_type"].ToString()).Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string AllowedAccountTypes = ConfigurationManager.AppSettings["AllowedAccountTypes"];
                string[] allowed_account_type_list = AllowedAccountTypes.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                bool isAccountTypeAllowed = false;
                foreach (string allowed_account_type in allowed_account_type_list)
                {
                    foreach (string account_type in account_type_list)
                    {
                        if (account_type == allowed_account_type)
                        {
                            isAccountTypeAllowed = true;
                            break;
                        }
                    }
                    if (isAccountTypeAllowed)
                        break;
                }
                if (!isAccountTypeAllowed)
                {
                    foreach (string account_type in account_type_list)
                    {
                        if (account_type == "google_apps")
                            return "If you created a ViziApps account from Google Apps Marketplace, you can only login into ViziApps from your Google account to maintain secure access to your data.";
                    }
                    return "Invalid Login";
                }
                State["AccountType"] = GetAccountType(row["account_type"].ToString());

                Hashtable UsersList = (Hashtable)HttpRuntime.Cache["UsersList"];
                if (UsersList == null)
                {
                    //this shouldn't happen so report this now and go on
                    String error = "Application Cache UsersList has been set to null";
                    string NOW = GetCurrentDateTimeUTCMySqlFormat();

                    sql = "INSERT INTO error_log SET log_id=UUID(), timestamp='" + NOW + "',username='******',app='no app selectred',error='" + error + "',stacktrace='no stack trace'";
                    db.ViziAppsExecuteNonQuery(State, sql);
                    db.CloseViziAppsDatabase(State);

                    HttpRuntime.Cache["UsersList"] = new Hashtable();
                    UsersList = (Hashtable)HttpRuntime.Cache["UsersList"];
                }

                string force_1_user_sessions = row["force_1_user_sessions"].ToString();
                bool one_user_allowed = force_1_user_sessions == "1" || force_1_user_sessions.ToLower() == "true";
                if (UsersList[username] != null)
                {
                    Hashtable UserTable = (Hashtable)UsersList[username];
                    //check if only 1 user is allowed
                    if (one_user_allowed && State["PageRequestIPAddress"] != null && UserTable["PageRequestIPAddress"].ToString() != State["PageRequestIPAddress"].ToString())
                        return "The account is already in use.";
                    UserTable["PageRequestIPAddress"] = State["PageRequestIPAddress"].ToString();
                    UserTable["SessionID"] = State["SessionID"];
                }
                else
                {
                    Hashtable UserTable = new Hashtable();
                    UserTable["PageRequestIPAddress"] = State["PageRequestIPAddress"].ToString();
                    UserTable["SessionID"] = State["SessionID"];
                    UsersList[username] = UserTable;
                }

                //initialize configurations
                State["CustomerStatus"] = row["status"].ToString();
                State["Password"] = password;
                State["Username"] = username;
                SetLoggedIn(State);

                TimeZones zone_util = new TimeZones();
                zone_util.GetDefaultTimeZone(State);

                IncrementNLogins(State);
                LogLastUsed(State);

                string agreed_to_eula = row["agreed_to_eula"].ToString();

                if (username.ToLower() == "admin")
                    return "admin";

                else if (agreed_to_eula == "1" || agreed_to_eula.ToLower() == "true")
                {
                    return "OK";
                }

                else
                    return "agree_to_EULA";
            }
            else
            {
                db.CloseViziAppsDatabase(State);
                return "Either the username or the password is incorrect.";
            }
        }
        catch (Exception ex)
        {
            LogError(State, ex);
            return "Internal error in login process.";
        }
    }