Exemplo n.º 1
0
        private void cmdUpdate_Click(object sender, System.EventArgs e)
        {
            //Validate password
            if (txtNewPassword.Text.Length > 0) {
                if (!(new Users(Globals.CurrentIdentity)).IsValid(Globals.CurrentUserName, txtOldPassword.Text)) {
                    PageError("Error: Old password is incorrect");
                    return;
                }
                if (txtNewPassword.Text != txtRepeat.Text){
                    PageError("Error: New passwords do not match (Make sure you type carefully!)");
                    return;
                }

                try {
                    (new Users(Globals.CurrentIdentity)).ChangePassword(Globals.CurrentUserName, txtNewPassword.Text);
                } catch (DataAccessException er) {
                    PageError(er.Message); return;
                }
            }

            User user = new User();
            user.FirstName = txtFirst.Text; user.LastName = txtLast.Text;
            user.Email = txtEmail.Text; user.UserName = Globals.CurrentUserName;
            user.VerifyKey = "";

            try {
                (new Users(Globals.CurrentIdentity)).Update(user, null);
            } catch (DataAccessException er) {
                PageError(er.Message); return;
            }

            BindData();
            PageError("Success!");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a user to a section
        /// switchuser indicates that the user should be dropped 
        /// from all other sections
        /// Email owner of the group if actor != username
        /// </summary>
        public bool AddUser(int sectionID, string username, bool switchuser)
        {
            Section section = GetInfo(sectionID);
            //Check permission
            Authorize(section.CourseID, Permission.SECTION, "update", sectionID, null);

            //Check to see if the user is in this group already
            string actor = Identity.Name;
            User.UserList users = GetMembers(sectionID);
            User user = new User(); user.UserName = username;
            if (users.Contains(user))
                throw new DataAccessException("User already exists in the section");

            //Send email to the owner if the owner did not make the change

            if (actor != section.Owner)
                new EmailWizard(m_ident).SendByUsername(section.Owner, "FrontDesk Section Notification",
                    String.Format(Globals.GetMessage("SectionAdd"), actor, username, System.DateTime.Now));

            //TODO: Enforce policy of section membership

            //Create the membership
            m_dp.CreateSectionMember(sectionID, username, switchuser);

            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Group users into binsize groups
        /// </summary>
        public bool Group(User.UserList users, ArrayList groups, int binsize)
        {
            groups.Clear();
            groups.AddRange(Setup(users));
            while (Divide(groups, binsize) || Combine(groups, binsize));
            if (groups.Count == 1)
                return false;

            return true;
        }
Exemplo n.º 4
0
        protected string GetAsstPoints(User user, int asstID)
        {
            Components.Submission latsub =
                new Principals(Globals.CurrentIdentity).GetLatestGradedSubmission(user.PrincipalID, asstID);
            double total = new Assignments(Globals.CurrentIdentity).GetRubric(asstID).Points;

            if (latsub != null) {
                double userp = new Users(Globals.CurrentIdentity).GetAsstPoints(user.UserName, asstID);
                return String.Format("{0} / {1} ({2}%)", userp, total, Math.Round((userp/total)*100.0, 2));
            } else
                return String.Format("?? / {0}", total);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Regroup
 /// </summary>
 public void Regroup(string ubound, string lbound, User.UserList users)
 {
     int i;
     UserGroup group = new UserGroup();
     group.UpperBound = ubound; group.LowerBound = lbound;
     for (i = 0; i < users.Count; i++) {
         User user = users[i] as User;
         if (!group.InGroup(user.LastName)) {
             users.Remove(user);
             i--;
         }
     }
 }
        private void cmdUpdate_Click(object sender, System.EventArgs e)
        {
            User user = new User();

            user.UserName = GetUsername(); user.FirstName = txtFirst.Text;
            user.LastName = txtLast.Text; user.Email = txtEmail.Text;
            string role = ddlRoles.SelectedItem.Text;
            try {
                new Users(Globals.CurrentIdentity).Update(user, null);
                new Courses(Globals.CurrentIdentity).UpdateRole(user.UserName, GetCourseID(), role, null);
            } catch (CustomException er) {
                PageError(er.Message);
            }

            BindData();
            if (Refresh != null)
                Refresh(this, new RefreshEventArgs());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add users to the course from an XML stream
        /// </summary>
        public void BatchAddUsers(Stream xmlStream, int courseID, bool sync)
        {
            //TODO: Error checking
            User mem = new User();
            Users usersDB = new Users(m_ident);

            DataSet xmldata = new DataSet();
            xmldata.ReadXml(xmlStream);

            DataRowCollection users = xmldata.Tables["User"].Rows;

            IProviderTransaction tran = m_dp.BeginTransaction();
            foreach (DataRow row in users) {
                mem.UserName = (string) row["UserName"];
                string role = (string) row["Role"];

                //Make sure the user is in the system
                if (null == usersDB.GetInfo(mem.UserName, tran)) {
                    m_dp.RollbackTransaction(tran);
                    throw new DataAccessException("User: "******" is not in the FrontDesk database");
                }

                User.UserList cmems = GetMembers(courseID, tran);
                //The user already exists in the course
                if (cmems.Contains(mem)) {
                    if (sync)
                        UpdateRole(mem.UserName, courseID, role, tran);
                    else {
                        m_dp.RollbackTransaction(tran);
                        throw new DataAccessException("User: "******" already exists in the course. " +
                            "Do a merge if you want to change the roles");
                    }
                }
                else
                    m_dp.CreateCourseMember(mem.UserName, courseID, role, tran);
            }
            m_dp.CommitTransaction(tran);
        }
Exemplo n.º 8
0
 private TreeNode AddUserNode(TreeNodeCollection par, User user, int asstID, bool expand)
 {
     return AddNode(par, user.FullName + " (" + user.UserName + ")",
         "attributes/user.gif", "attributes/user.gif",
         "User " + user.UserName + " " + asstID, expand);
 }
Exemplo n.º 9
0
        private void SendVerifyEmail(User user)
        {
            string body = String.Format("To activate your FrontDesk account, please attempt to login and enter this verification key when prompted: {0} ",
                user.VerifyKey);

            new EmailWizard(m_ident).SendByEmail(user.Email, "FrontDesk Account Activation", body);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get a PrincipalList with the user and all their groups
        /// </summary>
        public Principal.PrincipalList GetPrincipals(string username, int asstID)
        {
            Principal.PrincipalList plist = new Principal.PrincipalList();
            User user = new User();

            //Add the user principal
            m_dp.GetUserInfo(username, user, null);
            plist.Add(user);

            //Add the groups
            Group.GroupList glist = m_dp.GetUserGroups(username, asstID);
            plist.AddRange(glist);

            return plist;
        }
Exemplo n.º 11
0
        private DataTable TabulateUsers(User.UserList users)
        {
            DataTable resulttab = new DataTable();
            int asstID = GetAsstID();
            Rubrics rubda = new Rubrics(Globals.CurrentIdentity);
            Principals prinda = new Principals(Globals.CurrentIdentity);
            Rubric asstrub = new Assignments(Globals.CurrentIdentity).GetRubric(asstID);

            //Add rubric columns to data grid
            Rubric.RubricList flatrub = rubda.Flatten(asstrub);
            resulttab.Columns.Add("UserName");
            resulttab.Columns.Add("Status");
            resulttab.Columns.Add("Total");
            foreach (Rubric rub in flatrub) {
                AddRubricColumn(rub.Name, rub.Name);
                resulttab.Columns.Add(rub.Name);
            }

            //Add user data to the datatable
            foreach (User user in users) {
                Components.Submission sub = prinda.GetLatestSubmission(user.PrincipalID, asstID);
                DataRow row = resulttab.NewRow();

                if (sub == null) continue;

                row["UserName"] = user.UserName;
                row["Status"] = sub.Status;
                row["Total"] = rubda.GetPoints(asstrub.ID, sub.ID).ToString() + "/" + asstrub.Points.ToString();
                foreach (Rubric rub in flatrub)
                    row[rub.Name] = GetRubricPoints(rub, sub.ID) + "/" + rub.Points.ToString();

                resulttab.Rows.Add(row);
            }

            return resulttab;
        }
Exemplo n.º 12
0
        private void BindUserItem(User user, Label lblName, Label numSubmissions, LinkButton lnkProgress,
            System.Web.UI.WebControls.Image imgStatus,
            System.Web.UI.WebControls.Image imgType, CheckBox chkSelect)
        {
            imgType.ImageUrl = "../../attributes/user.gif";
            lblName.Text = user.FullName + "(" + user.UserName + ")";
            if (lnkProgress == null) lnkProgress = new LinkButton();

            Principals prinda = new Principals(Globals.CurrentIdentity);
            Components.Submission sub = prinda.GetLatestSubmission(user.PrincipalID, GetAsstID());
            int numsubs = prinda.GetSubmissions(user.PrincipalID, GetAsstID()).Count;
            numSubmissions.Text = numsubs.ToString();

            if (sub == null) {
                imgStatus.ImageUrl = "../../attributes/nosub.gif";
                lnkProgress.Text = "N/A";
                chkSelect.Enabled = false;
            }
            else {
                switch (sub.Status) {
                    case Components.Submission.GRADED:
                        imgStatus.ImageUrl = "../../attributes/subgrade.gif";
                        lnkProgress.Text = "100%";
                        break;
                    case Components.Submission.INPROGRESS:
                        imgStatus.ImageUrl = "../../attributes/clock.gif";
                        lnkProgress.Text = "??%";
                        break;
                    case Components.Submission.UNGRADED:
                        imgStatus.ImageUrl = "../../attributes/sub.gif";
                        lnkProgress.Text = "0%";
                        break;
                }
            }
        }
Exemplo n.º 13
0
        private void BindGroups(User.UserList users)
        {
            //Load the groups into viewstate
            ArrayList groups = new ArrayList();
            new UserGrouper().Group(users, groups, 9);
            string vsrecord="";
            foreach (UserGrouper.UserGroup group in groups)
                vsrecord += group.LowerBound + " " + group.UpperBound + "\n";
            ViewState["Groups"] = vsrecord;

            dgUserSearch.VirtualItemCount = 9*groups.Count;
            //	dgUserSearch.CurrentPageIndex = 0;
        }
Exemplo n.º 14
0
        public void BindSearchData(User.UserList users)
        {
            int courseID = new Assignments(Globals.CurrentIdentity).GetInfo(GetAsstID()).CourseID;

            //Load the groups into viewstate
            if (users.Count > 0) {
                string[] bounds = GetGroups().Split(
                    "\n".ToCharArray())[dgUserSearch.CurrentPageIndex].Split(" ".ToCharArray());
                new UserGrouper().Regroup(bounds[1], bounds[0], users);
            }

            dgUserSearch.DataSource = users;
            dgUserSearch.DataBind();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Create a new user
        /// </summary>
        public bool Create(string username, string password, 
            string first, string last, string email,
            IProviderTransaction tran)
        {
            if (GetInfo(username, null) != null)
                throw new DataAccessException("User already exists");

            if (password.Length < Globals.MinPasswordLength)
                throw new
                    DataAccessException("Password must be at least " + Globals.MinPasswordLength +
                    " characters long!");

            User user = new User();
            user.UserName = username;
            user.FirstName = first;
            user.LastName = last;
            user.Email = email;
            user.VerifyKey = Globals.GeneratePassword(8);

            bool result = m_dp.CreateUser(user, password, tran);
            if (result)
                SendVerifyEmail(user);
            return result;
        }
Exemplo n.º 16
0
        private void dgAllUsers_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            User user = new User();

            user.UserName = (string)dgAllUsers.DataKeys[e.Item.ItemIndex];
            user.Email = ((TextBox)(e.Item.Cells[2].Controls[1])).Text;
            user.FirstName = ((TextBox)(e.Item.Cells[3].Controls[1])).Text;
            user.LastName = ((TextBox)(e.Item.Cells[4].Controls[1])).Text;

            (new Users(Globals.CurrentIdentity)).Update(user, null);
            dgAllUsers.EditItemIndex = -1;

            BindData();
        }
Exemplo n.º 17
0
 /// <summary>
 /// Returns extended user information
 /// If the user is unknown, error handling takes place
 /// </summary>
 public User GetInfo(string username, IProviderTransaction tran)
 {
     User user = new User();
     if (!m_dp.GetUserInfo(username, user, tran)) {
         //TODO: Do error handling stuff
         return null;
     }
     return user;
 }
Exemplo n.º 18
0
        private ArrayList Setup(User.UserList users)
        {
            ArrayList groups = new ArrayList();
            int i;

            for (i = 0; i < alphabet.Length; i++) {
                string bound = alphabet[i];
                UserGroup group = new UserGroup();
                group.UpperBound = alphabet[i];
                if (i == alphabet.Length - 1)
                    group.LowerBound = bound;
                else
                    group.LowerBound = alphabet[i+1];

                foreach (User user in users)
                    if (group.InGroup(user.LastName))
                        group.Users.Add(user);

                groups.Add(group);
            }

            return groups;
        }
Exemplo n.º 19
0
 /// <summary>
 /// Update user information
 /// </summary>
 public bool Update(User user, IProviderTransaction tran)
 {
     return m_dp.UpdateUser(user, tran);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Group users into binsize groups
 /// </summary>
 public bool Group(User.UserList users, ArrayList groups)
 {
     return Group(users, groups, BINSIZE);
 }
Exemplo n.º 21
0
        /// <summary>
        /// Create a set of users specified by XML data
        /// </summary>
        public void BatchCreate(Stream xmlStream, bool sync)
        {
            User user = new User();
            Users userDB = new Users(Globals.CurrentIdentity);
            DataSet xmldata = new DataSet();
            xmldata.ReadXml(xmlStream);
            DataRowCollection users = xmldata.Tables["User"].Rows;

            IProviderTransaction tran = m_dp.BeginTransaction();
            foreach (DataRow row in users) {

                user.UserName = (string) row["UserName"];
                user.FirstName = (string) row["FirstName"];
                user.LastName = (string) row["LastName"];
                user.Email = (string) row["Email"];

                //If the user is already in the system
                if (null != userDB.GetInfo(user.UserName, tran)) {
                    if (sync)
                        m_dp.UpdateUser(user, tran);
                    else {
                        m_dp.RollbackTransaction(tran);
                        throw new DataAccessException("User: "******" is already in the FrontDesk database. Use a merge to add additional users.");
                    }
                }
                else {
                    string passwd = Globals.GeneratePassword(Globals.MinPasswordLength);
                    m_dp.CreateUser(user, passwd, tran);
                    new EmailWizard(m_ident).SendByUsername(user.UserName, "FrontDesk: User Account Created",
                        String.Format(Globals.GetMessage("CreateUser"), user.UserName, passwd,
                        user.Email));
                }
            }
            m_dp.CommitTransaction(tran);
        }
Exemplo n.º 22
0
        private TreeNode AddSubjUserNode(TreeNodeCollection par, User user, int asstID, Components.Submission sub, 
            bool expand)
        {
            string imageurl;
            string desc;

            switch (sub.Status) {
            case Components.Submission.GRADED:
                imageurl = "attributes/subgrade.gif"; break;
            case Components.Submission.DEFUNCT:
                imageurl = "attributes/skull.gif"; break;
            default:
                imageurl = "attributes/sub.gif"; break;
            };

            CFile sdir = new FileSystem(Globals.CurrentIdentity).GetFile(sub.LocationID);
            if (sdir == null)
                desc = "*Error*";
            else
                desc = sdir.Alias;

            if (expand) desc = "(" + user.UserName + ") " + desc; //Make top level more clear
            return AddNode(par, desc, imageurl, imageurl,
                "SubjUser " + user.UserName + " " + asstID.ToString() + " " + sub.ID, expand);
        }