Esempio n. 1
0
        protected void btnSendMessage_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsValid)
                {
                    return;
                }

                if (Page as Trackr.Page == null)
                {
                    throw new ArgumentException("Page is not inheriting Trackr.Page");
                }

                int clubID = (Page as Trackr.Page).CurrentUser.ClubID;

                List<string> emailRecipients = txtRecipients.Text.Split(',').Select(i => i.Trim().ToUpper()).Distinct().ToList();

                using (TrackrModels.UserManagement um = new TrackrModels.UserManagement())
                {
                    List<int> recipients = um.WebUsers.Where(i => i.ClubID == clubID && emailRecipients.Contains(i.Email.ToUpper())).Select(i => i.UserID).Distinct().ToList();

                    Message message = new Message()
                    {
                        Body = txtMessage.Text,
                        CreateDate = DateTime.UtcNow,
                        FromID = int.Parse(Page.User.Identity.Name),
                    };

                    recipients.ForEach(i =>
                    {
                        message.MessageRecipients.Add(new MessageRecipient()
                        {
                            UserID = i,
                            SentDate = DateTime.UtcNow
                        });
                    });

                    um.Add(message);
                    um.SaveChanges();

                    txtRecipients.Text = "";
                    txtMessage.Text = "";


                    Master.AddAlert("Successfully sent message.", UI.AlertBoxType.Success);
                    divCompose.Visible = false;
                    upNested.Update();
                    ScriptManager.RegisterStartupScript(upModal, upModal.GetType(), "ToggleCompose", "$('.modal-backdrop').remove()", true);
                }
            }
            catch (Exception ex)
            {
                Master.HandleException(ex);
            }
        }
Esempio n. 2
0
        public List<ScopeAssignment> GetScopeAssignments(int userID, string permission)
        {
            using (UserManagement um = new UserManagement())
            {
                Permission permObject = um.Permissions.Where(i => i.PermissionName == permission).FirstOrDefault();

                if (permObject == null)
                {
                    throw new Exception("Permission does not exist in the database.");
                }

                var allScopeAssignments = um.ScopeAssignments
                    .Include(i => i.Permission)
                    .Include(i => i.Role)
                    .Where(i => i.UserID == userID);

                var allRoleAssignments = allScopeAssignments.Where(i => !i.IsDeny && i.RoleID.HasValue && i.Role.Permissions.Contains(permObject));
                var allPermissionAssignments = allScopeAssignments.Where(i => !i.IsDeny && i.Permission == permObject);

                return allRoleAssignments.Union(allPermissionAssignments).ToList();
            }
        }
Esempio n. 3
0
        private List<MyLink> GetPermissionedLinksFromDB()
        {
            using(UserManagement um = new UserManagement())
            using (WebUsersController wuc = new WebUsersController())
            using(LinksController lc = new LinksController())
            {
                FetchStrategy fetch = new FetchStrategy();
                fetch.LoadWith<Link>(i => i.LinkGroup);
                fetch.LoadWith<Link>(i => i.Glyphicon);
                fetch.LoadWith<LinkGroup>(i => i.Glyphicon);
                fetch.LoadWith<Link>(i => i.LinkPermissions);


                IEnumerable<ScopeAssignment> assignedScopes = um.ScopeAssignments.Where(i => i.UserID == CurrentUser.UserID);

                // if user has even one allowed permission, then we need to add it. need to do it by permission then by role
                var allowedByPermission = assignedScopes.Where(i => i.PermissionID.HasValue && !i.IsDeny).Select(i => i.PermissionID.Value);
                var allowedByRole = assignedScopes.Where(i => i.RoleID.HasValue && !i.IsDeny).Select(i => i.Role).SelectMany(i => i.Permissions).Select(i => i.PermissionID);

                List<int> allowed = allowedByPermission.Union(allowedByRole).Distinct().ToList();
                
                // now get the links
                var links = lc.GetWhere(i => i.LinkPermissions.Count() == 0 || i.LinkPermissions.Where(j => !j.IsDeny && allowed.Contains(j.PermissionID)).Count() > 0, fetch);

                var noGroups = links.Where(i => !i.LinkGroupID.HasValue)
                    .OrderBy(i => i.SortOrder)
                    .Select(i => new MyLink()
                    {
                        IsGroup = false,
                        Glyphicon = i.GlyphiconID.HasValue ? i.Glyphicon.Glyphicon1 : null,
                        Name = i.LinkName,
                        CurrentModulePattern = i.CurrentModulePattern,
                        LinkURL = i.LinkURL,
                        Tooltip = i.LinkTitle,
                        ShowInMobileNav = i.ShowInMobileNav
                    }).ToList();

                var groups = links.Where(i => i.LinkGroupID.HasValue)
                    .GroupBy(i => i.LinkGroupID)
                    .OrderBy(i => i.First().LinkGroup.SortOrder)
                    .Select(i => new MyLink()
                    {
                        IsGroup = true,
                        Name = i.First().LinkGroup.LinkGroupName,
                        Glyphicon = i.First().LinkGroup.GlyphiconID.HasValue ? i.First().LinkGroup.Glyphicon.Glyphicon1 : null,
                        CurrentModulePattern = i.First().LinkGroup.CurrentModulePattern,
                        Tooltip = i.First().LinkGroup.LinkGroupName,
                        ShowInMobileNav = i.First().LinkGroup.ShowInMobileNav,
                        MyLinks = i.OrderBy(j => j.SortOrder).Select(j => new MyLink()
                        {
                            Glyphicon = j.GlyphiconID.HasValue ? j.Glyphicon.Glyphicon1 : null,
                            IsGroup = false,
                            Name = j.LinkName,
                            CurrentModulePattern = j.CurrentModulePattern,
                            Tooltip = j.LinkTitle,
                            LinkURL = j.LinkURL,
                            ShowInMobileNav = j.ShowInMobileNav
                        }).ToList()
                    }).ToList();

                List<MyLink> myLinks = new List<MyLink>();
                myLinks.AddRange(noGroups);
                myLinks.AddRange(groups);

                return myLinks;
            }
        }
Esempio n. 4
0
        private static void UpdateScopingForGuardians(int playerID)
        {
            // make sure all guardians have parent scope to this player, and remove old ones if not explicit
            // since we are deleting and re-adding we will use a transaction

            using (ClubManagement cm = new ClubManagement())
            using (TrackrModels.UserManagement um = new TrackrModels.UserManagement())
            {
                try
                {
                    List<int> userIDs = cm.Guardians.Where(i => i.PlayerID == playerID && i.Person.UserID.HasValue && i.Active).Select(i => i.Person.UserID.Value).Distinct().ToList();

                    // delete assignments for this player
                    IQueryable<ScopeAssignment> assignmentsToDelete = um.ScopeAssignments.Where(i => i.ResourceID == playerID && i.ScopeID == 4 && i.RoleID == 6 && !i.IsExplicit);
                    um.Delete(assignmentsToDelete);

                    // add assignments back in
                    foreach (int userID in userIDs)
                    {
                        ScopeAssignment assignment = new ScopeAssignment()
                        {
                            IsDeny = false,
                            ResourceID = playerID,
                            RoleID = 6,
                            ScopeID = 4,
                            UserID = userID,
                            IsExplicit = false
                        };

                        um.Add(assignment);
                    }

                    // commit
                    um.SaveChanges();
                }
                catch (Exception ex)
                {
                    um.ClearChanges();
                    ex.HandleException();
                }
            }
        }
Esempio n. 5
0
        protected void lnkCreateAccount_Click(object sender, EventArgs e)
        {
            LinkButton btn = (LinkButton)sender;
            int personID = int.Parse(btn.CommandArgument);

            hdnPersonID.Value = personID.ToString();

            using (TrackrModels.UserManagement um = new TrackrModels.UserManagement())
            {
                List<string> emailAddressesForGuardian = NonUserGuardianResults.First(i => i.PersonID == personID).EmailAddresses;

                radioList.DataSource = emailAddressesForGuardian;
                radioList.DataBind();

                litGuardianName.Text = NonUserGuardianResults.First(i => i.PersonID == personID).FirstName + " " + NonUserGuardianResults.First(i => i.PersonID == personID).LastName;
                litPlayerNames.Text = string.Join(", ", NonUserGuardianResults.First(i => i.PersonID == personID).Players);

                ScriptManager.RegisterStartupScript(this, this.GetType(), "modal", "$('.add-non-user-guardian-as-user').modal('toggle')", true);
            }
        }
Esempio n. 6
0
        protected void btnCreateUserAccounts_Click(object sender, EventArgs e)
        {
            int personID = int.Parse(hdnPersonID.Value);
            string email = radioList.SelectedValue.Trim();
            string password = txtPassword.Text.Trim();

            List<int> playerIDs = NonUserGuardianResults.First(i=>i.PersonID == personID).PlayerIDs.Distinct().ToList();

            using(TrackrModels.UserManagement um = new TrackrModels.UserManagement())
            using (ClubManagement cm = new ClubManagement())
            using (NewUserMappingsController numc = new NewUserMappingsController())
            {
                MembershipCreateStatus status;
                MembershipUser user = Membership.CreateUser(email, password, email, null, null, true, out status);

                switch (status)
                {
                    case MembershipCreateStatus.Success:
                        int userID = (int)user.ProviderUserKey;

                        um.WebUsers.First(i => i.UserID == userID).ClubID = CurrentUser.ClubID;
                        um.SaveChanges();

                        var roleIDs = numc.GetWhere(i => i.ClubID == CurrentUser.ClubID).Select(i => i.RoleID).Distinct().ToList();

                        foreach (int roleID in roleIDs)
                        {
                            ScopeAssignment assignment = new ScopeAssignment()
                            {
                                IsDeny = false,
                                ScopeID = 5,
                                UserID = userID,
                                ResourceID = userID,
                                RoleID = roleID
                            };
                            um.Add(assignment);
                        }

                        foreach (int playerID in playerIDs)
                        {
                            ScopeAssignment assignment = new ScopeAssignment()
                            {
                                IsDeny = false,
                                ScopeID = 4, //player scope
                                UserID = userID,
                                ResourceID = playerID,
                                RoleID = 6 //parent role
                            };
                            um.Add(assignment);
                        }

                        cm.Add(new WebUserInfo()
                        {
                            FName = "",
                            LName = "",
                            UserID = userID
                        });

                        try
                        {
                            // try to save scoep assignments, if it fails then rollback user. i.e. delete user
                            um.SaveChanges();
                            cm.SaveChanges();

                            Person person =cm.People.First(i => i.PersonID == personID);
                            person.UserID = userID;

                            cm.SaveChanges();

                            try
                            {
                                List<Trackr.Utils.Messenger.EmailRecipient> recipients = new List<Trackr.Utils.Messenger.EmailRecipient>();
                                recipients.Add(new Trackr.Utils.Messenger.EmailRecipient()
                                {
                                    Email = email,
                                    Name = person.FName + " " + person.LName,
                                    RecipientType = Trackr.Utils.Messenger.EmailRecipientType.TO
                                });

                                List<Trackr.Utils.Messenger.TemplateVariable> variables = new List<Trackr.Utils.Messenger.TemplateVariable>();
                                variables.Add(new Trackr.Utils.Messenger.TemplateVariable()
                                {
                                    VariableName = "PersonName",
                                    VariableContent = person.FName + " " + person.LName
                                });
                                variables.Add(new Trackr.Utils.Messenger.TemplateVariable()
                                {
                                    VariableName = "LoginEmail",
                                    VariableContent = email
                                });
                                variables.Add(new Trackr.Utils.Messenger.TemplateVariable()
                                {
                                    VariableName = "LoginPassword",
                                    VariableContent = password
                                });

                                Trackr.Utils.Messenger.SendEmail("user-account-created", null, variables, recipients, false, false);

                                AlertBox.AddAlert(string.Format("Successfully created user account for {0} and emailed them their login information.", email));
                            }
                            catch (Exception ex)
                            {
                                Guid guid = ex.HandleException();
                                AlertBox.AddAlert(string.Format("Successfully created user account for {0} but failed to email them their login information. Reference #: " + guid, email), false, UI.AlertBoxType.Error);
                            }
                            finally
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "modal", "$('.modal-backdrop').remove()", true);
                                gvAllNonUsers.DataBind();

                                uP_Main.Update();
                            }
                        }
                        catch (Exception ex)
                        {
                            Guid guid = ex.HandleException();
                            CreateAlertBox.AddAlert("An error occurred while trying to create new user from guardian. Please try again. Reference #: " + guid, false, UI.AlertBoxType.Error);
                            um.ClearChanges();
                            cm.ClearChanges();

                            // remove any assignments
                            um.Delete(um.ScopeAssignments.Where(i => i.UserID == userID).ToList());
                            um.Delete(um.WebUsers.First(i => i.UserID == userID));
                            um.SaveChanges();
                        }
                        break;

                    default:
                        CreateAlertBox.AddAlert("Unable to create new user from guardian for the following reason: " + status.ToString(), false, UI.AlertBoxType.Error);
                        break;
                }
            }
        }
Esempio n. 7
0
        protected void validatorRecipientListOK_ServerValidate(object source, ServerValidateEventArgs args)
        {
            try
            {
                if (Page as Trackr.Page == null)
                {
                    throw new ArgumentException("Page is not inheriting Trackr.Page");
                }

                int clubID = (Page as Trackr.Page).CurrentUser.ClubID;

                List<string> emailRecipients = txtRecipients.Text.Split(',').Select(i => i.Trim()).Distinct().ToList();
                List<string> emailRecipientsUpper = emailRecipients.Select(i => i.Trim().ToUpper()).Distinct().ToList();

                using (TrackrModels.UserManagement um = new TrackrModels.UserManagement())
                {

                    List<string> recipientsNotAuthorizedFor = um.WebUsers.Where(i => emailRecipientsUpper.Contains(i.Email.ToUpper()) && i.ClubID != clubID)
                        .Select(i => i.Email).Distinct().ToList();

                    List<string> existingEmails = um.WebUsers.Where(i => emailRecipientsUpper.Contains(i.Email.ToUpper())).Select(i => i.Email.ToUpper()).Distinct().ToList();

                    List<string> nonExistantEmails = emailRecipients.Where(i => !existingEmails.Contains(i.ToUpper())).Distinct().ToList();


                    validatorRecipientListOK.ErrorMessage = string.Format(validatorRecipientListOK.ErrorMessage, string.Join(", ", recipientsNotAuthorizedFor.Union(nonExistantEmails).OrderBy(i => i)));
                    args.IsValid = recipientsNotAuthorizedFor.Count() == 0 && nonExistantEmails.Count() == 0;
                }
            }
            catch (Exception ex)
            {
                Master.HandleException(ex);
                args.IsValid = false;
            }
        }