public HomeController()
 {
     _db         = new foryoubestDb();
     _userRep    = new UserRepository(_db);
     _orgRep     = new OrganizationRepository(_db);
     _OrgUserRep = new OrganizationUserRepository(_db);
 }
        public ActionResult Delete(int id, FormCollection collection)
        {
            var organizationUser = OrganizationUserRepository.OrganizationUserFetch(id);

            OrganizationUserRepository.OrganizationUserDelete(id);

            return(this.RedirectToAction("Details", "Organization", new { id = organizationUser.OrganizationId }));
        }
Пример #3
0
 public DataAuthenticationController()
 {
     this._userRoleRepository      = RF.Concrete <UserRoleRepository>();
     this._roleOperationRepository = RF.Concrete <RoleOperationRepository>();
     this._operationRepository     = RF.Concrete <ResourceOperationRepository>();
     this._organizationRepository  = RF.Concrete <OrganizationRepository>();
     this._orgUserRepository       = RF.Concrete <OrganizationUserRepository>();
 }
        public static OrganizationUser OrganizationUserAdd()
        {
            var organizationUserMember = OrganizationUserTestHelper.OrganizationUserNew();

            organizationUserMember = OrganizationUserRepository.OrganizationUserSave(organizationUserMember);

            return(organizationUserMember);
        }
        public void OrganizationUser_Fetch_Info_List()
        {
            OrganizationUserTestHelper.OrganizationUserAdd();
            OrganizationUserTestHelper.OrganizationUserAdd();

            var organizationUserMembers = OrganizationUserRepository.OrganizationUserFetchInfoList(new OrganizationUserMemberDataCriteria());

            Assert.IsTrue(organizationUserMembers.Count() > 1, "Row returned should be greater than one");
        }
        public void OrganizationUser_Fetch()
        {
            var organizationUserMember = OrganizationUserTestHelper.OrganizationUserNew();

            organizationUserMember = OrganizationUserRepository.OrganizationUserSave(organizationUserMember);

            organizationUserMember = OrganizationUserRepository.OrganizationUserFetch(organizationUserMember.OrganizationUserMemberId);

            Assert.IsTrue(organizationUserMember != null, "Row returned should not equal null");
        }
        public ActionResult Create(int organizationId, int userId)
        {
            var model            = new OrganizationUserFormModel();
            var organizationUser = OrganizationUserRepository.OrganizationUserNew(organizationId, userId);

            organizationUser.RoleId = (int)Role.Collaborator;

            organizationUser = OrganizationUserRepository.OrganizationUserSave(organizationUser);

            return(this.RedirectToAction("Details", "Organization", new { id = organizationUser.OrganizationId }));
        }
        public static OrganizationUser OrganizationUserNew(Role roleId)
        {
            var organization = OrganizationTestHelper.OrganizationAdd();
            var user         = UserTestHelper.UserAdd();

            var organizationUserMember = OrganizationUserRepository.OrganizationUserNew(organization.OrganizationId, user.UserId);

            organizationUserMember.RoleId = (int)roleId;

            return(organizationUserMember);
        }
        public ActionResult Create(int organizationId)
        {
            var model            = new OrganizationUserFormModel();
            var organizationUser = OrganizationUserRepository.OrganizationUserNew(organizationId, 0);

            model.Title             = "Organization User Create";
            model.Users             = UserRepository.UserFetchInfoList();
            model.OrganizationUser  = organizationUser;
            model.OrganizationUsers = OrganizationUserRepository.OrganizationUserFetchInfoList(organizationId);

            return(this.View(model));
        }
        public void OrganizationUser_Add()
        {
            var organizationUserMember = OrganizationUserTestHelper.OrganizationUserNew();

            Assert.IsTrue(organizationUserMember.IsValid, "IsValid should be true");

            organizationUserMember = OrganizationUserRepository.OrganizationUserSave(organizationUserMember);

            Assert.IsTrue(organizationUserMember.OrganizationUserMemberId != 0, "OrganizationUserMemberId should be a non-zero value");

            OrganizationUserRepository.OrganizationUserFetch(organizationUserMember.OrganizationUserMemberId);
        }
        public ActionResult Delete(int id)
        {
            var model            = new DeleteModel();
            var organizationUser = OrganizationUserRepository.OrganizationUserFetch(id);

            model.Title          = "Organization User Delete";
            model.Id             = organizationUser.OrganizationUserMemberId;
            model.Name           = "Organization User";
            model.Description    = organizationUser.UserName;
            model.ControllerName = "OrganizationUser";
            model.BackUrl        = Url.Action("Details", "Organization", new { id = organizationUser.OrganizationId });

            return(this.View(model));
        }
        public void OrganizationUser_Edit()
        {
            var organizationUserMember = OrganizationUserTestHelper.OrganizationUserNew();

            var roleId = organizationUserMember.RoleId;

            Assert.IsTrue(organizationUserMember.IsValid, "IsValid should be true");

            organizationUserMember = OrganizationUserRepository.OrganizationUserSave(organizationUserMember);

            organizationUserMember = OrganizationUserRepository.OrganizationUserFetch(organizationUserMember.OrganizationUserMemberId);

            organizationUserMember.RoleId = (int)Role.Reviewer;

            organizationUserMember = OrganizationUserRepository.OrganizationUserSave(organizationUserMember);

            organizationUserMember = OrganizationUserRepository.OrganizationUserFetch(organizationUserMember.OrganizationUserMemberId);

            Assert.IsTrue(organizationUserMember.RoleId != roleId, "RoleId should have different value");
        }
Пример #13
0
        /// <summary>
        ///     Attempts to sign in the specified <paramref name="email"/> and <paramref name="password"/> combination.
        /// </summary>
        /// <param name="email">The user email to sign in.</param>
        /// <param name="password">The password to attempt to authenticate.</param>
        /// <returns>Instance of <see cref="TokenContext"/>.</returns>
        public virtual async Task <TokenContext> PasswordSignInAsync(string email, string password)
        {
            if (await UserRepository.GetByEmailAsync(email) is not IUser user)
            {
                throw new AuthenticationException();
            }

            // FUTURE: Single call?
            var organizationId = await OrganizationUserRepository.GetOrganizationByUserIdAsync(user.Id);

            if (await CheckPasswordAsync(user.Id, password))
            {
                if (await UserRepository.GetAccessFailedCount(user.Id) > 10)
                {
                    Logger.LogWarning($"User '{user}' locked out.");

                    throw new AuthenticationException();
                }

                await UserRepository.ResetAccessFailed(user.Id);

                await UserRepository.RegisterAccess(user.Id);

                Logger.LogInformation($"User '{user}' password sign in was successful.");

                Organization organization = await OrganizationRepository.GetByIdAsync(organizationId);

                OrganizationRole organizationRole = await OrganizationUserRepository.GetOrganizationRoleByUserIdAsync(user.Id);

                ClaimsPrincipal principal = PrincipalProvider.CreateTenantUserPrincipal(user, organization,
                                                                                        organizationRole,
                                                                                        JwtBearerDefaults.AuthenticationScheme);
                return(TokenProvider.GetTokenContext(principal));
            }

            Logger.LogWarning($"User '{user}' failed to provide the correct password.");

            await UserRepository.BumpAccessFailed(user.Id);

            throw new AuthenticationException();
        }
        public void OrganizationUser_Delete()
        {
            var organizationUserMember = OrganizationUserTestHelper.OrganizationUserNew();

            Assert.IsTrue(organizationUserMember.IsValid, "IsValid should be true");

            organizationUserMember = OrganizationUserRepository.OrganizationUserSave(organizationUserMember);

            organizationUserMember = OrganizationUserRepository.OrganizationUserFetch(organizationUserMember.OrganizationUserMemberId);

            OrganizationUserRepository.OrganizationUserDelete(organizationUserMember.OrganizationUserMemberId);

            try
            {
                OrganizationUserRepository.OrganizationUserFetch(organizationUserMember.OrganizationUserMemberId);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetBaseException() is InvalidOperationException);
            }
        }
        public void OrganizationUser_Create()
        {
            var organizationUserMember = OrganizationUserRepository.OrganizationUserNew(0, 0);

            Assert.IsTrue(organizationUserMember.IsNew, "IsNew should be true");
            Assert.IsTrue(organizationUserMember.IsDirty, "IsDirty should be true");
            Assert.IsFalse(organizationUserMember.IsValid, "IsValid should be false");
            Assert.IsTrue(organizationUserMember.IsSelfDirty, "IsSelfDirty should be true");
            Assert.IsFalse(organizationUserMember.IsSelfValid, "IsSelfValid should be false");

            Assert.IsTrue(
                ValidationHelper.ContainsRule(organizationUserMember, DbType.Int32, "OrganizationId"),
                "OrganizationId should be required");

            Assert.IsTrue(
                ValidationHelper.ContainsRule(organizationUserMember, DbType.Int32, "UserId"),
                "UserId should be required");

            Assert.IsTrue(
                ValidationHelper.ContainsRule(organizationUserMember, DbType.Int32, "RoleId"),
                "RoleId should be required");
        }