示例#1
0
 public User(SecUser user, bool enableUserSecurityLoading)
 {
     try
     {
         this.UserId       = user.UserId;
         this.EmailAddress = user.EmailAddress;
         this.DisplayName  = user.DisplayName;
         this.OrgId        = user.OrgId;
         this.ManagerId    = user.ManagerId;
         this.CreatedAt    = user.CreatedAt;
         this.DeletedAt    = user.DeletedAt;
         if (this.ManagerId.HasValue && user.Manager != null)
         {
             this.ManagerName = user.Manager.DisplayName;
         }
         this.Organization     = new Organization(user.Org);
         this.OrganizationName = Organization.Label;
         this.UserRoles        = new List <UserRole>();
         if (enableUserSecurityLoading)
         {
             foreach (SecUserRole userRole in user.SecUserRole)
             {
                 if (userRole.DeletedAt == null && userRole.Role.DeletedAt == null)
                 {
                     this.UserRoles.Add(new UserRole(userRole));
                 }
             }
         }
     }
     catch (System.Exception)
     {
     }
 }
示例#2
0
        private void purgeRoles(SecUser user)
        {
            var roles = context.SecUserRole.Where(r => r.UserId == user.UserId);

            context.SecUserRole.RemoveRange(roles);
            context.SaveChanges();
        }
示例#3
0
        public static void SetTutorialMode(int userId, bool tutorialMode)
        {
            SecUser secUser = DbContextHelper.DbContext.SecUser.First(x => x.UserId == userId);

            secUser.TutorialMode = tutorialMode;
            DbContextHelper.DbContext.SaveChanges();
        }
示例#4
0
        private void checkPaginationStatus()
        {
            int  itemId = int.Parse(itemDropDownList.SelectedValue);
            Item item   = bp.ItemSelectPagination(itemId);

            if (item != null)
            {
                paginationStatusLabel.Text = PaginationStatus.GetStatusString(item.PaginationStatusID);

                if (item.PaginationStatusID != null)
                {
                    DateTime paginationStatusDate = (DateTime)item.PaginationStatusDate;
                    paginationDetailStatusLabel.Text = "Pagination status set by " + item.PaginationUserName + " on " +
                                                       paginationStatusDate.ToShortDateString() + " at " + paginationStatusDate.ToShortTimeString();
                    if (item.PaginationStatusID == (int)PaginationStatus.InProgress)
                    {
                        // Look up userid based on token string
                        SecUser secUser = getSecUser();
                        configurePaginationStatusButtons(item, (item.PaginationStatusUserID == secUser.UserID));
                        toggleButtons(item.PaginationStatusUserID == secUser.UserID);
                    }
                    else
                    {
                        configurePaginationStatusButtons(item, true);
                        toggleButtons(false);
                    }
                }
                else
                {
                    paginationDetailStatusLabel.Text = "Pagination status has not been manually updated";
                    configurePaginationStatusButtons(item, true);
                    toggleButtons(false);
                }
            }
        }
示例#5
0
 public User(SecUser user)
 {
     try
     {
         this.UserId           = user.UserId;
         this.EmailAddress     = user.EmailAddress;
         this.DisplayName      = user.DisplayName;
         this.OrgId            = user.OrgId;
         this.ManagerId        = user.ManagerId;
         this.Organization     = new Organization(user.Org);
         this.OrganizationName = Organization.Label;
         this.UserRoles        = new List <UserRole>();
         this.CreatedAt        = user.CreatedAt;
         this.DeletedAt        = user.DeletedAt;
         foreach (SecUserRole userRole in user.SecUserRole)
         {
             if (userRole.DeletedAt == null && userRole.Role.DeletedAt == null)
             {
                 this.UserRoles.Add(new UserRole(userRole));
             }
         }
     }
     catch (Exception)
     {
     }
 }
示例#6
0
        protected void clearPageTypeButton_Click(object sender, EventArgs e)
        {
            SecUser    secUser = getSecUser();
            List <int> pages   = getSelectedPageIds();

            if (pages.Count > 0)
            {
                int[] arrPages = new int[pages.Count];
                pages.CopyTo(arrPages);
                bp.Page_PageTypeDeleteAllForPage(arrPages, secUser.UserID);
                int itemId = int.Parse(itemDropDownList.SelectedValue);
                //fillPageList( itemId );

                // By manually filling the cells in the datagrid (instead of just
                // refreshing/refilling the dataset, we are able to preserve the
                // checked fields and the scroll position of the grid.
                foreach (GridViewRow gvr in detailGridView.Rows)
                {
                    CheckBox cb = (CheckBox)gvr.FindControl("pageCheckBox");
                    if (cb.Checked)
                    {
                        gvr.Cells[7].Text = "";
                    }
                }

                clearInputs();
            }
        }
示例#7
0
        public static SecUser GetById(int userId)
        {
            SecUser user = (from x in DbContextHelper.DbContext.SecUser
                            where x.UserId == userId
                            select x).FirstOrDefault();

            return(user);
        }
示例#8
0
 internal void update(SecUser oldUser, SecUser newUser)
 {
     newUser.CreatedAt            = oldUser.CreatedAt;
     context.Entry(oldUser).State = EntityState.Deleted;
     context.Entry(newUser).State = EntityState.Modified;
     newUser.UpdatedAt            = DateTime.Now;
     context.SecUser.Update(newUser);
 }
示例#9
0
        /// <summary>
        ///   Costruisce un "principal" partendo da un utente di Caravan.
        /// </summary>
        /// <param name="user">L'utente Caravan.</param>
        public IdnPrincipal(SecUser user)
        {
            // Preconditions
            Raise.ArgumentNullException.IfIsNull(user, nameof(user));

            User = user;
            Identity = new IdnIdentity(user.AppName, user.Login);
        }
示例#10
0
        public JsonResult Login(SecUser model, string ValidateCode)
        {
            MyJsonResult mjr = new MyJsonResult();

            try
            {
                var obj = Session["ValidateCode"];
                if (obj == null || obj.ToString() != ValidateCode)
                {
                    mjr.Success = false;
                    mjr.Message = "验证码不正确!";
                    mjr.Data    = 1;
                    if (obj == null)
                    {
                        mjr.Data = 11;
                    }
                    return(Json(mjr));
                }

                UserService userService = new UserService();

                var user = userService.GetUserByLoginName(model.LoginName);

                if (user == null)
                {
                    mjr.Success = false;
                    mjr.Message = "用户名不正确!";
                    mjr.Data    = 2;
                }
                else
                {
                    if (user.Password != model.Password)
                    {
                        mjr.Success = false;
                        mjr.Message = "密码不正确!";
                        mjr.Data    = 3;
                    }
                    else
                    {
                        SecurityContext.Current = new SecurityContext()
                        {
                            User = user,
                            PermissionManager = new PermissionManager(user.UserId)
                        };

                        //Session[SSessionIndex.IsAuthorizedForCKEditor] = true;
                        mjr.Success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                mjr.Success = false;
                mjr.Message = ex.Message;
            }

            return(Json(mjr));
        }
示例#11
0
        /// <summary>
        ///   Costruisce un "principal" partendo dal nome dell'applicazione e dalla login
        ///   dell'utente. Questo costruttore può essere usato quando non si ha a disposizione un
        ///   vero e proprio utente Caravan.
        /// </summary>
        /// <param name="appName">Il nome dell'applicazione Caravan, può essere fittizio.</param>
        /// <param name="userLogin">La login dell'utente Caravan, può essere fittizia.</param>
        public IdnPrincipal(string appName, string userLogin)
        {
            // Preconditions
            Raise.ArgumentException.IfIsNullOrWhiteSpace(appName, nameof(appName));
            Raise.ArgumentException.IfIsNullOrWhiteSpace(userLogin, nameof(userLogin));

            User = new SecUser { AppName = appName, Login = userLogin };
            Identity = new IdnIdentity(appName, userLogin);
        }
示例#12
0
        public JsonResult Save(SecUser model)
        {
            MyJsonResult mjr = new MyJsonResult();

            using (var dba = DbAccessor.Create())
            {
                try
                {
                    dba.BeginTran();

                    model.ModifiedById = SecurityContext.Current.User.UserId;
                    model.ModifiedDate = DateTime.Now;

                    if (model.UserId == null)
                    {
                        #region 校验数据
                        dynamic count = _dba.ExecuteScalar <dynamic>("SecuritySettings.User.CountByLoginName",
                                                                     new { LoginName = model.LoginName, Status = (int)StatusType.Enabled });

                        if (count > 0)
                        {
                            mjr.Success = false;
                            mjr.Message = "登录名已存在!";
                            goto End;
                        }
                        #endregion

                        model.UserId      = Guid.NewGuid().ToString();
                        model.Status      = (int)StatusType.Enabled;
                        model.CreatedById = SecurityContext.Current.User.UserId;
                        model.CreatedDate = DateTime.Now;
                        dba.Insert <SecUser>(model);
                    }
                    else
                    {
                        dba.UpdateFields(model, "LoginName", "Password", "Name", "Sex", "Birthday",
                                         "MobilePhone", "OrganizationId",
                                         "ModifiedById", "ModifiedDate");
                    }

                    dba.CommitTran();
                    mjr.Success = true;
                    mjr.Message = "保存成功!";
                }
                catch (Exception ex)
                {
                    dba.RollbackTran();
                    mjr.Success = false;
                    mjr.Message = ex.Message;
                }
            }

End:

            return(Json(mjr));
        }
示例#13
0
 public int CreateUser(SecUser secUser)
 {
     context.SecUser.Add(secUser);
     foreach (var sur in secUser.SecUserRole)
     {
         context.SecUserRole.Add(sur);
     }
     context.SaveChanges();
     return(secUser.UserId);
 }
示例#14
0
        public void SaveSecUser()
        {
            SecUser sec = new SecUser();

            sec.ID        = Guid.NewGuid();
            sec.SecUserID = Guid.NewGuid();
            sec.Email     = "*****@*****.**";

            //_secUserRepository.get
        }
示例#15
0
        internal void Update(SecUser secUser)
        {
            SecUser oldUser = RetrieveByUserId(secUser.UserId);

            purgeRoles(oldUser);
            foreach (var sur in secUser.SecUserRole)
            {
                context.SecUserRole.Add(sur);
            }
            update(oldUser, secUser);
            context.SaveChanges();
        }
示例#16
0
        internal void Return(IListable entity)
        {
            
            SecUser originator = this.referenceRepository.context.SecUser.Where(u => u.UserId == entity.CreatedByUserId).SingleOrDefault();

            entity.AssignedToUserId = null;
            entity.AssignedToOrgId = originator.OrgId.Value;
            entity.AssignedByUserId = null;
            entity.StatusId = referenceRepository.GetStatus(StatusType.RETURNED).StatusId;            
            entity.AssignedAt = null;
            entity.ResolvedAt = null;
        }
示例#17
0
        public ActionResult Edit(string id)
        {
            SecUser user = new SecUser();

            if (id != null)
            {
                user = _userService.Get(id);
                string strSql  = @"SELECT Name FROM Sec_Organization WHERE OrganizationId=#OrganizationId#";
                string orgName = _dba.ExecuteScalar <string>(strSql, new { OrganizationId = user.OrganizationId });

                ViewBag.OrgName = orgName;
            }
            return(View(user));
        }
示例#18
0
 public StatusEnum.ChangePasswordStatus ChangePassword(LoginCredential credential, SecUser secUser = null)
 {
     StatusEnum.ChangePasswordStatus status = StatusEnum.ChangePasswordStatus.InvalidOldPassword;
     try
     {
         _user = secUser ?? GetUserByEmail(credential.Email.ToLower());
         if (_user != null)
         {
             _isPIN    = credential.IsPIN;
             _isOldPIN = credential.IsOldPIN;
             status    = ValidatePasswordForChange(credential);
         }
         return(status);
     }
     catch (Exception) { throw; }
 }
示例#19
0
        protected void assignPageTypeButton_Click(object sender, EventArgs e)
        {
            bool       flag  = false;
            List <int> pages = getSelectedPageIds();

            if (pages.Count == 0)
            {
                flag = true;
                errorControl.AddErrorText("You must select at least one page to update.");
            }
            else
            {
                SecUser secUser  = getSecUser();
                int[]   arrPages = new int[pages.Count];
                pages.CopyTo(arrPages);
                bp.Page_PageTypeSave(arrPages, int.Parse(pageTypeCombo.SelectedValue), secUser.UserID);
                int itemId = int.Parse(itemDropDownList.SelectedValue);
                //fillPageList( itemId );

                // By manually filling the cells in the datagrid (instead of just
                // refreshing/refilling the dataset, we are able to preserve the
                // checked fields and the scroll position of the grid.
                foreach (GridViewRow gvr in detailGridView.Rows)
                {
                    CheckBox cb = (CheckBox)gvr.FindControl("pageCheckBox");
                    if (cb.Checked)
                    {
                        String existingValue = gvr.Cells[7].Text;
                        if (!existingValue.Contains(pageTypeCombo.SelectedItem.Text))
                        {
                            if (existingValue == String.Empty)
                            {
                                gvr.Cells[7].Text = pageTypeCombo.SelectedItem.Text;
                            }
                            else
                            {
                                gvr.Cells[7].Text = pageTypeCombo.SelectedItem.Text + ", " + existingValue;
                            }
                        }
                    }
                }

                clearInputs();
            }

            errorControl.Visible = flag;
        }
示例#20
0
        public void Users_Insert2Users_ReturnsListOfUsers()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };
            var user2 = new SecUser { FirstName = "pluto", Login = "******" };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);
            CaravanDataSource.Security.AddUser(_myApp.Name, user2);

            IEnumerable<SecUser> retValue = CaravanDataSource.Security.GetUsers(_myApp.Name);
            Assert.That(retValue.Count(), Is.EqualTo(2));

            var q = (from user in CaravanDataSource.Security.GetUsers(_myApp2.Name)
                     where (user.Login == user1.Login || user.Login == user2.Login)
                     select user).ToList();

            Assert.That(q.Count(), Is.EqualTo(0));
        }
示例#21
0
        protected void statusButton_Click(object sender, EventArgs e)
        {
            // Validate the state of the button and the selected item before performing any updates
            int     itemId           = int.Parse(itemDropDownList.SelectedValue);
            Item    item             = bp.ItemSelectPagination(itemId);
            string  paginationStatus = statusButton.Text;
            SecUser secUser          = getSecUser();

            if (item.PaginationStatusID.HasValue == false || item.PaginationStatusID.Value == PaginationStatus.Pending)
            {
                // if the status is pending, validate that the action will set it to "Complete"
                if (paginationStatus.Equals(_completeStatus) == false)
                {
                    displayPaginationStatusInvalid();
                }
                else
                {
                    updatePaginationStatus(itemId, PaginationStatus.Complete, secUser.UserID);
                }
            }
            else if (item.PaginationStatusID.Value == PaginationStatus.InProgress)
            {
                // If the status is "In Progress", validate that the action will set it to "Complete"
                // also make sure that the logged in user has rights to unlock this item
                if (paginationStatus.Equals(_completeStatus) == false || item.PaginationStatusUserID != secUser.UserID)
                {
                    displayPaginationStatusInvalid();
                }
                else
                {
                    updatePaginationStatus(itemId, PaginationStatus.Complete, secUser.UserID);
                }
            }
            else if (item.PaginationStatusID.Value == PaginationStatus.Complete)
            {
                // If the status is "Complete", validate that the action will set it to "In Progress"
                if (paginationStatus.Equals(_lockEditStatus) == false)
                {
                    displayPaginationStatusInvalid();
                }
                else
                {
                    updatePaginationStatus(itemId, PaginationStatus.InProgress, secUser.UserID);
                }
            }
        }
示例#22
0
        public static SecUser Save(SecUser secUser)
        {
            if (secUser.UserId == 0)
            {
                secUser.CreatedBy        = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                secUser.CreatedOn        = DateTime.Now;
                secUser.CreatedMachineIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
                DbContextHelper.DbContext.Add(secUser);
            }

            //secUser.UpdatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
            secUser.UpdatedMachineIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
            secUser.UpdatedOn        = DateTime.Now;
            DbContextHelper.DbContext.SaveChanges();

            return(secUser);
        }
        /// <summary>
        ///   Valida parte delle proprietà dell'utente passato come parametro, utilizzando i metodi
        ///   definiti da questa interfaccia.
        /// </summary>
        /// <param name="user">L'utente da validare.</param>
        /// <returns>Il risultato della validazione.</returns>
        public virtual async Task<SecValidationResult> ValidateUserAsync(SecUser user)
        {
            var errors = new List<string>();

            var emailValidationResult = await ValidateEmailAsync(user.Email);
            if (!emailValidationResult.Succeeded)
            {
                errors.AddRange(emailValidationResult.Errors);
            }

            var phoneNumberValidationResult = await ValidatePhoneNumberAsync(user.PhoneNumber);
            if (!phoneNumberValidationResult.Succeeded)
            {
                errors.AddRange(phoneNumberValidationResult.Errors);
            }

            return errors.Count == 0 ? SecValidationResult.Success : SecValidationResult.Failure(errors);
        }
示例#24
0
 public void SaveNewPrimaryPassword(string newPassword, Guid?newSalt = null, string email = "")
 {
     _user = new SecUser();
     if (newSalt == null)
     {
         newSalt = Guid.NewGuid();
     }
     byte[] computedPassword = ComputePasswordHash(newPassword, newSalt.Value, PASSWORD_REHASH_TIMES);
     _user.ID              = Guid.NewGuid();
     _user.SecUserID       = Guid.NewGuid();
     _user.Email           = email;
     _user.PasswordHash256 = computedPassword;
     _user.PasswordSalt    = newSalt.Value;
     _user.CreatedDate     = DateTime.UtcNow;
     _user.IsActive        = true;
     _user.IsDeleted       = false;
     _user.ModifiedDate    = null;
     _secUserRepository.Create(_user);
     _secUserRepository.SaveChanges();
 }
示例#25
0
        public JsonResult Delete(string id)
        {
            MyJsonResult mjr = new MyJsonResult();


            try
            {
                var user = new SecUser();
                user.UserId = id;
                user.Status = (int)StatusType.Deleted;
                _dba.UpdateFields(user, "Status");

                mjr.Success = true;
            }
            catch (Exception ex)
            {
                mjr.Success = false;
                mjr.Message = ex.Message;
            }

            return(Json(mjr));
        }
示例#26
0
        public UserActivityReason ValidateUser(LoginCredential credential, SecUser secUser = null)
        {
            UserActivityReason activityReason = new UserActivityReason();

            activityReason.ReturnFlag = false;
            activityReason.Message    = UserAccountNotification.EmailNotFound;
            try
            {
                _user = secUser ?? GetUserByEmail(credential.Email.Trim());
                if (_user != null)
                {
                    activityReason = ValidatePassword(credential, activityReason);
                    if (activityReason.ReturnFlag == true)
                    {
                        activityReason.UserId = _user.SecUserID;
                        //activityReason.UserTypeId = _user.SecUserTypeID;
                    }
                }
                return(activityReason);
            }
            catch (Exception) { throw; }
        }
示例#27
0
        protected void assignYearAndVolumeButton_Click(object sender, EventArgs e)
        {
            bool       flag  = false;
            List <int> pages = getSelectedPageIds();

            if (pages.Count == 0)
            {
                flag = true;
                errorControl.AddErrorText("You must select at least one page to update.");
            }
            else
            {
                SecUser secUser  = getSecUser();
                int[]   arrPages = new int[pages.Count];
                pages.CopyTo(arrPages);
                bp.PageUpdateYear(arrPages, yearTextBox.Text.Trim(), secUser.UserID);
                bp.PageUpdateVolume(arrPages, volumeTextBox.Text.Trim(), secUser.UserID);
                int itemId = int.Parse(itemDropDownList.SelectedValue);
                //fillPageList( itemId );

                // By manually filling the cells in the datagrid (instead of just
                // refreshing/refilling the dataset, we are able to preserve the
                // checked fields and the scroll position of the grid.
                foreach (GridViewRow gvr in detailGridView.Rows)
                {
                    CheckBox cb = (CheckBox)gvr.FindControl("pageCheckBox");
                    if (cb.Checked)
                    {
                        gvr.Cells[3].Text = yearTextBox.Text.Trim();
                        gvr.Cells[4].Text = volumeTextBox.Text.Trim();
                    }
                }

                clearInputs();
            }

            errorControl.Visible = flag;
        }
示例#28
0
        internal SecUser SecUser()
        {
            SecUser secUser = new SecUser();

            secUser.CreatedAt    = this.CreatedAt;
            secUser.DeletedAt    = this.DeletedAt;
            secUser.DisplayName  = this.DisplayName;
            secUser.EmailAddress = this.EmailAddress;
            secUser.ManagerId    = this.ManagerId;
            secUser.OrgId        = this.OrgId;
            secUser.UpdatedAt    = this.UpdatedAt;
            secUser.UserId       = this.UserId;

            foreach (var userrole in UserRoles)
            {
                SecUserRole secUserRole = new SecUserRole();
                secUserRole.RoleId    = userrole.RoleId;
                secUserRole.UserId    = userrole.UserId;
                secUserRole.CreatedAt = DateTime.Now;
                secUser.SecUserRole.Add(secUserRole);
            }
            return(secUser);
        }
示例#29
0
 public void Send(IListable entity,string notificationEventCode, User submitter)
 {
     EmployeeService employeeService = new EmployeeService();
     Employee employee = employeeService.RetrieveById(entity.EmplId);
     notificationEvent = notificationRepository.RetrieveNotificationEventByCode(notificationEventCode);
     originator = userRepository.RetrieveByUserId(entity.CreatedByUserId.Value);
     bool willSendtoSubmitter = ((originator.UserId == submitter.UserId) && (notificationEvent.NotificationEventType.NotificationEventTypeCode == NotificationEventType.INDIV));
     if(!willSendtoSubmitter)
     {
         notificationEventType = notificationEvent.NotificationEventType;
         QmsWorkitemcomment comment = correctiveActionRepository.RetrieveLatestComment(entity.Id);
         switch(notificationEventType.NotificationEventTypeCode)
         {
             case NotificationEventType.INDIV:
                 sendIndividualMessage(entity,notificationEvent, submitter,comment);
                 break;
             case NotificationEventType.ORG:
                 sendOrganizationalMessage(entity,notificationEvent,comment);
                 break;
             default:
                 break;
         }
     }
 }        
示例#30
0
        public void UpdateUser_EmptyUserLogin_ThrowsArgumentNullException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" };

            user1.Login = "";

            CaravanDataSource.Security.UpdateUser(_myApp.Name, user1.Login, new SecUserUpdates
            {
                Login = user1.Login.ToOption()
            });
        }
示例#31
0
 public void AddUser_NullAppName_ThrowsArgumentException()
 {
     var user1 = new SecUser { FirstName = "pippo", Login = "******" };
     CaravanDataSource.Security.AddUser(null, user1);
 }
示例#32
0
        public void AddEntry_InsertTwiceTheSameUserDifferentObject_EntriesAdded()//same context and App; different object
        {
            var c1 = new SecContext { Name = "c1", Description = "context1" };
            var group1 = new SecGroup { Name = "my_group" };
            var user1 = new SecUser { FirstName = "user1", Login = "******" };
            var user2 = new SecUser { FirstName = "user2", Login = "******" };

            var obj1 = new SecObject
            {
                Name = "obj1",
                Description = "oggetto1",
                Type = "button"
            };

            var obj2 = new SecObject
            {
                Name = "obj2",
                Description = "oggetto2",
                Type = "button"
            };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);
            CaravanDataSource.Security.AddUser(_myApp.Name, user2);
            CaravanDataSource.Security.AddGroup(_myApp.Name, group1);
            CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null);
            CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj2, user1.Login, null);

            var l = CaravanDataSource.Security.GetEntriesForUser(_myApp.Name, c1.Name, user1.Login);

            Assert.That(l.Count(), Is.EqualTo(2));
        }
示例#33
0
 public int UpdateUser(SecUser secUser)
 {
     context.SecUser.Update(secUser);
     return(context.SaveChanges());
 }
示例#34
0
        public void AddUserToGroup_ValidArgs_UserAddedInCorrectGroup_Async(int userCount)
        {
            var group1 = new SecGroup { Name = "mygroup" };
            var group2 = new SecGroup { Name = "mygroup2" };
            CaravanDataSource.Security.AddGroup(_myApp.Name, group1);
            CaravanDataSource.Security.AddGroup(_myApp.Name, group2);

            Parallel.ForEach(Enumerable.Range(1, userCount), i =>
            {
                var user1 = new SecUser { FirstName = "pippo" + i, Login = "******" + i };

                CaravanDataSource.Security.AddUser(_myApp.Name, user1);

                CaravanDataSource.Security.AddUserToGroup(_myApp.Name, user1.Login, group1.Name);
            });
            group1 = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group1.Name);
            group2 = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group2.Name);
            Assert.AreEqual(userCount, group1.Users.Length);
            Assert.AreEqual(0, group2.Users.Length);

            for (var i = 1; i <= userCount; ++i)
            {
                var q =
                   (from u in CaravanDataSource.Security.GetUsers(_myApp.Name) where u.Login == ("blabla" + i) select u.Groups).ToList();
                Assert.That(q.Count, Is.EqualTo(1));
                Assert.True(q.First().Contains(group1));
                Assert.False(q.First().Contains(group2));
            }
        }
示例#35
0
        public void User_ValidArgs_ReturnsCorrectUser()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);

            var u = CaravanDataSource.Security.GetUserByLogin(_myApp.Name, user1.Login);
            Assert.That(u, Is.Not.Null);
            Assert.That(u.FirstName, Is.EqualTo("pippo"));
            Assert.That(u.Login, Is.EqualTo("blabla"));
        }
示例#36
0
        public void UpdateUser_ValidArgs_UserUpdated_Async(int userCount)
        {
            Parallel.ForEach(Enumerable.Range(1, userCount), i =>
            {
                var user = new SecUser { FirstName = "pippo" + i, Login = "******" + i, Email = "*****@*****.**" + i };
                CaravanDataSource.Security.AddUser(_myApp.Name, user);

                user.Login = "******" + i;

                CaravanDataSource.Security.UpdateUser(_myApp.Name, "blabla" + i, new SecUserUpdates
                {
                    Login = user.Login.ToOption()
                });
            });

            for (var i = 1; i <= userCount; ++i)
            {
                //verifico che sia stato aggiornato user
                var q = (from u in CaravanDataSource.Security.GetUsers(_myApp.Name)
                         where u.Login == ("updatedLogin" + i).ToLower()
                         select u).ToList();

                Assert.That(q.Count(), Is.EqualTo(1));
                Assert.That(q.First().Login, Is.EqualTo(("updatedLogin" + i).ToLower()));

                //verifico che non sia più presente l'utente con login "blabla" (vecchia login)
                var q2 = (from u in CaravanDataSource.Security.GetUsers(_myApp.Name)
                          where u.Login == "blabla" + i
                          select u).ToList();

                Assert.That(q2.Count, Is.EqualTo(0));
            }
        }
示例#37
0
        public void UpdateUser_LogIncremented_ReturnOK()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);

            WaitForLogger();
            var l = CaravanDataSource.Logger.GetEntries(_myApp.Name);

            user1.Login = "******";

            CaravanDataSource.Security.UpdateUser(_myApp.Name, "blabla1", new SecUserUpdates
            {
                Login = user1.Login.ToOption()
            });
            WaitForLogger();
            var l1 = CaravanDataSource.Logger.GetEntries(_myApp.Name);

            Assert.That(l1.Count(), Is.EqualTo(l.Count() + 1));
        }
示例#38
0
        public void RemoveUser_UserNotFound_ThrowsUserNotFoundException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };

            CaravanDataSource.Security.RemoveUser(_myApp.Name, user1.Login);
        }
示例#39
0
        public void UpdateUser_ValidArgs_UserUpdated()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);

            user1.Login = "******";

            CaravanDataSource.Security.UpdateUser(_myApp.Name, "blabla", new SecUserUpdates
            {
                Login = user1.Login.ToOption()
            });

            var q = (from u in CaravanDataSource.Security.GetUsers(_myApp.Name)
                     where u.Login == user1.Login.ToLower()
                     select u).ToList();

            Assert.That(q.Count(), Is.EqualTo(1));
            Assert.That(q.First().Login, Is.EqualTo("updatedLogin".ToLower()));

            var q2 = (from u in CaravanDataSource.Security.GetUsers(_myApp.Name)
                      where u.Login == "blabla"
                      select u).ToList();
            Assert.That(q2.Count, Is.EqualTo(0));
        }
示例#40
0
        public void RemoveEntry_EmptyGroupName_Throws()
        {
            var c1 = new SecContext { Name = "c1", Description = "context1" };
            var group1 = new SecGroup { Name = "my_group" };
            var user1 = new SecUser { FirstName = "user1", Login = "******" };

            var obj1 = new SecObject
            {
                Name = "obj1",
                Description = "oggetto1",
                Type = "button"
            };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);
            CaravanDataSource.Security.AddGroup(_myApp.Name, group1);
            CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null);

            CaravanDataSource.Security.RemoveEntry(_myApp.Name, c1.Name, obj1.Name, user1.Login, "");
        }
示例#41
0
 public void AddUser_UserLoginAlreadyPresent_ThrowsException_Async()
 {
     var failCount = 0;
     Parallel.ForEach(Enumerable.Range(1, 2), i =>
     {
         var user1 = new SecUser { FirstName = "pippo", Login = "******" };
         try
         {
             CaravanDataSource.Security.AddUser(_myApp.Name, user1);
         }
         catch (SecUserExistingException)
         {
             failCount++;
         }
     });
     Assert.AreEqual(1, failCount, "UserLoginAlreadyPresent");
 }
示例#42
0
        //public static SecUser SelectUser()
        //{
        //    var users = from x in DbContextHelper.DbContext.SecUsers

        //                select x;

        //    return users.Any() ? users.First() : new SecUser();
        //}
        public static void Delete(SecUser user)
        {
            DbContextHelper.DbContext.DeleteObject(user);
        }
示例#43
0
        public void UpdateUser_NullNewUserArg_ThrowsArgumentNullException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" };

            user1.Login = "******";

            CaravanDataSource.Security.UpdateUser(_myApp.Name, user1.Login, null);
        }
示例#44
0
        public void AddUser_UserLoginAlreadyPresent_ThrowsException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };
            var user2 = new SecUser { FirstName = "pluto", Login = "******" };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);
            CaravanDataSource.Security.AddUser(_myApp.Name, user2);
        }
示例#45
0
        public void AddUserToGroup_ValidArgs_UserAddedInCorrectGroup()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" };
            var group1 = new SecGroup { Name = "mygroup" };
            var group2 = new SecGroup { Name = "mygroup2" };
            CaravanDataSource.Security.AddUser(_myApp.Name, user1);
            CaravanDataSource.Security.AddGroup(_myApp.Name, group1);
            CaravanDataSource.Security.AddGroup(_myApp.Name, group2);
            CaravanDataSource.Security.AddUserToGroup(_myApp.Name, user1.Login, group1.Name);

            user1 = CaravanDataSource.Security.GetUserByLogin(_myApp.Name, user1.Login);
            group1 = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group1.Name);
            group2 = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group2.Name);

            Assert.True(user1.Groups.Any(g => g.Equals(group1)));
            Assert.False(user1.Groups.Any(g => g.Equals(group2)));
            Assert.AreEqual(1, user1.Groups.Length);

            Assert.True(group1.Users.Any(g => g.Equals(user1)));
            Assert.False(group2.Users.Any(g => g.Equals(user1)));
            Assert.AreEqual(1, group1.Users.Length);
            Assert.AreEqual(0, group2.Users.Length);
        }
示例#46
0
        public void UpdateUser_UserNotExisting_ThrowsUserNotFoundException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" };

            user1.Login = "******";

            CaravanDataSource.Security.UpdateUser(_myApp.Name, user1.Login, new SecUserUpdates
            {
                Login = user1.Login.ToOption()
            });
        }
示例#47
0
 public void AddUserToGroup_EmptyGroupName_ThrowsArgumentException()
 {
     var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" };
     var group1 = new SecGroup { Name = "mygroup" };
     CaravanDataSource.Security.AddUser(_myApp.Name, user1);
     CaravanDataSource.Security.AddGroup(_myApp.Name, group1);
     CaravanDataSource.Security.AddUserToGroup(_myApp.Name, user1.Login, "");
 }
示例#48
0
 public void UpdateUser_UserNotExisting_ThrowsUserNotFoundException_Async(int userCount)
 {
     var failCount = 0;
     Parallel.ForEach(Enumerable.Range(1, userCount), i =>
     {
         var user1 = new SecUser { FirstName = "pippo" + i, Login = "******" + i };
         try
         {
             CaravanDataSource.Security.AddUser(_myApp.Name, user1);
             CaravanDataSource.Security.RemoveUser(_myApp.Name, user1.Login);
             CaravanDataSource.Security.UpdateUser(_myApp.Name, user1.Login, new SecUserUpdates
             {
                 Login = user1.Login.ToOption(),
                 FirstName = user1.FirstName.ToOption(),
             });
         }
         catch (SecUserNotFoundException)
         {
             failCount++;
         }
     });
     Assert.AreEqual(userCount, failCount, "UserNotFound");
 }
示例#49
0
        public void RemoveEntry_ValidArgs_EntryRemoved()
        {
            var c1 = new SecContext { Name = "c1", Description = "context1" };
            var group1 = new SecGroup { Name = "my_group" };
            var user1 = new SecUser { FirstName = "user1", Login = "******" };
            var user2 = new SecUser { FirstName = "user2", Login = "******" };

            var obj1 = new SecObject
            {
                Name = "obj1",
                Description = "oggetto1",
                Type = "button"
            };

            var obj2 = new SecObject
            {
                Name = "obj2",
                Description = "oggetto2",
                Type = "button"
            };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);
            CaravanDataSource.Security.AddUser(_myApp.Name, user2);
            CaravanDataSource.Security.AddGroup(_myApp.Name, group1);
            CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null);
            CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj2, user1.Login, null);

            CaravanDataSource.Security.RemoveEntry(_myApp.Name, c1.Name, obj1.Name, user1.Login, null);
            CaravanDataSource.Security.RemoveEntry(_myApp.Name, c1.Name, obj2.Name, user1.Login, null);

            var l = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj1.Name);
            Assert.That(l.Count(), Is.EqualTo(0));

            var l1 = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj2.Name);
            Assert.That(l1.Count(), Is.EqualTo(0));
        }
示例#50
0
        public void UpdateUser_UserUpdatedAlreadyExisting_ThrowsUserExistingException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" };
            var user2 = new SecUser { FirstName = "pluto", Login = "******", Email = "*****@*****.**" };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);
            CaravanDataSource.Security.AddUser(_myApp.Name, user2);

            user1.Login = "******";

            CaravanDataSource.Security.UpdateUser(_myApp.Name, "blabla", new SecUserUpdates
            {
                Login = user1.Login.ToOption()
            });
        }
示例#51
0
        public User RetrieveByUserId(int userId)
        {
            SecUser secUser = repository.RetrieveByUserId(userId);

            return(new User(secUser, true, true));
        }
示例#52
0
        public void UpdateUser_UserUpdatedAlreadyExisting_ThrowsUserExistingException_Async()
        {
            var failCount = 0;
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };
            var user2 = new SecUser { FirstName = "pluto", Login = "******", Email = "*****@*****.**" };
            CaravanDataSource.Security.AddUser(_myApp.Name, user1);
            CaravanDataSource.Security.AddUser(_myApp.Name, user2);

            Parallel.ForEach(Enumerable.Range(1, 1), i =>
            {
                try
                {
                    user1.Login = "******";
                    CaravanDataSource.Security.UpdateUser(_myApp.Name, "blabla1", new SecUserUpdates
                    {
                        Login = user1.Login.ToOption()
                    });
                }
                catch (SecUserExistingException)
                {
                    failCount++;
                }
            });
            Assert.AreEqual(1, failCount, "UserLoginAlreadyPresent");
        }
示例#53
0
 public int CreateUser(SecUser secUser)
 {
     context.SecUser.Add(secUser);
     context.SaveChanges();
     return(secUser.UserId);
 }
示例#54
0
        public void UpdateUser_NullAppName_ThrowsArgumentNullException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" };

            user1.Login = "******";

            CaravanDataSource.Security.UpdateUser(null, user1.Login, new SecUserUpdates
            {
                Login = user1.Login.ToOption()
            });
        }
示例#55
0
        public void RemoveUser_EmptyAppName_ThrowsArgumentException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };

            CaravanDataSource.Security.RemoveUser("", user1.Login);
        }
示例#56
0
        public void RemoveUser_ValidArgs_RemoveUser()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);

            CaravanDataSource.Security.RemoveUser(_myApp.Name, user1.Login);

            var q = (from u in CaravanDataSource.Security.GetUsers(_myApp.Name) where u.Login == user1.Login select u).ToList();

            Assert.That(q.Count(), Is.EqualTo(0));
        }
示例#57
0
        public void RemoveUser_ValidArgs_RemoveUser_Async(int userCount)
        {
            Parallel.ForEach(Enumerable.Range(1, userCount), i =>
               {
                   var user = new SecUser { FirstName = "pippo" + i, Login = "******" + i };
                   CaravanDataSource.Security.AddUser(_myApp.Name, user);
                   CaravanDataSource.Security.RemoveUser(_myApp.Name, user.Login);
               });

            for (var i = 1; i <= userCount; ++i)
            {
                //verifico che siano stati eliminati tutti gli user
                var q = (from u in CaravanDataSource.Security.GetUsers(_myApp.Name) where u.Login == "blabla" + i select u).ToList();

                Assert.IsEmpty(q);
            }
        }
示例#58
0
        public void RemoveUser_EmptyUserLogin_ThrowsArgumentException()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "" };

            CaravanDataSource.Security.RemoveUser(_myApp.Name, user1.Login);
        }
示例#59
0
        private void AssignOrReplaceIndicatedPages(bool replace)
        {
            bool       flag  = false;
            List <int> pages = getSelectedPageIds();

            if (pages.Count == 0)
            {
                flag = true;
                errorControl.AddErrorText("You must select at least one page to update.");
            }
            else
            {
                IndicatedPageStyle style = (IndicatedPageStyle)int.Parse(styleDropDownList.SelectedValue);
                int    i     = 0;
                string start = startValueTextBox.Text.Trim();

                if (numStyleRadio.Checked)
                {
                    if (style == IndicatedPageStyle.Integer)
                    {
                        if (int.TryParse(incrementTextBox.Text, out i))
                        {
                            int s;
                            if (int.TryParse(startValueTextBox.Text, out s) == false)
                            {
                                flag = true;
                                errorControl.AddErrorText("The start value must be an integer.");
                            }
                        }
                        else
                        {
                            flag = true;
                            errorControl.AddErrorText("The increment value must be an integer.");
                        }
                    }
                    else if (style != IndicatedPageStyle.FreeForm)
                    {
                        if (int.TryParse(incrementTextBox.Text, out i))
                        {
                            try
                            {
                                RomanNumerals.FromRomanNumeral(startValueTextBox.Text.Trim());
                            }
                            catch
                            {
                                flag = true;
                                errorControl.AddErrorText("The start value must be a Roman numeral.");
                            }
                        }
                    }
                    else
                    {
                        flag = true;
                        errorControl.AddErrorText("The increment value must be an integer.");
                    }
                }
                else
                {
                    start = freeTextBox.Text.Trim();
                    style = IndicatedPageStyle.FreeForm;
                }

                if (!flag)
                {
                    SecUser secUser  = getSecUser();
                    int[]   arrPages = new int[pages.Count];
                    pages.CopyTo(arrPages);
                    if (replace)
                    {
                        bp.IndicatedPageDeleteAllForPage(arrPages, secUser.UserID);
                    }
                    bp.IndicatedPageSave(arrPages, prefixTextBox.Text.Trim(), style, start, i, impliedCheckBox.Checked,
                                         secUser.UserID);
                    int itemId = int.Parse(itemDropDownList.SelectedValue);
                    //fillPageList(itemId);

                    // By manually filling the cells in the datagrid (instead of just
                    // refreshing/refilling the dataset, we are able to preserve the
                    // checked fields and the scroll position of the grid.
                    foreach (GridViewRow gvr in detailGridView.Rows)
                    {
                        CheckBox cb = (CheckBox)gvr.FindControl("pageCheckBox");
                        if (cb.Checked)
                        {
                            String existingValue = gvr.Cells[6].Text.Trim();
                            gvr.Cells[6].Text = prefixTextBox.Text.Trim() + " " + (impliedCheckBox.Checked ? "[" + start + "]" : start);
                            if (!replace && (existingValue != String.Empty))
                            {
                                gvr.Cells[6].Text += ", " + existingValue;
                            }
                            start = this.GetNextPageNumber(style, start, i);
                        }
                    }

                    clearInputs();
                }
            }

            errorControl.Visible = flag;

            // Reset the indicated page fields to the initial values
            prefixTextBox.Text              = "Page";
            freeTextStyleRadio.Checked      = false;
            numStyleRadio.Checked           = true;
            styleDropDownList.SelectedIndex = 0;
            startValueTextBox.Text          = "1";
            incrementTextBox.Text           = "1";
            impliedCheckBox.Checked         = false;
            freeTextBox.Text = "";
        }
示例#60
0
        public void RemoveUser_LogIncremented_ReturnOK()
        {
            var user1 = new SecUser { FirstName = "pippo", Login = "******" };

            CaravanDataSource.Security.AddUser(_myApp.Name, user1);

            WaitForLogger();
            var l = CaravanDataSource.Logger.GetEntries(_myApp.Name);

            CaravanDataSource.Security.RemoveUser(_myApp.Name, user1.Login);

            WaitForLogger();
            var l1 = CaravanDataSource.Logger.GetEntries(_myApp.Name);

            Assert.That(l1.Count(), Is.EqualTo(l.Count() + 1));
        }