示例#1
0
        public void AddUser(User user, string roleName)
        {
            UserService     = Container.Resolve <IUserService>();
            UserRoleService = Container.Resolve <IUserRoleService>();

            if (string.IsNullOrEmpty(roleName))
            {
                roleName = Constants.RoleNameUser;
            }

            var userRole = new UserRole
            {
                User = user
            };

            var mdmPassword = SecurityHelper.EncryptPassword(user.Password);

            user.Password = mdmPassword;

            var role = GetRole(roleName);

            UserService.Save(user);

            userRole.Roles.Add(role);

            UserRoleService.Save(userRole);
        }
示例#2
0
        private void TestScript(string script, string parameters)
        {
            var renewal         = new Renewal();
            var storeOptions    = new CertificateStoreOptions();
            var settings        = new MockSettingsService();
            var iisClient       = new Mock.Clients.MockIISClient(log);
            var userRoleService = new UserRoleService(iisClient);
            var store           = new CertificateStore(log, iis, settings, userRoleService, storeOptions);
            var oldCert         = cs.RequestCertificate(null, RunLevel.Unattended, renewal, new Target()
            {
                CommonName = "test.local"
            }, null).Result;
            var newCert = cs.RequestCertificate(null, RunLevel.Unattended, renewal, new Target()
            {
                CommonName = "test.local"
            }, null).Result;

            newCert.StoreInfo.Add(typeof(CertificateStore), new StoreInfo()
            {
            });
            var options = new ScriptOptions
            {
                Script           = script,
                ScriptParameters = parameters
            };
            var installer = new Script(renewal, options, new Clients.ScriptClient(log, settings));

            installer.Install(new[] { store }, newCert, oldCert).Wait();
        }
示例#3
0
        protected override async Task OnInitializedAsync()
        {
            allroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
            await LoadSettingsAsync();

            userroles = Search(_search);
        }
示例#4
0
 public SelfHosting(ILogService log, SelfHostingOptions options, UserRoleService userRoleService)
 {
     _log             = log;
     _options         = options;
     _files           = new Dictionary <string, string>();
     _userRoleService = userRoleService;
 }
示例#5
0
 public ResponseMessageWrap <int> Update([FromBody] UserRole userRole)
 {
     return(new ResponseMessageWrap <int>
     {
         Body = UserRoleService.Update(userRole)
     });
 }
示例#6
0
 public ResponseMessageWrap <int> DeleteById(long id)
 {
     return(new ResponseMessageWrap <int>
     {
         Body = UserRoleService.DeleteById(id)
     });
 }
示例#7
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);

            if (AbstractService.Context == null)
            {
                AbstractService.Context = new ApplicationDbContext();
            }
            var store = new UserStore <ApplicationUser>(AbstractService.Context);
            var v     = new ApplicationUserManager(store);
            //var v = new ApplicationUserManager((IUserStore<ApplicationUser>)AbstractService.Context.Users);
            var roleService = new RoleService(new Guid());
            //var accntCnt = new AccountController(v,new ApplicationSignInManager(v,null));
            var accountService  = new AccountService(Guid.NewGuid(), v);
            var userRoleService = new UserRoleService(new Guid(), v);

            if (!roleService.Exists("Admin"))
            {
                roleService.CreateRole("Admin");
                var user = new ApplicationUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                };
                //if (GStorage.Data["UserManager"] == null) throw new Exception("USERMANAGER GLOBAL IS NULL");
                var result = v.Create(user, "SATAN@666");
                var urs    = new UserRoleService(new Guid(), v);
                urs.AssignRole(Guid.Parse(user.Id), roleService.GetRoleByName("Admin"));
                AbstractService.Context.SaveChanges();
            }
            //userRoleService.RemoveUnmapped();
        }
示例#8
0
        public async Task <IHttpActionResult> DeleteUserRole(UserRoleModel userRole)
        {
            if (await UserRoleService.UserRoleExistsForUpdateAndDelete(userRole.ID))
            {
                var userRoleToDelete = new UserRoleModel
                {
                    ID   = userRole.ID,
                    Name = userRole.Name
                };

                CommonResponse roleResponse = await UserRoleService.DeleteRole(userRoleToDelete);

                if (roleResponse.IsError)
                {
                    return(BadRequest("Error In Deleting The User Role!"));
                }
                else
                {
                    return(Ok("User Role Deleted Successfully!"));
                }
            }
            else
            {
                return(BadRequest("User Role Does Not Exist!"));
            }
        }
示例#9
0
 public CreateRoleForUserPage(RegisterUserModel user)
 {
     uri             = Application.Current.Properties["ServerLink"].ToString();
     this.user       = user;
     userRoleService = new UserRoleService();
     InitializeComponent();
 }
示例#10
0
        public async Task <IHttpActionResult> AddUserRole(UserRoleModel userRole)
        {
            if (await UserRoleService.UserRoleExists(userRole.Name))
            {
                return(BadRequest("User Role Already Exists"));
            }
            else
            {
                var usertocreate = new UserRoleModel
                {
                    Name = userRole.Name
                };

                CommonResponse roleResponse = await UserRoleService.AddNewUserRole(usertocreate);

                if (roleResponse.IsError)
                {
                    return(BadRequest("Error In Adding The New Uer Role!"));
                }
                else
                {
                    return(Ok("Successfully Added A New User Role!"));
                }
            }
        }
示例#11
0
        public static bool HasAccess(string controllerName, string actionName, string customName)
        {
            var userService = new UserService();
            var user        = userService.Get();

            var userAuthorizationService = new UserRoleService();
            var moduleService            = new ModuleService();

            int moduleId = 0;

            var actions = actionName.Split(',');

            foreach (var action in actions)
            {
                var module = moduleService.Get($"{controllerName}.{action}.{customName}");

                if (module != null)
                {
                    moduleId = module.Id;
                    break;
                }
            }

            if (moduleId == 0)
            {
                return(false);
            }

            if (userAuthorizationService.GetUserRole(moduleId, user.Id))
            {
                return(true);
            }

            return(false);
        }
        public void DeleteShouldDeleteAndReturnTheDeletedUserRole()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldDeleteAndReturnTheDeletedUserRole))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var addUserRole     = new UserRolePostModel()
                {
                    Name        = "Newbegginer",
                    Description = "A role for a new guy..."
                };


                var actual               = userRoleService.Create(addUserRole);
                var afterDelete          = userRoleService.Delete(actual.Id);
                int numberOfUserRoleInDb = context.UserRoles.CountAsync().Result;
                var resultUR             = context.UserRoles.Find(actual.Id);


                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultUR);
                Assert.AreEqual(0, numberOfUserRoleInDb);
            }
        }
示例#13
0
        /// <summary>
        /// 依据sql语句查询用户
        /// </summary>
        /// <param name="safeSql"></param>
        /// <returns></returns>
        private static IList <User> GetUsersBySql(string safeSql)
        {
            List <User> list = new List <User>();

            using (DataTable table = DBHelper.GetDataSet(safeSql))
            {
                foreach (DataRow row in table.Rows)
                {
                    User user = new User();

                    user.Id        = (int)row["Id"];
                    user.LoginName = (string)row["LoginId"];
                    user.LoginPwd  = (string)row["LoginPwd"];
                    user.Name      = (string)row["Name"];
                    user.Address   = (string)row["Address"];
                    user.Phone     = (string)row["Phone"];
                    user.Mail      = (string)row["Mail"];
                    user.UserState = UserStateService.GetUserStateById((int)row["UserStateId"]); //FK
                    user.UserRole  = UserRoleService.GetUserRoleById((int)row["UserRoleId"]);    //FK

                    list.Add(user);
                }

                return(list);
            }
        }
        public void UpsertShouldModifyTheGivenUserRole()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyTheGivenUserRole))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var toAdd           = new UserRolePostModel()
                {
                    Name        = "Newbegginer",
                    Description = "A role for a new guy..."
                };

                var added = userRoleService.Create(toAdd);

                var update = new UserRolePostModel()
                {
                    Name = "New employee"
                };

                var toUp = userRoleService.Create(update);
                Assert.IsNotNull(toUp);
                Assert.AreEqual(added.Name, added.Name);
                Assert.AreEqual(added.Name, added.Name);
            }
        }
示例#15
0
        public ActionResult ListUsers()
        {
            var model = AccountService.GetAccountListItems();

            foreach (var item in model)
            {
                var rolz = SRoleManager.Roles.ToArray();
                var ctx  = AbstractService.Context;
                List <IdentityRole> bar = new List <IdentityRole>();
                //var userIDStr = User.Identity.GetUserId();
                var userID = new Guid();
                var rarr   = new UserRoleService(userID, UserManager).GetRoles(item.UserID);
                if (rarr != null)
                {
                    foreach (var rm in rarr)
                    {
                        if (rm == null)
                        {
                            continue;
                        }
                        var rid = rm.Id;
                        bar.Add(ctx.Roles.Where(e => e.Id == rid).Single());
                    }
                }
                item.Roles = bar.ToArray();
            }
            return(View(model));
        }
 private void ListUserRoles()
 {
     openTasks++;
     UserRoleService.List()
     .SetCompletion(new OnCompletedHandler <ListResponse <UserRole> >(OnUserRoleListComplete))
     .Execute(client);
 }
示例#17
0
 public IISFtp(IISFtpOptions options, IIISClient iisClient, ILogService log, UserRoleService userRoleService)
 {
     _iisClient       = iisClient;
     _options         = options;
     _log             = log;
     _userRoleService = userRoleService;
 }
        public void UpsertShouldModifyTheGivenUserRole()
        {
            var options = new DbContextOptionsBuilder <TasksDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyTheGivenUserRole))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new TasksDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var toAdd           = new UserRolePostDTO
                {
                    Name        = "Newcomer",
                    Description = "A new guy..."
                };

                var added = userRoleService.Create(toAdd);

                //context.Entry(added).State = EntityState.Detached;

                var update = new UserRolePostDTO
                {
                    Name = "Rouge"
                };

                //var updateResult = userRoleService.Upsert(added.Id, update);

                Assert.NotNull(added);
                Assert.AreEqual(toAdd.Name, toAdd.Name);
                Assert.AreNotEqual(update.Name, toAdd.Name);
            }
        }
示例#19
0
 public SelfHosting(ILogService log, string identifier, SelfHostingOptions options, UserRoleService userRoleService)
 {
     _identifier      = identifier;
     _log             = log;
     _options         = options;
     _userRoleService = userRoleService;
 }
示例#20
0
        public void UpsertShouldModifyFieldsValues()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyFieldsValues))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var expected        = new UserRolePostModel
                {
                    Name        = "Regular",
                    Description = "Regular for test"
                };

                userRoleService.Create(expected);

                var updated = new UserRolePostModel
                {
                    Name        = "Admin",
                    Description = "Admin for test"
                };

                var userUpdated = userRoleService.Upsert(5, updated); //id 5 pt ca altfel imi da eroare de as no tracking

                Assert.NotNull(userUpdated);
                Assert.AreEqual("Admin", userUpdated.Name);
            }
        }
示例#21
0
        public void DeleteShouldRemoveAndReturnUserRole()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldRemoveAndReturnUserRole))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var addUserRole     = userRoleService.Create(new ExamenNet.ViewModels.UserRolePostModel
                {
                    Name        = "Rol testare",
                    Description = "Creat pentru testare"
                });

                Assert.IsNotNull(addUserRole);
                Assert.AreEqual("Rol testare", context.UserRoles.Find(1).Name);

                var deletedUserRole = userRoleService.Delete(1);

                Assert.IsNotNull(deletedUserRole);
                Assert.AreEqual(addUserRole.Name, deletedUserRole.Name);
            }
        }
        public void Upsert()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(Upsert))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var roleService = new UserRoleService(context, config);
                var toAdd       = new UserRolePostDto
                {
                    Name = "GOD"
                };

                var toUpdate = new UserRolePostDto
                {
                    Name = "Sclave Master"
                };

                UserRole role = roleService.Create(toAdd);
                context.Entry(role).State = EntityState.Detached;
                UserRole updated = roleService.Upsert(role.Id, toUpdate);

                Assert.AreNotEqual(role.Name, updated.Name);
            }
        }
示例#23
0
 static ServiceLocator()
 {
     AddressService        = new AddressService();
     BoatService           = new BoatService();
     ClubService           = new ClubService();
     UserService           = new UserService();
     EntryService          = new EntryService();
     RaceEventService      = new RaceEventService();
     RegattaService        = new RegattaService();
     SocialEventService    = new SocialEventService();
     TeamService           = new TeamService();
     EmailService          = new EmailService();
     PhoneNumberService    = new PhoneNumberService();
     RegisteredUserService = new RegisteredUserService();
     ResultService         = new ResultService();
     UserRoleService       = new UserRoleService();
     ClubsUsersUserRolesJunctionsService    = new Clubs_Users_UserRoles_JunctionsService();
     RegattasUsersUserRolesJunctionsService = new Regattas_Users_UserRoles_JunctionsService();
     RegisteredUserSocialEventService       = new RegisteredUser_SocialEventService();
     TeamRaceEventService      = new Team_RaceEventService();
     TeamRegisteredUserService = new Team_RegisteredUserService();
     BoatService = new BoatService();
     SocialEventsUsersUserRolesJunctionsService = new SocialEvents_Users_UserRoles_JunctionsService();
     RaceEventsUsersUserRolesJunctionsService   = new RaceEvents_Users_UserRoles_JunctionsService();
     ClubsEmailsService       = new ClubsEmailsService();
     ClubsPhoneNumbersService = new ClubsPhoneNumbersService();
 }
示例#24
0
 public ExternalController()
 {
     db = new MyDBcontext();
     UserRoleService = new UserRoleService();
     userService     = new UserService();
     response        = new Response();
 }
示例#25
0
 public IISWeb(Target target, IISWebOptions options, IIISClient iisClient, ILogService log, UserRoleService userRoleService)
 {
     _iisClient       = iisClient;
     _log             = log;
     _options         = options;
     _target          = target;
     _userRoleService = userRoleService;
 }
示例#26
0
 public WelcomeTabbedPage()
 {
     NavigationPage.SetHasBackButton(this, false);
     userRoleService = new UserRoleService();
     _connection     = DependencyService.Get <ISQLiteDb>().GetConnection();
     userService     = new UserService();
     InitializeComponent();
 }
示例#27
0
        public void UserRoleService_Get()
        {
            UserRoleService service = new UserRoleService(mockRepository.Object, mockMapper.Object);

            var result = service.Get();

            Assert.IsNotNull(result);
        }
 private void ListUserRolesWithImpersonation()
 {
     openTasks++;
     UserRoleService.List()
     .WithUserId(IMPERSONATION_TEST_USER_ID)
     .SetCompletion(new OnCompletedHandler <ListResponse <UserRole> >(OnUserRoleListComplete))
     .Execute(client);
 }
示例#29
0
 public IISSiteTests()
 {
     log             = new Mock.Services.LogService(false);
     iis             = new Mock.Clients.MockIISClient(log);
     helper          = new IISSiteHelper(log, iis);
     plugins         = new MockPluginService(log);
     userRoleService = new UserRoleService(iis);
 }
示例#30
0
        /// <summary>
        /// This method is called when the page is loaded and paramters are set
        /// </summary>
        /// <returns></returns>
        protected async override Task OnParametersSetAsync()
        {
            Employee = await UserService.GetUser(EmployeeId);

            UserRoles = await UserRoleService.GetAll();

            await base.OnParametersSetAsync();
        }
示例#31
0
        private void BindGrid()
        {
            bool isAdmin = IsAdmin;
            // 审核员角色Id
            string role = ConfigurationManager.AppSettings["CheckRoleId"];
            int roleId = Convert.ToInt32(role);
            UserRoleService urs = new UserRoleService();
            // 如果用户有审核员的角色,则能审核全部文章
            if (urs.Exists(cmsUserRole._.UserId == UserID && cmsUserRole._.RoleId == roleId))
            {
                isAdmin = true;
            }
            int recordCount = 0;
            DataTable dt = ns.GetListByFilter2(
                "",
                txtTitle.Text,
                txtSource.Text,
                txtAuthor.Text,
                txtTags.Text,
                Convert.ToInt32(ddlIndex.SelectedValue),
                Convert.ToInt32(ddlTop.SelectedValue),
                Convert.ToInt32(type),
                txtAddTime1.Text,
                txtAddTime2.Text,
                txtEditTime1.Text,
                txtEditTime2.Text,
                UserID,
                isAdmin,
                pager.CurrentPageIndex,
                pager.PageSize,
                ref recordCount);

            // 绑定数据到GridView
            base.BindGrid(recordCount, dt);
        }
示例#32
0
		public AccountController() {
			HouseholdService = new HouseholdService(AppSession);
			UserService = new UserRoleService(AppSession);
		}
示例#33
0
        public ActionResult Create(CreateAccountModel model)
        {
            if (ModelState.IsValid)
            {

                try
                {
                    //If there are no UserRoles in the Roles table shit breaks, Add them if not present
                    UserRoleService URS = new UserRoleService();
                    if (URS.GetCount() == 0)
                    {
                        UserRole UR = new UserRole();
                        UR.Name = "Administrator";
                        URS.Save(UR);
                        UR = new UserRole();
                        UR.Name = "User";
                        URS.Save(UR);
                    }

                    //Armor.Data.User user = Mapper.Map<CreateAccountModel, Armor.Data.User>(model);
                    User Newuser = new User();

                    Newuser.Address = model.Address;
                    Newuser.City = model.City;
                    Newuser.CreatedDate = DateTime.UtcNow;
                    Newuser.EmailAddress = model.EmailAddress;
                    Newuser.FaxNumber = model.Fax;
                    Newuser.FirstName = model.FirstName;
                    Newuser.ForgotPasswordHash = new Guid();
                    Newuser.GSTInformation = model.GSTInformation;
                    Newuser.IsActive = true;
                    Newuser.LastName = model.LastName;
                    Newuser.Password = PasswordHelpers.EncryptPassword(model.Password);
                    Newuser.PhoneNumber = model.Phone;
                    Newuser.PostalCode = model.PostalCode;
                    Newuser.Province = model.Province;
                    Newuser.RoleID = URS.GetByRoleName("User").ID ;

                    service.Save(Newuser);

                    // build a message to send to the user.
                    //string validateUrl = string.Format("{0}account/validate/{1}", App.BaseUrl, Helpers.base64Encode(user.EmailAddress));

                    //TemplateParser parser = new TemplateParser();
                    //Dictionary<string, string> replacements = new Dictionary<string, string>();
                    //replacements.Add("[BASE_URL]", App.BaseUrl);
                    //replacements.Add("[FIRST_NAME]", user.EmailAddress);
                    //replacements.Add("[VALIDATE_ACCOUNT_URL]", validateUrl);

                    //string message = parser.Replace(AccountEmails.ValidateAccount, replacements);

                    //EmailSender sender = new EmailSender();
                    //sender.Send(App.MailConfiguration, model.EmailAddress, "", "Thank you for registering on epilogger.com", message);

                    //this.StoreSuccess("Your account was created successfully<br /><br/>Please check your inbox for our validation message, your account will be inaccessable until you validate it.");

                    return RedirectToAction("login", "account");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ViewRes.SharedString.CreateAccountProblem + " - " + ex.Message.ToString());
                    return View(model);
                }
            }
            else
                return View(model);
        }
示例#34
0
 public HouseholdController()
 {
     Service = new HouseholdService(AppSession);
     UserService = new UserRoleService(AppSession);
 }
示例#35
0
 public DropboxController()
 {
     Service = new UserRoleService(AppSession);
     BankDataService = new BankAccountService(AppSession);
 }