Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // see if user already has a number signed up and that he user preference is set to mobile ok
            int  curr_user_id  = Convert.ToInt32(Context.Items["UserID"]);
            bool mobile_exists = false;
            bool mobile_active = false;
            lblCampaignID.Text = Convert.ToString(campaign_id);
            lblReturnURL.Text  = return_url;
            qPtl_UserProfile profile = new qPtl_UserProfile(curr_user_id);

            string mobile_number = string.Empty;

            if (profile.Phone1Type == "Mobile")
            {
                mobile_number = profile.Phone1;
            }
            else if (profile.Phone2Type == "Mobile")
            {
                mobile_number = profile.Phone2;
            }

            plhCurrentlyVerified.Visible = false;
            plhNotYetVerified.Visible    = true;
            if (!String.IsNullOrEmpty(mobile_number))
            {
                mobile_exists  = true;
                litStatus.Text = "Use this form to change the number you want to use.<br><br>";
                btnEnroll.Text = "Update Number";
                plhCurrentlyVerified.Visible = true;
                plhNotYetVerified.Visible    = false;
            }

            qCom_UserPreference pref = new qCom_UserPreference(curr_user_id);
            if (!String.IsNullOrEmpty(Convert.ToString(pref.MobilePINverified)) && pref.OkSms == "Yes")
            {
                mobile_active = true;
            }

            if (mobile_exists == true)
            {
                txtMobileNumber.Text = mobile_number;
            }

            if (mobile_active == true)
            {
                btnEnroll.Text = "Turn Off Text Messages";
            }

            if (mobile_active == false && mobile_verification_required == true)
            {
                // mobile is required and has not been completed
            }
        }
    }
Ejemplo n.º 2
0
    protected void btnVerify_Click(object sender, EventArgs e)
    {
        int    curr_user_id = Convert.ToInt32(Context.Items["UserID"]);
        string pin          = txtMobileVerify.Text;
        string return_url   = string.Empty;

        if (!String.IsNullOrEmpty(lblReturnURL.Text))
        {
            return_url = lblReturnURL.Text;
        }

        qCom_UserPreference comm = qCom_UserPreference.GetUserPreference(curr_user_id);
        qPtl_User           user = new qPtl_User(curr_user_id);

        string dbPIN = Convert.ToString(comm.MobilePIN);

        if (dbPIN == pin)
        {
            comm.OkSms             = "Yes";
            comm.ConfirmSms        = "Yes";
            comm.MobilePINverified = DateTime.Now;
            comm.Update();

            if (!String.IsNullOrEmpty(return_url))
            {
                Response.Redirect(lblReturnURL.Text);
            }
            else
            {
                litMsg.Text = "* PIN successfully validated. You will start receiving messages shortly";
            }
        }
        else
        {
            comm.OkSms = "No";
            comm.Update();

            litMsg.Text = "* WARNING: the PIN your entered does not match the one we sent to your phone. Please try again. If this problem continues, please contact support using the link below.<br><br>";
        }
    }
        public static qPtl_User RegisterNewUser(RegistrationData data)
        {
            int    existing_user_id = 0;
            int    new_space_id     = 0;
            string sqlCode          = string.Empty;

            // Redundancy check -- write Highest Level into qPtl_User table in case DB trigger not working
            qPtl_Role role = new qPtl_Role(data.default_role_id);

            // add user
            qPtl_User new_user = new qPtl_User();

            new_user.Available      = "Yes";
            new_user.OrgUnitID      = data.scope_id;
            new_user.ScopeID        = data.scope_id;
            new_user.Created        = DateTime.Now;
            new_user.CreatedBy      = 0;
            new_user.LastModified   = DateTime.Now;
            new_user.LastModifiedBy = 0;
            new_user.MarkAsDelete   = 0;
            new_user.Status         = "";           // used to include a default message for their status, now leave blank
            new_user.FirstName      = data.firstname;
            new_user.LastName       = data.lastname;
            new_user.Email          = data.email;
            new_user.UserName       = data.username;
            string password_for_storing = FormsAuthentication.HashPasswordForStoringInConfigFile(data.password, "sha1");

            new_user.Password      = password_for_storing;
            new_user.AccountStatus = "Active";
            new_user.HighestRank   = role.RoleRank;
            new_user.HighestRole   = role.RoleName;
            new_user.Insert();
            existing_user_id = new_user.UserID;

            DateTime DOB;

            try
            {
                DOB = Convert.ToDateTime(data.dob);
            }
            catch
            {
                // no valid date so use default value
                DOB = Convert.ToDateTime("1/1/1900");
            }

            // add user profile
            qPtl_UserProfile new_profile = new qPtl_UserProfile();

            new_profile.UserID             = existing_user_id;
            new_profile.ScopeID            = data.scope_id;
            new_profile.Available          = "Yes";
            new_profile.Created            = DateTime.Now;
            new_profile.CreatedBy          = existing_user_id;
            new_profile.LastModified       = DateTime.Now;
            new_profile.LastModifiedBy     = existing_user_id;
            new_profile.MarkAsDelete       = 0;
            new_profile.Style              = "default";
            new_profile.Visibility         = "all";
            new_profile.Division           = data.division;
            new_profile.Agency             = data.agency;
            new_profile.Position           = data.position;
            new_profile.Degrees            = data.degrees;
            new_profile.Address1           = data.address;
            new_profile.Address2           = data.address2;
            new_profile.City               = data.city;
            new_profile.StateProvince      = data.state;
            new_profile.PostalCode         = data.postal_code;
            new_profile.Country            = data.country;
            new_profile.Gender             = data.gender;
            new_profile.DOB                = DOB;
            new_profile.Race               = data.race;
            new_profile.EmploymentLocation = data.employment_location;
            new_profile.EmploymentSetting  = data.employment_setting;
            new_profile.WorkSites          = data.employment_sites;
            new_profile.Profession         = data.profession;
            new_profile.Phone1             = data.work_phone;
            new_profile.Phone1Type         = "work";
            new_profile.Insert();

            qPtl_User user = new qPtl_User(existing_user_id);

            // add user communication preference
            if (!String.IsNullOrEmpty(user.Email))
            {
                qCom_UserPreference connect = new qCom_UserPreference();
                connect.UserID         = user.UserID;
                connect.Created        = DateTime.Now;
                connect.CreatedBy      = user.UserID;
                connect.LastModified   = DateTime.Now;
                connect.LastModifiedBy = user.UserID;
                connect.Available      = "Yes";
                connect.ScopeID        = 1;
                connect.MarkAsDelete   = 0;
                connect.OkBulkEmail    = "Yes";
                connect.OkEmail        = "Yes";
                connect.OkSms          = "Yes";
                connect.LanguageID     = 1;
                connect.Insert();
            }

            // ****************************************************
            // STEP 5: Add User Role & Supporting Role Structures
            // Add role

            /*
             * qPtl_UserRole role = new qPtl_UserRole();
             * role.UserID = user.UserID;
             * role.RoleID = role_id;
             * role.Insert();
             */
            qDbs_SQLcode sql = new qDbs_SQLcode();

            sqlCode = "INSERT INTO qPtl_UserRoles ([UserID],[RoleID]) VALUES(" + user.UserID + "," + data.default_role_id + ")";
            sql.ExecuteSQL(sqlCode);

            // Add possible role actions for the new user role
            AddRoleAction(data.default_role_id, data.scope_id, user);

            // add folder for user_data
            string rootLocation = HttpContext.Current.Server.MapPath("~/") + "user_data\\";

            if (!Directory.Exists(rootLocation + user.UserName))
            {
                Directory.CreateDirectory(rootLocation + user.UserName);
            }

            if (new_user.UserID > 0)
            {
                return(new_user);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
    protected void btnEnroll_Click(object sender, EventArgs e)
    {
        // run check for mobile text
        if (!String.IsNullOrEmpty(lblCampaignID.Text))
        {
            campaign_id = Convert.ToInt32(lblCampaignID.Text);
        }
        return_url = lblReturnURL.Text;
        string mobile_number  = txtMobileNumber.Text;
        bool   error_occurred = false;
        bool   phone_belongs_to_another_user = false;

        // check to see if this number is already being used by another user
        int curr_user_id = Convert.ToInt32(Context.Items["UserID"]);
        int scope_id     = Convert.ToInt32(Context.Items["ScopeID"]);

        var check_user = qPtl_User.GetUserByPhone(txtMobileNumber.Text, scope_id);

        if (check_user.UserID > 0)
        {
            if (check_user.UserID != curr_user_id)
            {
                error_occurred = true;
                phone_belongs_to_another_user = true;
            }
        }

        // replace characters
        if (mobile_number.Contains("-"))
        {
            mobile_number = mobile_number.Replace("-", "");
        }

        if (mobile_number.Contains("."))
        {
            mobile_number = mobile_number.Replace(".", "");
        }

        if (mobile_number.Contains("/"))
        {
            mobile_number = mobile_number.Replace("/", "");
        }

        if (mobile_number.Contains("("))
        {
            mobile_number = mobile_number.Replace("(", "");
        }

        if (mobile_number.Contains(")"))
        {
            mobile_number = mobile_number.Replace(")", "");
        }

        if (mobile_number.Contains("*"))
        {
            mobile_number = mobile_number.Replace("*", "");
        }

        if (mobile_number.Contains(" "))
        {
            mobile_number = mobile_number.Replace(" ", "");
        }

        try
        {
            string first_char = mobile_number.Substring(0, 1);
            if (mobile_number.Length == 11 && first_char == "1")
            {
                mobile_number = mobile_number.Substring(1, 10);
            }
        }
        catch
        {
            litMsg.Text    = "<br><br>* Make sure to enter a 10 digit phone number";
            error_occurred = true;
        }

        if (String.IsNullOrEmpty(mobile_number))
        {
            litMsg.Text    = "<br><br>* Make sure to enter a 10 digit phone number";
            error_occurred = true;
        }

        string pat_m = @"^[0-9]{10}$";
        Regex  r_m   = new Regex(pat_m, RegexOptions.IgnoreCase);
        Match  m_m   = r_m.Match(mobile_number);

        if (!m_m.Success)
        {
            error_occurred = true;
            litMsg.Text    = "<br><br>* Make sure to enter a 10 digit phone number";
        }

        if (error_occurred == false)
        {
            if (btnEnroll.Text == "Turn Off Text Messages")
            {
                qCom_UserPreference pref = new qCom_UserPreference(curr_user_id);
                pref.OkSms = "No";
                pref.Update();
            }
            else
            {
                // save phone number to profile
                qPtl_UserProfile profile = new qPtl_UserProfile(curr_user_id);
                if (profile.Phone1Type == "Mobile")
                {
                    profile.Phone1     = string.Empty;
                    profile.Phone1Type = string.Empty;
                }
                if (profile.Phone2Type == "Mobile")
                {
                    profile.Phone2     = string.Empty;
                    profile.Phone2Type = string.Empty;
                }
                profile.Phone1     = txtMobileNumber.Text;
                profile.Phone1Type = "Mobile";

                profile.Update();

                // add new mobile verification code to qCom_UserPreferences
                var pref    = qCom_UserPreference.GetUserPreference(curr_user_id);
                int new_pin = qCom_UserPreference.GenerateMobilePIN();

                if (pref != null)
                {
                    if (pref.UserID > 0)
                    {
                        pref.MobilePIN = Convert.ToString(new_pin);
                        pref.Update();
                    }
                }
                else
                {
                    qCom_UserPreference pref2 = new qCom_UserPreference();
                    pref2.ScopeID        = Convert.ToInt32(Context.Items["ScopeID"]);
                    pref2.Available      = "Yes";
                    pref2.Created        = DateTime.Now;
                    pref2.CreatedBy      = curr_user_id;
                    pref2.LastModified   = DateTime.Now;
                    pref2.LastModifiedBy = curr_user_id;
                    pref2.UserID         = curr_user_id;
                    pref2.OkBulkEmail    = "Yes";
                    pref2.OkSms          = "Yes";
                    pref2.OkEmail        = "Yes";
                    pref2.MobilePIN      = Convert.ToString(new_pin);
                    pref2.Insert();
                }

                // get correct DID
                string alt_did = string.Empty;
                // see if user has custom record
                var camp_pref = qCom_UserCampaignPreference.GetUserCampaignPreferences(campaign_id, curr_user_id);
                if (camp_pref != null)
                {
                    alt_did = camp_pref.DID;
                }
                else
                {
                    // see if campaign has available dedicated DIDs
                    qSoc_Campaign campaign = new qSoc_Campaign(campaign_id);
                    qPtl_User     user     = new qPtl_User(curr_user_id);
                    alt_did = AddCampaignUserPreference(campaign, user, scope_id);

                    if (String.IsNullOrEmpty(alt_did))
                    {
                        alt_did = System.Configuration.ConfigurationManager.AppSettings["SMSDid"];
                    }
                }

                string alt_pin_message_uri = string.Empty;
                var    c_pref = qCom_CampaignPreference.GetCampaignPreferences(campaign_id);
                if (c_pref != null)
                {
                    if (c_pref.CampaignPreferenceID > 0)
                    {
                        alt_pin_message_uri = c_pref.MobileVerifySMSURI;
                    }
                }

                // send mobile pin
                qCom_UserPreference.SendMobilePIN(Convert.ToString(new_pin), curr_user_id, alt_did, alt_pin_message_uri);

                plhManage.Visible = false;
                plhVerify.Visible = true;
            }
        }
        else
        {
            if (phone_belongs_to_another_user == true)
            {
                litMsg.Text = "<br><br>* This phone number belongs to another user.";
            }
        }
    }