Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ds"> </param>
        private void populateFields(UserM user)
        {
            if (user.EmailAddress != null && user.EmailAddress != String.Empty)
            {
                txtEMailAddress.Text = user.EmailAddress;
            }

            if (user.FirstName != null && user.FirstName != String.Empty)
            {
                txtFirstName.Text = user.FirstName;
            }

            if (user.LastName != null && user.LastName != String.Empty)
            {
                txtLastName.Text = user.LastName;
            }

            if (user.MiddleName != null && user.MiddleName != String.Empty)
            {
                txtMiddleName.Text = user.MiddleName;
            }

            if (user.UniversityID != null && user.UniversityID != String.Empty)
            {
                txtUniversityIdentifier.Text = user.UniversityID;
            }

            if (user.UserName != null && user.UserName != "")
            {
                txtUserName.Text = user.UserName;
            }

            //Set current role
            RoleM role = user.GetRoleInCourse(courseId);

            for (int i = 0; i < UserRolesList.Items.Count; i++)
            {
                if (UserRolesList.Items[i].Value == role.ID.ToString())
                {
                    UserRolesList.SelectedIndex = i;
                    break;
                }
            }

            if (role.ID > 0)
            {
                RoleM currentUsersRole = RoleM.GetUsersRoleInCourse(SharedSupport.GetUserIdentity(), courseId);
                //Note: Can't change the role of someone = in level to you.
                if ((currentUsersRole.ID > (int)PermissionsID.Admin) && (currentUsersRole.ID >= role.ID))
                {
                    UserRolesList.Enabled = false;
                }
            }
        }
Esempio n. 2
0
 public ActionResult Role(RoleM roleM)
 {
     if (ModelState != null)
     {
         int id = db.RoleEmp(roleM);
         if (id > 0)
         {
             ModelState.Clear();
             return(RedirectToAction("Index", "Employee_Master"));
         }
     }
     return(View());
 }
Esempio n. 3
0
        private async Task Authenticate(User user)
        {
            var claims = new List <Claim>
            {
                new Claim(ClaimsIdentity.DefaultNameClaimType, user.Email),
                new Claim(ClaimsIdentity.DefaultRoleClaimType, RoleM.GetRole((int)user.RoleId)?.Name)
            };

            ClaimsIdentity id = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType,
                                                   ClaimsIdentity.DefaultRoleClaimType);

            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id));
        }
Esempio n. 4
0
 private void SetupRoleButtons()
 {
     RoleM[] roles = RoleM.GetAllRoles();
     if (roles.Length == 0)
     {
         UserRolesList.Visible = false;
     }
     else
     {
         foreach (RoleM role in roles)
         {
             ListItem item = new ListItem();
             item.Text  = Server.HtmlEncode(role.Name);
             item.Value = Server.HtmlEncode(role.ID.ToString());
             if (item.Value == ((int)PermissionsID.Student).ToString())
             {
                 item.Selected = true;
             }
             UserRolesList.Items.Add(item);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        public void btnUpdate_Click(object sender, System.EventArgs e)
        {
            try
            {
                //reset error handling label
                Nav1.Feedback.Text = String.Empty;
                checkErrorCases();

                UserM user = null;
                //Save Updated or New User - check for UserID on query string
                if (userId != 0)
                {
                    if (!SharedSupport.SecurityIsAllowed(courseId, SecurityAction.USER_EDIT))
                    {
                        throw new Exception(SharedSupport.GetLocalizedString("Global_Unauthorized"));
                    }

                    //Update
                    user = UserM.Load(userId);

                    if (user.IsValid)
                    {
                        //Save updated user
                        user.EmailAddress      = txtEMailAddress.Text.ToString();
                        user.FirstName         = txtFirstName.Text.ToString();
                        user.LastName          = txtLastName.Text.ToString();
                        user.LastUpdatedDate   = DateTime.Now;
                        user.LastUpdatedUserID = SharedSupport.GetUserIdentity();
                        user.MiddleName        = txtMiddleName.Text.ToString();
                        user.UniversityID      = txtUniversityIdentifier.Text.ToString();
                        user.UserName          = txtUserName.Text.ToString();

                        user.Update();

                        if (user.IsInCourse(courseId))
                        {
                            if (SharedSupport.SecurityIsAllowed(courseId, SecurityAction.SECURITY_EDIT))
                            {
                                int   roleid           = Convert.ToInt32(UserRolesList.SelectedItem.Value);
                                RoleM currentUsersRole = RoleM.GetUsersRoleInCourse(SharedSupport.GetUserIdentity(), courseId);

                                // The lower role => greater permissions
                                if ((currentUsersRole.ID == (int)PermissionsID.Admin) || (currentUsersRole.ID < roleid))
                                {
                                    user.SetRoleInCourse(courseId, roleid);
                                }
                                else
                                {
                                    throw new Exception(SharedSupport.GetLocalizedString("AddEditUser_ErrorRolePermissionDenied"));
                                }
                            }
                        }
                        else
                        {
                            // Add user to Course
                            PermissionsID permission = PermissionsID.Student;
                            if (SharedSupport.SecurityIsAllowed(courseId, SecurityAction.SECURITY_EDIT))
                            {
                                int   roleid           = Convert.ToInt32(UserRolesList.SelectedItem.Value);
                                RoleM currentUsersRole = RoleM.GetUsersRoleInCourse(SharedSupport.GetUserIdentity(), courseId);

                                // The lower role => greater permissions
                                // Note: Cannot change the permission of someone at your level.
                                if ((currentUsersRole.ID == (int)PermissionsID.Admin) || (currentUsersRole.ID < roleid))
                                {
                                    permission = (PermissionsID)roleid;
                                    user.AddToCourse(courseId, permission);
                                }
                                else
                                {
                                    throw new Exception(SharedSupport.GetLocalizedString("AddEditUser_ErrorRolePermissionDenied"));
                                }
                            }
                        }
                        btnUpdate.Text     = SharedSupport.GetLocalizedString("AddEditUser_Update");
                        Nav1.Feedback.Text = SharedSupport.GetLocalizedString("AddEditUser_UserUpdated");                          //"User has been Updated.";
                    }
                    else
                    {
                        throw new Exception(NO_USER_FOR_USERID_ERROR);
                    }
                }
                else
                {
                    if (!SharedSupport.SecurityIsAllowed(courseId, SecurityAction.USER_ADD))
                    {
                        throw new Exception(SharedSupport.GetLocalizedString("Global_Unauthorized"));
                    }

                    //Insert
                    user = new UserM();

                    user.EmailAddress      = txtEMailAddress.Text.ToString();
                    user.FirstName         = txtFirstName.Text.ToString();
                    user.LastName          = txtLastName.Text.ToString();
                    user.LastUpdatedDate   = DateTime.Now;
                    user.LastUpdatedUserID = SharedSupport.GetUserIdentity();
                    user.MiddleName        = txtMiddleName.Text.ToString();
                    user.UniversityID      = txtUniversityIdentifier.Text.ToString();
                    user.UserName          = txtUserName.Text.ToString();
                    user.ChangedPassword   = false;

                    // Does the user already exist?
                    UserM userByName = UserM.LoadByUserName(user.UserName);
                    if (!userByName.IsValid)
                    {
                        userId = user.Create();

                        btnUpdate.Text     = SharedSupport.GetLocalizedString("AddEditUser_Update");
                        Nav1.Feedback.Text = SharedSupport.GetLocalizedString("AddEditUser_UserInserted");                          //"User has been inserted.";

                        PermissionsID permission = PermissionsID.Student;
                        if (SharedSupport.SecurityIsAllowed(courseId, SecurityAction.SECURITY_EDIT))
                        {
                            int   roleid           = Convert.ToInt32(UserRolesList.SelectedItem.Value);
                            RoleM currentUsersRole = RoleM.GetUsersRoleInCourse(SharedSupport.GetUserIdentity(), courseId);

                            // The lower role = greater permissions
                            // Note: Can't change permissions of someone equal in level to you.
                            if ((currentUsersRole.ID == (int)PermissionsID.Admin) || (currentUsersRole.ID < roleid))
                            {
                                permission = (PermissionsID)roleid;
                            }
                            else
                            {
                                throw new Exception(SharedSupport.GetLocalizedString("AddEditUser_ErrorRolePermissionDenied"));
                            }
                        }
                        user.AddToCourse(courseId, permission);
                    }
                    else
                    {
                        throw new Exception(SharedSupport.GetLocalizedString("User_UserNameMustBeUnique"));
                    }
                }

                Response.Redirect("Users.aspx?UserID=" + userId.ToString() + "&" + Request.QueryString.ToString(), false);
            }
            catch (Exception ex)
            {
                Nav1.Feedback.Text = ex.Message.ToString();
            }
        }
        private void btnSave_Click(object sender, System.EventArgs e)
        {
            try
            {
                AssignmentManager.Common.Functions func = new AssignmentManager.Common.Functions();

                if (this.txtConfirmPwd.Text == "")
                {
                    throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_ConfirmPassword_RequiredField"));
                }
                else if (this.txtNewPwd.Text == "")
                {
                    throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_NewPassword_RequiredField"));
                }
                else if ((this.txtNewPwd.Text.Trim().Length < 4) || (this.txtNewPwd.Text.Trim().Length > 50))
                {
                    throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_PwdLengthError"));
                }
                if (this.txtNewPwd.Text != this.txtConfirmPwd.Text)
                {
                    this.txtNewPwd.Text     = "";
                    this.txtConfirmPwd.Text = "";
                    throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_ConfirmationError"));
                }

                int UserID   = func.ValidateNumericQueryStringParameter(this.Request, "UserID");
                int courseId = func.ValidateNumericQueryStringParameter(this.Request, "CourseID");

                if (UserID != 0)
                {
                    int currentUserID = SharedSupport.GetUserIdentity();
                    if (currentUserID == 0)
                    {
                        throw new Exception(SharedSupport.GetLocalizedString("Global_Unauthorized"));
                    }

                    if (currentUserID == UserID)
                    {
                        // you are always allowed to change your own password.
                        setNewPassword(currentUserID);
                    }
                    else
                    {
                        if (!SharedSupport.SecurityIsAllowed(courseId, SecurityAction.USER_EDIT))
                        {
                            // Note that Redirect ends page execution.
                            Response.Redirect(@"../Error.aspx?ErrorDetail=" + "Global_Unauthorized");
                        }
                        try
                        {
                            RoleM currentUsersRole = RoleM.GetUsersRoleInCourse(currentUserID, courseId);
                            RoleM targetUsersRole  = RoleM.GetUsersRoleInCourse(UserID, courseId);

                            //Lower ID = more permissions
                            if (currentUsersRole.ID <= targetUsersRole.ID)
                            {
                                setNewPassword(UserID);
                            }
                            else
                            {
                                throw new Exception();
                            }
                        }
                        catch (Exception)
                        {
                            throw new Exception(SharedSupport.GetLocalizedString("Global_Unauthorized"));
                        }
                    }


                    Response.Redirect(@"AddEditUser.aspx?UserID=" + UserID + "&CourseID=" + courseId);
                }
            }
            catch (Exception ex)
            {
                Nav1.Feedback.Text = ex.Message;
            }
        }