コード例 #1
0
        private void SeedUserRoleType(DataContext context)
        {
            List <string> items = new List <string>()
            {
                "CRO",
                "AVP",
                "CEO",
                "DBD",
                "CL",
                "CAC",
                "PU",
                "MC",
                "SLH",
                "CU",
                "CBO",
                "NCM",
                "IT"
            };

            foreach (string item in items)
            {
                var entity = context.UserRoleTypes.Where(p => p.Name == item && p.Deleted == false).SingleOrDefault();

                if (entity == null)
                {
                    entity      = new UserRoleType();
                    entity.Name = item;
                    context.UserRoleTypes.Add(entity);
                }
            }
        }
コード例 #2
0
 public void AssignRoleToUser(ApplicationUser user, UserRoleType userRole)
 {
     if (!_userManager.IsInRoleAsync(user, userRole.ToString()).Result)
     {
         _userManager.AddToRoleAsync(user, userRole.ToString()).Wait();
     }
 }
コード例 #3
0
        private void GetRoleType(int userId)
        {
            UserRoleType userRoleType = new UserRoleType();

            userRoleType.Attach(this);
            userRoleType.GetUserRoleId(userId);
        }
        public static void AttachRole(User user, UserRoleType role)
        {
            var userStore   = new UserStore <User>(new CaiDbContext());
            var userManager = new UserManager <User>(userStore);

            userManager.AddToRole(user.Id, role.ToString());
        }
コード例 #5
0
 public void Test1()
 {
     UserRoleType.findAll(typeof(UserRoleType)).ForEach(userRole =>
     {
         Assert.True(userRole.name.Equals(dbContext.userRoleTypes.Single(u => u.value == userRole.value).name));
         _testOutputHelper.WriteLine(userRole.name + " : " + userRole.value);
     });
 }
コード例 #6
0
ファイル: User.cs プロジェクト: ch604aru/ProviderBase
 public User()
 {
     this.UserID         = 0;
     this.Username       = "";
     this.Encrypted      = "";
     this.CreateDate     = new DateTime(1900, 1, 1);
     this.ModifyDate     = new DateTime(1900, 1, 1);
     this.LastLogin      = new DateTime(1900, 1, 1);
     this.UserRoleTypeID = UserRoleType.Unassigned;
 }
コード例 #7
0
        /// <summary>
        /// Check whether the user has any of the allowed roles to access given functionality.
        /// </summary>
        /// <param name="user">User account with roles.</param>
        /// <param name="requiredRole">Required user role.</param>
        /// <exception cref="InsufficientRoleException">is thrown when the user doesn't have any role specified by <see cref="allowedRoles"/></exception>
        internal static void CheckUserRole(AdaptorUser user, UserRoleType requiredUserRole)
        {
            bool hasRequiredRole = user.Roles.Any(userRole => (UserRoleType)userRole.Id == requiredUserRole);

            if (!hasRequiredRole)
            {
                using var unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork();
                var requiredRoleModel = unitOfWork.AdaptorUserRoleRepository.GetById((long)requiredUserRole);
                throw InsufficientRoleException.CreateMissingRoleException(requiredRoleModel, user.Roles);
            }
        }
コード例 #8
0
ファイル: Client.cs プロジェクト: dangnr/GameRent.Api
 public Client(Guid id, string firstName, string lastName, string cpf, string email, string username, string password, UserRoleType role, bool isActive)
 {
     Id        = id;
     FirstName = firstName;
     LastName  = lastName;
     Cpf       = cpf;
     Email     = email;
     Username  = username;
     Password  = password;
     Role      = role;
     IsActive  = isActive;
 }
コード例 #9
0
ファイル: Client.cs プロジェクト: dangnr/GameRent.Api
 public Client(string firstName, string lastName, string cpf, string email, string username, string password, UserRoleType role)
 {
     Id        = Guid.NewGuid();
     FirstName = firstName;
     LastName  = lastName;
     Cpf       = cpf;
     Email     = email;
     Username  = username;
     Password  = password;
     Role      = role;
     IsActive  = true;
     CreatedOn = DateTime.Now;
 }
コード例 #10
0
ファイル: Client.cs プロジェクト: dangnr/GameRent.Api
 public void UpdateClient(Client client)
 {
     Id        = client.Id;
     FirstName = client.FirstName;
     LastName  = client.LastName;
     Cpf       = client.Cpf;
     Email     = client.Email;
     Username  = client.Username;
     Password  = client.Password;
     Role      = client.Role;
     IsActive  = client.IsActive;
     UpdatedOn = DateTime.Now;
 }
コード例 #11
0
        public async Task <bool> HasRole(int id, UserRoleType urt)
        {
            var user = await GetUserById(id);

            if (user != null)
            {
                return(user.Roles.Any(r => r == (int)urt));
            }
            else
            {
                return(false);
            }
        }
コード例 #12
0
        /// <summary>
        /// 根据Id获取
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public UserRoleType GetById(int Id)
        {
            UserRoleType obj = NSession.Get <UserRoleType>(Id);

            if (obj == null)
            {
                throw new Exception("返回实体为空");
            }
            else
            {
                return(obj);
            }
        }
コード例 #13
0
 public ActionResult Edit(UserRoleType obj)
 {
     try
     {
         NSession.Update(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
コード例 #14
0
 public JsonResult DeleteConfirmed(int id)
 {
     try
     {
         UserRoleType obj = GetById(id);
         NSession.Delete(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return(Json(new { IsSuccess = false, ErrorMsg = "出错了" }));
     }
     return(Json(new { IsSuccess = true }));
 }
コード例 #15
0
 public async Task AddToRoleAsync(UserModel user, UserRoleType role)
 {
     using (var db = HibernateSession.GetCurrentSession()) {
         using (var tx = db.BeginTransaction()) {
             user = db.Get <UserModel>(user.Id);
             user.Roles.Add(new UserRole()
             {
                 RoleType = role
             });
             db.SaveOrUpdate(user);
             tx.Commit();
             db.Flush();
         }
     }
 }
コード例 #16
0
        public async Task <IList <string> > GetAuthorizedMenus(string role)
        {
            var menus    = new List <string>();
            var userRole = UserRoleType.Parse(typeof(UserRoleType), role);

            await Task.Run(() =>
            {
                switch (userRole)
                {
                case UserRoleType.Admin:
                    menus.Add("ClassRooms");
                    menus.Add("Classes");
                    menus.Add("Students");
                    menus.Add("Teachers");
                    menus.Add("Calenders");
                    menus.Add("CenterAdmins");
                    break;

                case UserRoleType.CenterAdmin:
                    menus.Add("ClassRooms");
                    menus.Add("Classes");
                    menus.Add("Students");
                    menus.Add("Teachers");
                    menus.Add("Calenders");
                    break;

                case UserRoleType.Head:
                    menus.Add("ClassRooms");
                    menus.Add("Calenders");
                    break;

                case UserRoleType.Student:
                    menus.Add("MyCalender");
                    menus.Add("ClassRooms");
                    menus.Add("Classes");
                    break;

                case UserRoleType.Teacher:
                    menus.Add("MyCalender");
                    menus.Add("ClassRooms");
                    menus.Add("Classes");
                    break;
                }
            });

            return(menus.ToList());
        }
コード例 #17
0
ファイル: UserTests.cs プロジェクト: stringly/EventsCore
        public void Should_Throw_UserArgumentException_When_Removing_User_From_NonExisting_Role()
        {
            // Arrange
            string ldapName      = "User123";
            uint   blueDeckId    = 1;
            string firstName     = "Bob";
            string lastName      = "Jones";
            string idNumber      = "1234";
            string email         = "*****@*****.**";
            string contactNumber = "1234567890";
            int    rankId        = 1;
            var    user          = new User(ldapName, blueDeckId, firstName, lastName, idNumber, email, contactNumber, rankId);
            var    role          = new UserRoleType {
                Name = "Administrator"
            };

            // Act/Assert
            Assert.Throws <UserArgumentException>(() => user.RemoveFromRole(role));
        }
コード例 #18
0
        public JsonResult UpdateUserRole(int id, UserRoleType role)
        {
            var user = _db.Users
                       .Include(u => u.UserRoles)
                       .Single(u => u.UserId == id);

            var uRole = user.UserRoles.First();

            uRole.RoleType = role;
            var log = new UserLog(CurrentUser, id)
            {
                Comment = "Made " + uRole.RoleType.ToString()
            };

            _db.UserLogs.Add(log);
            _db.Entry(uRole).State = System.Data.EntityState.Modified;
            _db.SaveChanges();
            return(GetErrorMsgJSON());
        }
コード例 #19
0
ファイル: UserTests.cs プロジェクト: stringly/EventsCore
        public void Can_Add_User_To_Role()
        {
            // Arrange
            string ldapName      = "User123";
            uint   blueDeckId    = 1;
            string firstName     = "Bob";
            string lastName      = "Jones";
            string idNumber      = "1234";
            string email         = "*****@*****.**";
            string contactNumber = "1234567890";
            int    rankId        = 1;
            var    user          = new User(ldapName, blueDeckId, firstName, lastName, idNumber, email, contactNumber, rankId);
            var    role          = new UserRoleType {
                Name = "Administrator"
            };

            // Act
            user.AddToRole(role);

            // Assert
            Assert.Single(user.Roles);
        }
コード例 #20
0
        public async Task RemoveFromRoleAsync(UserModel user, UserRoleType role)
        {
            using (var db = HibernateSession.GetCurrentSession()) {
                using (var tx = db.BeginTransaction()) {
                    user = db.Get <UserModel>(user.Id);
                    var found = user.Roles.NotNull(y => y.ToList().FirstOrDefault(x => x.RoleType == role));
                    if (found != null)
                    {
                        found.DeleteTime = DateTime.UtcNow;
                        db.Delete(found);
                        user.Roles.Remove(found);
                    }
                    else
                    {
                        throw new PermissionsException("Role could not be removed because it doesn't exist.");
                    }
                    //user.Roles.Remove(found);
                    //db.Update(user);

                    tx.Commit();
                    db.Flush();
                }
            }
        }
コード例 #21
0
        public async Task <bool> HasRole(int userId, UserRoleType urt)
        {
            var result = await _db.Include(u => u.RoleToUsers).ThenInclude(r => r.Role).SingleOrDefaultAsync(u => u.UserId == userId);

            return(result.RoleToUsers.Any(rtu => rtu.Role.UserRoleType == urt));
        }
コード例 #22
0
        public JsonResult UpdateUserRole(int id, UserRoleType role)
        {
            var user = _db.Users
                .Include(u => u.UserRoles)
                .Single(u => u.UserId == id);

            var uRole = user.UserRoles.First();
            uRole.RoleType = role;
            var log = new UserLog(CurrentUser, id)
                {
                    Comment = "Made " + uRole.RoleType.ToString()
                };
            _db.UserLogs.Add(log);
            _db.Entry(uRole).State = System.Data.EntityState.Modified;
            _db.SaveChanges();
            return GetErrorMsgJSON();
        }
コード例 #23
0
        public ActionResult Edit(int id)
        {
            UserRoleType obj = GetById(id);

            return(View(obj));
        }
コード例 #24
0
 /// <summary>
 /// Checks if role is in collection by RoleID
 /// </summary>
 /// <param name="adaptorUserUserRoles"></param>
 /// <param name="role"></param>
 /// <returns></returns>
 private static bool IsRoleInCollection(IEnumerable <AdaptorUserUserRole> adaptorUserUserRoles, UserRoleType role)
 {
     return(adaptorUserUserRoles.Any(x => x.AdaptorUserRoleId.Equals((long)role)));
 }
コード例 #25
0
 public AuthPolicyRequirement(UserRoleType type)
 {
     this.UserRoleType = type;
 }
コード例 #26
0
        /// <summary>
        /// Checks and adds Role to collection when is not in collection grouped by User
        /// </summary>
        /// <param name="currentUserUserRoles">Collection of role to user mapping grouped by User</param>
        /// <param name="roleType"></param>
        /// <param name="adaptorUserUserRolesCollection">Global role to user collection mapping</param>
        private static void CheckAndAddUserUserRole(IEnumerable <AdaptorUserUserRole> currentUserUserRoles, UserRoleType roleType, List <AdaptorUserUserRole> adaptorUserUserRolesCollection)
        {
            var userRole = currentUserUserRoles.FirstOrDefault();

            if (!IsRoleInCollection(currentUserUserRoles, roleType))
            {
                adaptorUserUserRolesCollection.Add(new AdaptorUserUserRole()
                {
                    AdaptorUserId     = userRole.AdaptorUserId,
                    AdaptorUserRoleId = (long)roleType
                });
            }
        }
コード例 #27
0
 public AuthorizationAttribute(UserRoleType roleType, string result = "")
 {
     RoleCodes = new int[] { (int)roleType };
     Result    = result;
 }
コード例 #28
0
 public Task AssociateAdvisorUserRoleAsync(string NTLogin, UserRoleType AdvisorRole, string ModifiedBy)
 {
     throw new NotImplementedException();
 }
コード例 #29
0
ファイル: User.cs プロジェクト: arunghosh/alumni-network
 public bool IsInRole(UserRoleType role)
 {
     return UserRoles.Any(r => r.RoleType == role);
 }
コード例 #30
0
        public async Task <IActionResult> GetByRole(UserRoleType role)
        {
            var response = await _mediator.Send(new ClientQueryRequest(role : role));

            return(CustomResponse.GetResponse(response));
        }
コード例 #31
0
 public UserRoleModel(UserRoleType name, params UserOperationModel[] userOperations)
 {
     this.Name           = name;
     this.UserOperations = userOperations;
 }
コード例 #32
0
 public UserRoleViewModel(UserRoleType userRoleType)
 {
     UserRoleType = userRoleType;
 }