Beispiel #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string urlCurrent                = HttpContext.Current.Request.Url.AbsolutePath;
        string urlChangePassword         = Navigation.User_ChangePassword().GetServerUrl(true);
        string urlChangePasswordFilename = urlChangePassword.Substring(urlChangePassword.LastIndexOf("/") + 1);

        if (Page.User.Identity.IsAuthenticated && !urlCurrent.Contains(urlChangePasswordFilename))
        {
            User currentUser = MembershipManager.GetUserByName(Page.User.Identity.Name);

            LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName;

            if (loginName != null)
            {
                loginName.FormatString = Utilities.GetDisplayUserFirstName(currentUser.Name);
            }
            if (currentUser.PasswordChangeRequired)
            {
                Response.Redirect(Navigation.User_ChangePassword().GetServerUrl(true));
            }
        }

        // Retrieve the client version number, add it to lblVersionNumber.
        string fileName = Path.Combine(Server.MapPath("~"), "Version.txt");

        if (File.Exists(fileName))
        {
            lblVersionNumber.Text = File.ReadAllText(fileName);
        }

        Page.Title = "BusiBlocks - " + Page.Title;

        DisplayAnyFeedback();
    }
Beispiel #2
0
    protected string GenerateLogonId(string firstName, string lastName)
    {
        string logonId = string.Empty;

        // Check the txtUserId field first. If not null, then don't generate a new one.
        if (string.IsNullOrEmpty(txtUserId.Text))
        {
            // Auto generate a userid.
            logonId = firstName.Replace(" ", string.Empty) + lastName.Replace(" ", string.Empty);
            if (logonId.Length > 18)
            {
                logonId = logonId.Substring(0, 18);
            }
        }
        else
        {
            logonId = txtUserId.Text;
        }

        int       iterator        = 1;
        string    originalLogonId = logonId;
        const int circuitBreaker  = 100;

        while (MembershipManager.GetUserByName(logonId) != null && circuitBreaker > iterator)
        {
            logonId = originalLogonId + iterator.ToString();
            ++iterator;
        }
        return(logonId);
    }
Beispiel #3
0
    private MailMessage CreateMessageFromTemplate(FeedbackForm form)
    {
        MailMessage message     = new MailMessage();
        var         xmlDocument = new XmlDocument();

        string xmlFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/MailTemplate_Feedback.xml");

        xmlDocument.Load(xmlFile);
        XmlNodeList blockNodes = xmlDocument.GetElementsByTagName("body");


        foreach (XmlNode node in blockNodes)
        {
            message.Body = node.InnerText;
        }

        User   user   = MembershipManager.GetUserByName(form.UserId);
        Person person = PersonManager.GetPersonByUserId(user.Id);

        message.From = new MailAddress((!string.IsNullOrEmpty(person.Email)) ? person.Email : "*****@*****.**");
        message.To.Add(new MailAddress("*****@*****.**"));
        message.Subject = form.Type + "-" + form.Subject;
        message.Body    = ReplaceTokens(message.Body, form, user, person);

        return(message);
    }
        public static bool IsApprover(string username, string ItemId)
        {
            bool isApprover = false;

            if (username == "admin")
            {
                isApprover = true;
            }
            else
            {
                string userId = MembershipManager.GetUserByName(username).Id;

                IList <Approver> approvers = ApproverManager.GetApproversByItem(ItemId);
                foreach (Approver approver in approvers)
                {
                    if ((!string.IsNullOrEmpty(approver.UserId)) && (approver.UserId == userId))
                    {
                        isApprover = true;
                    }


                    if (string.IsNullOrEmpty(approver.UserId))
                    {
                        if (!string.IsNullOrEmpty(approver.CategoryId))
                        {
                            if (SecurityHelper.CanUserEdit(username, approver.CategoryId))
                            {
                                isApprover = true;
                            }
                        }
                    }
                }
            }
            return(isApprover);
        }
    private void RecyclePrivateMessage(string divider, string subjectPrefix)
    {
        string subject = lblSubject.Text;

        if (subject.IndexOf(subjectPrefix) != 0)
        {
            subject = subjectPrefix + subject;
        }

        PrivateMessage pm = PrivateMessagesManager.GetPrivateMessage(hidPrivateMessageId.Value);

        string parentPrivateMessage = hidPrivateMessageId.Value;
        User   fromUser             = MembershipManager.GetUserByName(lblFrom.Text);

        string from = pm.Sender.Person.FirstName + " " + pm.Sender.Person.LastName + " (" + pm.Sender.Name + ")";

        ResetAll();

        hidPrivateMessageId.Value = parentPrivateMessage;
        txtNewTo.Text             = fromUser.Person.FirstName + " " + fromUser.Person.LastName + " (" + fromUser.Name + "), ";;
        txtNewSubject.Text        = subject;
        txtNewBody.Text           = string.Format(RecyledPrivateMessage, divider, from, pm.SentDate.ToString(), pm.Recipients, txtNewSubject.Text, pm.Body);

        divNewPrivateMessage.Visible = true;
    }
    private void BindSentbox(string sortExpression)
    {
        User currentUser          = MembershipManager.GetUserByName(Parent.Page.User.Identity.Name);
        List <PrivateMessage> pms = PrivateMessagesManager.GetAllSentPrivateMessages(currentUser).ToList <PrivateMessage>();

        BindList(pms, sortExpression);
    }
Beispiel #7
0
    protected void btnReject_Click(object sender, EventArgs e)
    {
        Item.ApprovalStatus     = ItemApprovalStatusManager.GetDraftStatus();
        Item.ActionedByPersonId = MembershipManager.GetUserByName(Page.User.Identity.Name).Id;
        Item.ActionedNotes      = popReject.Value;
        Item.ActionedOnDate     = DateTime.Now;

        NewsManager.UpdateItem(Item);
        Navigation.Communication_News().Redirect(this);
    }
Beispiel #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         currentUser = MembershipManager.GetUserByName(Page.User.Identity.Name);
         if (currentUser.PasswordChangeRequired)
         {
             heading.InnerText = "Change password required";
             ChangePassword1.ChangePasswordTitleText = "Your password was reset recently and you are <br>required to change it before you can continue.<br>&nbsp;";
             ChangePassword1.CancelButtonText        = "Log Out";
             ChangePassword1.CancelButtonClick      += new EventHandler(ChangePassword1_CancelButtonClick);
         }
     }
 }
Beispiel #9
0
    public static string GetDisplayUserFirstName(string userName)
    {
        if (string.IsNullOrEmpty(userName))
        {
            throw new ArgumentNullException(userName);
        }

        User user = MembershipManager.GetUserByName(userName);

        if (user == null)
        {
            return(Anonymous);
        }
        else
        {
            return(user.Person.FirstName);
        }
    }
 /// <summary>
 /// A Custom list of PersonWithUser constructed by searching the concatenated primary and secondary sites. Acts like a custom filter.
 /// </summary>
 /// <param name="personsAndUsers"></param>
 /// <param name="siteName"></param>
 protected void AddSiteToList(List <PersonWithUser> personsAndUsers, string siteName)
 {
     if (!string.IsNullOrEmpty(siteName))
     {
         //setting the DS to original list to perform filtering. Only assign it once when this function is called in loop for ',' seperated list.
         if (RadGrid1.DataSource != originalDS)
         {
             RadGrid1.DataSource = originalDS;
             RadGrid1.DataBind();
         }
         //loop through the radgrid rows.Combine primary and secondary sites and check if site name exists in it.
         foreach (GridDataItem item in RadGrid1.Items)
         {
             string userName          = ((LinkButton)item["LoginId"].FindControl("imgBtnView")).Text;
             Label  lblPrimarySite    = (Label)item["PrimarySite"].FindControl("lblPrimarySite");
             Label  lblSecondarySites = (Label)item["PrimarySite"].FindControl("lblSecondarySites");
             string sites             = lblPrimarySite.Text + lblSecondarySites.Text;
             //if site name is existing in the concatenated string then add it to the PersonUser list.
             if (!string.IsNullOrEmpty(userName) && sites.ToLower().Contains(siteName.ToLower()))
             {
                 Person person      = PersonManager.GetPersonByUserName(userName);
                 User   user        = MembershipManager.GetUserByName(userName);
                 Site   defaultSite = PersonManager.GetDefaultSiteByPerson(person);
                 if (defaultSite == null)
                 {
                     defaultSite = new Site();
                 }
                 if (person != null && user != null)
                 {
                     PersonWithUser personUser = new PersonWithUser()
                     {
                         Person = person, User = user, PrimarySite = defaultSite
                     };
                     personsAndUsers.Add(personUser);
                 }
             }
         }
     }
 }
    private void OpenPrivateMessage(string privateMessageId)
    {
        ResetAll();
        divList.Visible           = false;
        hidPrivateMessageId.Value = privateMessageId;

        PrivateMessage msg = PrivateMessagesManager.GetPrivateMessage(privateMessageId);

        if (msg != null)
        {
            User currentUser = MembershipManager.GetUserByName(Page.User.Identity.Name);
            if (currentUser.Id == msg.Recipient.Id || currentUser.Id == msg.Sender.Id)
            {
                if (msg.ReadDate == null)
                {
                    PrivateMessagesManager.MarkAsRead(msg);
                }

                divViewPrivateMessage.Visible = true;

                lblDateSent.Text = PrivateMessagesManager.FormatDateForDisplay(msg.SentDate);
                lblTo.Text       = msg.Recipients;
                lblFrom.Text     = msg.Sender.Name;
                lblSubject.Text  = msg.Subject;
                txtBody.Text     = msg.Body;
            }
            else
            {
                ((IFeedback)Page.Master).SetError(GetType(), ErrorPermissionDenied);
            }
        }
        else
        {
            ((IFeedback)Page.Master).SetError(GetType(), ErrorUnableToOpen);
        }
    }
        void context_PostAcquireRequestState(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            HttpContext context = application.Context;
            MembershipManager membershipManager = new MembershipManager(null);
            AccessControlPrincipal principal = null;
            DataEntities.User user = null;
            System.Security.Principal.IIdentity identity = null;

            if (IsValid)
            {
                context.Trace.Warn("Role Module Begin");

                #region Cookies

                if ((!Roles.CookieRequireSSL || context.Request.IsSecureConnection))
                {
                    if (Roles.CacheRolesInCookie)
                    {
                        HttpCookie cookie = context.Request.Cookies[Roles.CookieName];

                        if (cookie != null && cookie.Value != null)
                        {
                            if (!string.IsNullOrEmpty(Roles.CookiePath) && (Roles.CookiePath != "/"))
                                cookie.Path = Roles.CookiePath;

                            if (Roles.CookieProtectionValue == CookieProtection.Encryption)
                                cookie.Value = cookie.Value.Decrypt().Decompress();

                            cookie.Domain = Roles.Domain;
                            context.User = HttpUtility.UrlDecode(cookie.Value).Deserialize<AccessControlPrincipal>();
                        }
                        else { Roles.DeleteCookie(); }
                    }
                    else { Roles.DeleteCookie(); }

                }
                else { Roles.DeleteCookie(); }

                #endregion

                identity = context.User.Identity;
                principal = new AccessControlPrincipal(user, identity);

                if (context.Session != null && context.Session[context.Session.SessionID] != null && identity.IsAuthenticated)
                    principal = context.Session[context.Session.SessionID] as AccessControlPrincipal;


                if (String.IsNullOrEmpty(principal.Name) && !String.IsNullOrEmpty(identity.Name))
                {
                    user = membershipManager.GetUserByName(identity.Name);
                    if (user != null)
                    {
                        bool timeoutExpired = DateTime.Now.Subtract(user.LastActivityDate).Minutes > System.Web.Security.Membership.UserIsOnlineTimeWindow;
                        user.LastActivityDate = DateTime.Now;
                        user.IsOnline = !timeoutExpired;

                        membershipManager.DbContext.SubmitChanges();
                        membershipManager.DataManager.Commit();
                    }

                    principal = new AccessControlPrincipal(user, identity);
                }


                if (context.Application["Session_End"] == null)
                    context.Application["Session_End"] = new EventHandler(OnSessionEnd);

                //
                // Cache the user in session to dont query database
                //
                if (context.Session != null && identity.IsAuthenticated)
                    context.Session[context.Session.SessionID] = principal;

                System.Threading.Thread.CurrentPrincipal = principal;
                context.User = principal;

                context.Trace.Warn("Role Module End");
            }
        }
Beispiel #13
0
    private void BindApprovers()
    {
        //get the groups under the category
        //get the users in that group
        //bind the users to the drop down

        //clear the dropdown list
        ddlApprovers.Items.Clear();
        ddlApprovers.Enabled = false;

        ddlOwner.Items.Clear();
        ddlOwner.Enabled = true;

        if (!string.IsNullOrEmpty(currentSelectedNode))
        {
            IList <Access> accessList = AccessManager.GetItemEdittables(currentSelectedNode);
            bool           canEdit    = false;

            if (SecurityHelper.CanUserEdit(Page.User.Identity.Name, currentSelectedNode))
            {
                canEdit = true;
            }
            else if (SecurityHelper.CanUserContribute(Page.User.Identity.Name, currentSelectedNode))
            {
                User currentUser = MembershipManager.GetUserByName(Page.User.Identity.Name);
                ddlOwner.Items.Add(new ListItem(currentUser.Name, currentUser.Id));
            }
            if (canEdit)
            {
                foreach (Access access in accessList)
                {
                    IList <Person> persons = PersonManager.GetAllPersons();

                    foreach (Person person in persons)
                    {
                        User user = MembershipManager.GetUserByPerson(person);
                        if (!string.IsNullOrEmpty(user.Name))
                        {
                            if (ddlOwner.Items.FindByText(user.Name) == null)
                            {
                                if (SecurityHelper.CanUserEdit(user.Name, currentSelectedNode))
                                {
                                    ddlOwner.Items.Add(new ListItem(user.Name, user.Id));
                                }
                            }

                            //APPROVERS NOT REQUIRED AT THIS RELEASE - 19/06/2012
                            //if (ddlApprovers.Items.FindByText(user.Name) == null)
                            //{
                            //    ddlApprovers.Items.Add(new ListItem(user.Name, user.Id));
                            //}
                        }
                    }
                }
            }
            //ddlApprovers.Items.Insert(0, new ListItem("--All Approvers--", ""));
            if (ddlOwner.Items.FindByText("admin") == null)
            {
                User admin = MembershipManager.GetUserByName("admin");
                ddlOwner.Items.Insert(0, new ListItem(admin.Name, admin.Id));
            }

            if ((Item != null) && (Item.Owner != null) && (ddlOwner.Items.FindByValue(Item.Owner) == null))
            {
                User currentUser = MembershipManager.GetUserByName(Item.Owner);
                ddlOwner.Items.Insert(0, new ListItem(currentUser.Name, currentUser.Id));
                ddlOwner.SelectedIndex = ddlOwner.Items.IndexOf(ddlOwner.Items.FindByText(Item.Owner));
            }
        }
    }
Beispiel #14
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int?depositId      = null;
        int?representantId = null;

        if (!String.IsNullOrEmpty(cboDeposit.SelectedValue))
        {
            depositId = Convert.ToInt32(cboDeposit.SelectedValue);
        }

        if (!String.IsNullOrEmpty(cboRepresentant.SelectedValue))
        {
            representantId = Convert.ToInt32(cboRepresentant.SelectedValue);
        }

        //
        //Update User
        //
        if (!String.IsNullOrEmpty(Request["UserId"]))
        {
            var originalUser = CompanyManager.GetUser(Company.CompanyId, Convert.ToInt32(Page.ViewState["UserId"]));

            if (originalUser.UserName != txtUserName.Text && CompanyManager.ExistsUserInCompany(Company.CompanyId, txtUserName.Text))
            {
                ShowError(Exception.ExistentMail);
                return;
            }

            CompanyManager.UpdateUser(Company.CompanyId, Convert.ToInt32(Page.ViewState["UserId"]), depositId, representantId, ucProfile.ProfileEntity, SaveUser());

            RefreshDeposit();
            RefreshCredentials();
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "parent.location='Users.aspx'", true);
            return;
        }

        //
        // Verifies if the User already exist in company
        //

        if (CompanyManager.ExistsUserInCompany(Company.CompanyId, txtUserName.Text))
        {
            ShowError(Exception.ExistentMail);
            return;
        }

        var oldUser = MembershipManager.GetUserByName(txtUserName.Text);

        if (oldUser != null)
        {
            CompanyManager.UpdateUser(Company.CompanyId, oldUser.UserId, depositId, representantId, ucProfile.ProfileEntity, SaveUser());

            RefreshCredentials();
            Response.Redirect("User.aspx?UserId=" + oldUser.UserId);
            return;
        }

        //
        // Insert user
        //

        var newUser = SaveUser();
        InsertCompanyStatus status = CompanyManager.InsertUser(Company.CompanyId, depositId, representantId,

                                                               newUser, ucProfile.ProfileEntity);

        switch (status)
        {
        case InsertCompanyStatus.InvalidPassword:
            ShowError(Exception.InvalidPassword);
            break;

        case InsertCompanyStatus.InvalidUser:
        case InsertCompanyStatus.DuplicateCNPJ:
        case InsertCompanyStatus.DuplicatedAdminEmail:
        case InsertCompanyStatus.DuplicatedUserName:
            ShowError(Exception.ExistentMail);
            break;

        case InsertCompanyStatus.Success:

            Response.Redirect("User.aspx?UserId=" + newUser.UserId);
            break;
        }
        RefreshCredentials();
    }
Beispiel #15
0
    protected void btCreateAdmin_Click(object sender, EventArgs e)
    {
        // Create a person type, and a role, and a persontyperole.
        PersonType adminPersonType = new PersonType();

        adminPersonType.Name = BusiBlocks.BusiBlocksConstants.AdministratorsGroup;
        var personTypes = PersonManager.GetAllPersonTypes(true).FirstOrDefault(x => x.Name.Equals(adminPersonType.Name));

        if (personTypes == null)
        {
            PersonManager.CreatePersonType(adminPersonType);
        }
        adminPersonType = PersonManager.GetAllPersonTypes(true).FirstOrDefault(x => x.Name.Equals(adminPersonType.Name));
        Role role = RoleManager.GetRoleByName(txtAdminRole.Text);

        if (role == null)
        {
            Roles.CreateRole(txtAdminRole.Text);
        }
        PersonTypeRole personTypeRole = new PersonTypeRole();

        personTypeRole.PersonType = adminPersonType;
        Role role1 = RoleManager.GetRoleByName(txtAdminRole.Text);

        personTypeRole.Role = role1;
        var personTypeRole1 = PersonManager.GetAllPersonTypeRoles().FirstOrDefault(x => (x.Role.Name.Equals(role1.Name) && x.PersonType.Name.Equals(personTypeRole.PersonType.Name)));

        if (personTypeRole1 == null)
        {
            PersonManager.CreatePersonTypeRole(personTypeRole);
        }

        string pwd = txtAdminPassword.Text;

        MembershipUser user2 = Membership.GetUser(txtAdminUser.Text);

        if (user2 == null)
        {
            Membership.CreateUser(txtAdminUser.Text, pwd, txtAdminEMail.Text);
        }
        MembershipUserCollection col     = Membership.FindUsersByName(txtAdminUser.Text);
        MembershipUser           memUser = col[txtAdminUser.Text];
        User user = MembershipManager.GetUser(memUser.ProviderUserKey.ToString());

        var roles1 = RoleManager.GetRolesByUser(user).FirstOrDefault(x => x.Name.Equals(role1.Name));

        if (roles1 == null)
        {
            RoleManager.AddUserToRole(user, role1);
        }

        // Find a Person who matches this User.
        // If none exists, create one.
        string userName = txtAdminUser.Text;
        Person person   = PersonManager.GetPersonByUserName(userName);

        if (person == null)
        {
            Address address1 = new Address();
            address1.Address1 = "1 Admin Drive";
            AddressManager.CreateAddress(address1);
            User user1 = MembershipManager.GetUserByName(userName);
            PersonManager.CreatePerson(user1, userName, address1);
            person = PersonManager.GetPersonByUserId(user1.Id);
        }
        var personType1 = PersonManager.GetPersonTypesByPerson(person).FirstOrDefault(x => x.Name.Equals(adminPersonType.Name));

        if (personType1 == null)
        {
            PersonManager.AddPersonToPersonType(person.Id, adminPersonType.Id);
        }

        lblStatus.InnerText = "User created!";
    }
    private void SendPrivateMessage()
    {
        if (string.IsNullOrEmpty(txtNewSubject.Text.Trim()))
        {
            ((IFeedback)Page.Master).SetError(GetType(), ErrorSubjectEmpty);
        }
        if (string.IsNullOrEmpty(txtNewBody.Text.Trim()))
        {
            ((IFeedback)Page.Master).SetError(GetType(), ErrorBodyEmpty);
        }
        else
        {
            bool illFormedRecipientString = false;

            List <User> users = new List <User>();

            foreach (string recipient in txtNewTo.Text.Split(','))
            {
                if (!string.IsNullOrEmpty(recipient.Trim()))
                {
                    if ((recipient.IndexOf("(") < 0 || recipient.IndexOf(")") < 0) ||
                        (recipient.LastIndexOf("(") != recipient.IndexOf("(")) ||
                        (recipient.LastIndexOf(")") != recipient.IndexOf(")")))
                    {
                        illFormedRecipientString = true;
                    }
                    else
                    {
                        string username = (recipient.Split('(')[1]).Split(')')[0];;
                        try
                        {
                            User user = MembershipManager.GetUserByName(username);
                            if (user == null)
                            {
                                illFormedRecipientString = true;
                            }
                            else if (!users.Contains(user))
                            {
                                users.Add(user);
                            }
                        }
                        catch (Exception)
                        {
                            illFormedRecipientString = true;
                        }
                    }
                }
            }

            if (illFormedRecipientString || users.Count == 0)
            {
                ((IFeedback)Page.Master).SetError(GetType(), ErrorIllFormedRecipientString);
            }
            else
            {
                var  recipients = new StringBuilder();
                bool first      = true;
                foreach (User user in users)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        recipients.Append(", ");
                    }

                    recipients.Append(user.Person.FirstName);
                    recipients.Append(" ");
                    recipients.Append(user.Person.LastName);
                    recipients.Append(" (");
                    recipients.Append(user.Name).Append(")");
                }

                foreach (User user in users)
                {
                    var pMsg = new PrivateMessage();
                    pMsg.Recipient  = user;
                    pMsg.Sender     = MembershipManager.GetUserByName(Page.User.Identity.Name);
                    pMsg.Recipients = recipients.ToString();
                    pMsg.Subject    = txtNewSubject.Text;
                    pMsg.Body       = txtNewBody.Text;
                    string parentPrivateMessageId = hidPrivateMessageId.Value;
                    if (!string.IsNullOrEmpty(parentPrivateMessageId))
                    {
                        PrivateMessage parentMessage = PrivateMessagesManager.GetPrivateMessage(parentPrivateMessageId);
                        if (parentMessage != null)
                        {
                            pMsg.ParentPrivateMessage = parentMessage;
                        }
                    }
                    PrivateMessagesManager.Send(pMsg);
                }
                OpenInbox();
            }
        }
    }