protected void btnSave_Click(object sender, EventArgs e)
        {
            lblError.Text      = string.Empty;
            lblError.Visible   = false;
            lblMessage.Text    = string.Empty;
            lblMessage.Visible = false;
            lblSave.Text       = string.Empty;
            lblSave.Visible    = false;

            int    userId          = Convert.ToInt32(Session["UserId"]);
            string oldPassword     = txtOldPassword.Text.Trim();
            string newPassword     = txtNewPassword.Text.Trim();
            string confirmPassword = txtConPassword.Text.Trim();



            CRM.Data.Entities.SecUser user = SecUserManager.GetByUserId(userId);
            if (user != null && user.UserName != null && user.Password != null)
            {
                string password = SecurityManager.Decrypt(user.Password);
                if (password == oldPassword)
                {
                    if (newPassword != confirmPassword)
                    {
                        lblMessage.Text    = string.Empty;
                        lblMessage.Text    = "Confirm Password Must Match!";
                        lblMessage.Visible = true;
                    }
                    else
                    {
                        user.UserId   = userId;
                        user.UserName = user.UserName;
                        user.Password = SecurityManager.Encrypt(newPassword);
                        SecUserManager.Save(user);
                        resetControl();
                        lblSave.Text    = "Password Updated Successfully!";
                        lblSave.Visible = true;
                    }
                }
                else
                {
                    lblMessage.Text    = string.Empty;
                    lblMessage.Text    = "Old Password Is Wrong.";
                    lblMessage.Visible = true;
                }
            }
            else
            {
                lblMessage.Text    = "UserId Not Valid.";
                lblMessage.Visible = true;
            }
        }
Exemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int userID = 0;

            if (Session["UserId"] != null && int.TryParse(Session["UserId"].ToString(), out userID) && userID > 0)
            {
                CRM.Data.Entities.SecUser user = SecUserManager.GetByUserId(userID);

                if (user != null)
                {
                    user.emailHost = txtEmailHost.Text.Trim();

                    user.emailHostPort = txtHostPostNumber.Text.Trim();

                    user.emailSignature = txtEmailSignature.Text.Trim();

                    user.Email = txtEmail.Text.Trim();

                    user.isSSL = cbxSSL.Checked;

                    if (!string.IsNullOrEmpty(txtEmailPassword.Text) && txtEmailPassword.Text != "pass")
                    {
                        user.emailPassword = SecurityManager.Encrypt(txtEmailPassword.Text);
                    }

                    lblMessage.Visible = true;

                    try {
                        SecUserManager.Save(user);

                        lblMessage.Text = "Changes saved successfully.";
                    }
                    catch (Exception ex) {
                        lblMessage.Text = "Error saving changes.";
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected void btnResetPassword_Click(object sender, EventArgs e)
        {
            // random password
            string password = Guid.NewGuid().ToString().Substring(0, 8);

            try {
                CRM.Data.Entities.SecUser user = SecUserManager.GetByUserId(Convert.ToInt32(hfUserId.Value));

                // encrypt password
                user.Password = Core.SecurityManager.Encrypt(password);

                user = SecUserManager.Save(user);

                Core.EmailHelper.emailUserPasswordReset(user);

                lblSave.Text = "User password has been reset. New password sent to user via email.";
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);

                lblSave.Text    = "Unable to reset password.";
                lblSave.Visible = true;
            }
        }
Exemplo n.º 4
0
        protected void btnCreateCarrierAccount_Click(object sender, EventArgs e)
        {
            int     clientID    = 0;
            int     contactID   = 0;
            Contact contact     = null;
            string  newUserName = null;
            string  password    = null;

            CRM.Data.Entities.SecUser newUserAccount = null;
            CRM.Data.Entities.SecUser user           = null;

            lblMessage.Text     = string.Empty;
            lblMessage.CssClass = string.Empty;

            Page.Validate("Account");
            if (!Page.IsValid)
            {
                return;
            }

            clientID = SessionHelper.getClientId();

            newUserName = txtUserName.Text.Trim();

            // check username is not taken
            if (SecUserManager.IsUserNameExist(newUserName))
            {
                lblMessage.Text     = "User Name " + newUserName + " is already taken.";
                lblMessage.CssClass = "error";
                return;
            }

            // initialize user object
            user = new CRM.Data.Entities.SecUser();

            user.UserName  = newUserName;
            user.FirstName = txtFirstName.Text;
            user.LastName  = txtLastName.Text;
            user.Status    = true;
            user.isSSL     = true;

            // assign client for this user
            user.ClientID = clientID;

            // attach carrier to user
            user.CarrierID = this.carrierID;

            user.CreatedBy = Core.SessionHelper.getUserId();
            user.CreatedOn = DateTime.Now;
            user.Email     = txtContactEmail.Text.Trim();

            // assign selected role
            user.RoleId = Convert.ToInt32(ddlClientRoles.SelectedValue);

            // random password
            password = Guid.NewGuid().ToString().Substring(0, 8);

            // encrypt password
            user.Password = Core.SecurityManager.Encrypt(password);

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    // add new user account
                    newUserAccount = SecUserManager.Save(user);

                    // associate new user account with contact
                    contactID = Convert.ToInt32(ViewState["ContactID"]);

                    contact = ContactManager.Get(contactID);

                    contact.UserID = newUserAccount.UserId;

                    ContactManager.Save(contact);

                    scope.Complete();
                }

                // email adjuster about newly created account
                Core.EmailHelper.emailUserCredentials(newUserAccount);

                lblMessage.Text     = string.Format("User Account '{0}' was created and credentials were emailed to the user.", newUserName);
                lblMessage.CssClass = "ok";

                // hide create account button
                this.btnShowCreateAccount.Visible    = false;
                this.btnCreateCarrierAccount.Visible = false;
            }
            catch (Exception ex) {
                lblMessage.Text     = "Unable to create user account.";
                lblMessage.CssClass = "error";

                Core.EmailHelper.emailError(ex);
            }
        }
Exemplo n.º 5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            lblError.Text      = string.Empty;
            lblSave.Text       = string.Empty;
            lblMessage.Text    = string.Empty;
            lblError.Visible   = false;
            lblSave.Visible    = false;
            lblMessage.Visible = false;

            bool isnew   = false;
            bool isError = false;

            CRM.Data.Entities.SecUser user = null;

            Page.Validate("register");
            if (!Page.IsValid)
            {
                return;
            }

            // 2013-08-06 tortega
            int clientID = Core.SessionHelper.getClientId();
            int roleID   = Core.SessionHelper.getUserRoleId();

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    if (hfUserId.Value == "0")
                    {
                        isnew = true;

                        user = new CRM.Data.Entities.SecUser();

                        user.ClientID = clientID;
                    }
                    else
                    {
                        user = SecUserManager.GetByUserId(Convert.ToInt32(hfUserId.Value));
                    }

                    // ** Add User  ** //
                    if (isnew)
                    {
                        bool userExist = SecUserManager.IsUserNameExist(txtUserName.Text.Trim());
                        //bool emailExist = SecUserManager.IsEmailExist(txtEmail.Text.Trim());

                        // 2013-08-06 tortega
                        if (clientID > 0 && ClientManager.UsersLimitReached(clientID))
                        {
                            throw new Exception("Maximum number of users reached.");
                        }

                        if (userExist)
                        {
                            throw new Exception("User Name already exists.");
                        }
                    }

                    user.FirstName = txtFirstName.Text.Trim();
                    user.LastName  = txtLastName.Text.Trim();
                    user.Email     = txtEmail.Text;
                    user.UserName  = txtUserName.Text.Trim();
                    //user.Password = SecurityManager.Encrypt(txtPassWord.Text);

                    user.RoleId  = Convert.ToInt32(ddlRole.SelectedValue);
                    user.Status  = ddlStatus.SelectedValue == "1" ? true : false;
                    user.Blocked = false;

                    user.isViewAllClaims = cbxViewAllClaims.Checked;

                    if (chkPassword.Checked == true || isnew)
                    {
                        user.Password = SecurityManager.Encrypt(txtPassWord.Text);
                    }

                    user.UserName  = txtUserName.Text.Trim();
                    user.FirstName = txtFirstName.Text.Trim();
                    user.LastName  = txtLastName.Text.Trim();
                    user.Email     = txtEmail.Text;
                    user.Status    = ddlStatus.SelectedValue == "1" ? true : false;
                    user.Blocked   = user.Blocked;
                    user.RoleId    = Convert.ToInt32(ddlRole.SelectedValue);

                    user = SecUserManager.Save(user);

                    //clearControls();
                    scope.Complete();

                    if (isnew)
                    {
                        lblSave.Text = "User account has been created. User credentials sent via email.";
                    }
                    else
                    {
                        lblSave.Text = "User account saved.";
                    }

                    lblSave.Visible          = true;
                    btnResetPassword.Visible = true;
                }
            }
            catch (Exception ex) {
                isError          = true;
                lblError.Text    = ex.Message;
                lblError.Visible = true;

                Core.EmailHelper.emailError(ex);
            }
            finally {
                if (isnew && isError == false)
                {
                    // email user account info
                    Core.EmailHelper.emailUserCredentials(user);
                }
            }
        }
Exemplo n.º 6
0
        protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            lblError.Text      = string.Empty;
            lblSave.Text       = string.Empty;
            lblMessage.Text    = string.Empty;
            lblMessage.Visible = false;
            lblError.Visible   = false;
            lblSave.Visible    = false;
            if (e.CommandName.Equals("DoEdit"))
            {
                Session["UID"] = e.CommandArgument;
                var url = "~/protected/admin/UserEdit.aspx";
                Response.Redirect(url);
            }
            else if (e.CommandName.Equals("DoDelete"))
            {
                try {
                    var user = SecUserManager.GetByUserId(Convert.ToInt32(e.CommandArgument));
                    user.Status = false;
                    SecUserManager.Save(user);
                    DoBind();
                    lblSave.Text    = "Record Deleted Sucessfully.";
                    lblSave.Visible = true;
                }
                catch (Exception ex) {
                    lblError.Text    = "Record Not Deleted.";
                    lblError.Visible = true;
                }
            }
            else if (e.CommandName.Equals("DoView"))
            {
                Session["UIDV"] = e.CommandArgument;
                var url = "~/protected/admin/UserDetail.aspx";
                Response.Redirect(url);

                Response.Redirect(url);
            }
            else if (e.CommandName.Equals("DoUnlock"))
            {
                try {
                    var user = SecUserManager.GetByUserId(Convert.ToInt32(e.CommandArgument));
                    user.Blocked = false;
                    SecUserManager.Save(user);
                    DoBind();
                    lblSave.Text    = "User Unlock Successfully.";
                    lblSave.Visible = true;
                }
                catch (Exception ex) {
                    lblError.Text    = "User Not Unlocked.";
                    lblError.Visible = true;
                }
            }
            else if (e.CommandName.Equals("Dolock"))
            {
                try {
                    var user = SecUserManager.GetByUserId(Convert.ToInt32(e.CommandArgument));
                    user.Blocked = true;
                    SecUserManager.Save(user);
                    DoBind();
                    lblSave.Text    = "User lock Successfully.";
                    lblSave.Visible = true;
                }
                catch (Exception ex) {
                    lblError.Text    = "User Not locked.";
                    lblError.Visible = true;
                }
            }
            else if (e.CommandName.Equals("DoImpersonate"))
            {
                impersonateUser(Convert.ToInt32(e.CommandArgument));
            }
        }
Exemplo n.º 7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int    clientID = 0;
            Client client   = null;

            CRM.Data.Entities.SecUser user = null;
            bool isNew            = false;
            int  invoiceSettingID = 0;
            int  userID           = 0;


            Page.Validate("Client");

            if (!Page.IsValid)
            {
                return;
            }


            if (int.TryParse(hfclientid.Value, out clientID) && clientID > 0)
            {
                // update existing
                client = ClientManager.Get(clientID);
            }
            else
            {
                // new user
                client = new Client();

                // default value
                client.InactivityDays = 30;

                isNew = true;
            }

            if (client != null)
            {
                try {
                    client.ClientTypeID = Convert.ToInt32(ddlClientType.SelectedValue);

                    client.FirstName = txtFirstName.Text.Trim();

                    client.LastName = txtLastName.Text.Trim();

                    client.BusinessName = txtBusinessName.Text.Trim();

                    client.StreetAddress1 = txtAddress.Text.Trim();

                    client.CityId = Convert.ToInt32(ddlCity.SelectedValue);

                    client.StateId = Convert.ToInt32(ddlState.SelectedValue);

                    client.ZipCode = ddlZipCode.SelectedValue;

                    client.PrimaryPhoneNo = txtPhone.Text.Trim();

                    client.SecondaryPhoneNo = txtFaxNumber.Text.Trim();

                    client.PrimaryEmailId = txtEmail.Text.Trim();

                    client.Active = 1;

                    client.maxUsers = string.IsNullOrEmpty(txtNumberUsers.Text) ? 1 : Convert.ToInt32(txtNumberUsers.Text);

                    client.FeePerContract = string.IsNullOrEmpty(txtFeePerContract.Text) ? 1 : Convert.ToDecimal(txtFeePerContract.Text);

                    client.FederalIDNo = txtFederalTaxID.Text.Trim();

                    client.MaxLeads = Convert.ToInt32(string.IsNullOrEmpty(txtMaxLeads.Text) ? "0" : txtMaxLeads.Text);

                    client.isTrial = cbxTrial.Checked;

                    client.isShowTasks = cbxShowTasks.Checked;

                    client.InactivityDays = string.IsNullOrEmpty(txtInactivityPeriod.Text) ? 0 : Convert.ToInt32(txtInactivityPeriod.Text);

                    // imap settings
                    client.imapHost = txtImapHost.Text.Trim();

                    client.imapHostPort = string.IsNullOrEmpty(txtImapHostPort.Text) ? 0 : Convert.ToInt32(txtImapHostPort.Text);

                    client.imapHostUseSSL = cbxImapUseSSL.Checked;

                    // invoice billing settings
                    invoiceSettingID = Convert.ToInt32(ddlInvoiceSetting.SelectedValue);
                    if (invoiceSettingID > 0)
                    {
                        client.InvoiceSettingID = invoiceSettingID;
                    }

                    client.InvoiceContingencyFee = txtContingencyFee.Value == null ? 0 : Convert.ToDecimal(txtContingencyFee.Value);

                    // save client
                    clientID = ClientManager.Save(client);

                    if (isNew)
                    {
                        try {
                            user           = new CRM.Data.Entities.SecUser();
                            user.UserName  = txtUserName.Text.Trim();
                            user.FirstName = txtFirstName.Text.Trim();
                            user.LastName  = txtLastName.Text.Trim();
                            user.Status    = true;
                            user.RoleId    = (int)UserRole.Client;
                            user.Email     = txtEmail.Text.Trim();
                            user.Password  = SecurityManager.Encrypt(txtUserPassword.Text.Trim());
                            user.CreatedOn = DateTime.Now;
                            user.CreatedBy = 1;
                            user.UpdatedOn = DateTime.Now;
                            user.UpdatedBy = 1;
                            user.ClientID  = clientID;

                            CRM.Data.Entities.SecUser newUser = SecUserManager.Save(user);

                            client = ClientManager.Get(clientID);

                            if (client != null)
                            {
                                client.UserId = newUser.UserId;

                                ClientManager.Save(client);
                            }
                        }
                        catch (Exception ex) {
                            lblMessage.Text     = "Unable to create new user account.";
                            lblMessage.CssClass = "error";

                            Core.EmailHelper.emailError(ex);
                        }
                    }
                    else
                    {
                        // update user
                        if (int.TryParse(hfuserid.Value, out userID) && userID > 0)
                        {
                            user = SecUserManager.GetByUserId(userID);

                            if (user != null)
                            {
                                user.FirstName = txtFirstName.Text.Trim();
                                user.LastName  = txtLastName.Text.Trim();

                                if (!string.IsNullOrEmpty(txtUserPassword.Text))
                                {
                                    user.Password = SecurityManager.Encrypt(txtUserPassword.Text.Trim());
                                }

                                SecUserManager.Save(user);
                            }
                        }
                    }

                    lblMessage.Text     = "Client changes saved.";
                    lblMessage.CssClass = "ok";
                }
                catch (Exception ex) {
                    lblMessage.Text     = "Unable to create new user account.";
                    lblMessage.CssClass = "error";

                    Core.EmailHelper.emailError(ex);
                }
            }             // if (client != null) {


            // clear after edit
            //Session.Remove("EditClientId");

            //Response.Redirect("~/Protected/Admin/ClientList.aspx");
        }