private void btnDeleteRole_Click(object sender, EventArgs e)
        {
            int RoleID;

            if (WinFormUtil.DataGridView_GetSelectedID(dgvRoles, out RoleID))
            {
                BOUser   current_user = AccountantPool.Instance.CurrentAccountant.User;
                AuthRole role         = current_user.GetAuthRole(RoleID);
                if (role != null)
                {
                    if (current_user.CanDelete(role))
                    {
                        if (WinFormUtil.Confirm("Do you want to delete?", "Delete Warning") == DialogResult.Yes)
                        {
                            current_user.Delete(role);
                            ViewModel();
                        }
                    }
                    else if (WinFormUtil.Confirm("Other roles and users have inherited this role, delete this role will also delete them,\r\n do you still want to delete?", "Delete Warning") == DialogResult.Yes)
                    {
                        current_user.Delete(role);
                        ViewModel();
                    }
                }
            }
        }
 private void Build(TreeNode node, AuthRole role)
 {
     node.Text        = role.RoleName;
     node.Tag         = role;
     node.ToolTipText = role.Description;
     node.Checked     = mRole.HasRole(role, false);
 }
示例#3
0
        public void Login()
        {
            bool validated = false;

            DacII.WinForms.Security.FrmMyobLogin frm = new DacII.WinForms.Security.FrmMyobLogin(mAccountant);
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                validated = true;
            }

            if (!validated)
            {
                Exit();
            }
            else
            {
                BOUser curr_user = mAccountant.CurrentAuthUser;
                if (curr_user != null)
                {
                    AuthRole curr_role = curr_user.Role;
                    IsFullControl = curr_role == null || curr_role.IsFullControl;
                    Username      = curr_user.Username;
                }

                ShowCmd();

                mMiscPresenter.BackupEnabled = true;
            }
        }
 public BORole(Accountant acc, AuthRole data, BOContext context)
     : base(acc, context)
 {
     mObjectID   = BOType.BORole;
     mDataSource = data;
     mDataProxy  = data.Clone() as AuthRole;
 }
示例#5
0
        private void RemoveRoleItem(AuthRole _obj)
        {
            DbDeleteStatement statement = DbMgr.CreateDeleteClause();

            statement.DeleteFrom("AuthRoleItem").Criteria.IsEqual("AuthRoleItem", "RoleID", _obj.RoleID);
            ExecuteNonQuery(statement);
        }
示例#6
0
        public ActionResult Index(int?appId = null, string username = null, string password = null, bool isKeep = false, string backurl = null)
        {
            if (!appId.HasValue)
            {
                result.msg = "参数不能为空_appId";
                return(Json(result));
            }

            //清除缓存
            CookieHelper.Remove("dz_UserCookieNew");
            Response.ContentEncoding = Encoding.UTF8;
            username = StringHelper.NoHtml(username.Trim());
            password = StringHelper.NoHtml(password);

            AuthRole admin = AuthRoleBLL.SingleModel.UserLogin(appId.Value, username, password);

            if (admin == null)
            {
                result.msg = "用户名或密码错误";
                return(Json(result));
            }

            XcxAppAccountRelation app = XcxAppAccountRelationBLL.SingleModel.GetModel(admin.AId);

            if (app == null)
            {
                result.msg = "小程序不存在";
                return(Json(result));
            }
            Account account = AccountBLL.SingleModel.GetModel(app.AccountId);

            if (account == null)
            {
                result.msg = "授权账号不存在";
                return(Json(result));
            }

            Session["userName"]    = username;
            Session["passWord"]    = password;
            Session["dzAccountId"] = account.Id.ToString();
            if (isKeep)//--保存本地用户名
            {
                CookieHelper.SetCookie("LoginUserName", HttpUtility.UrlEncode(username));
            }
            else
            {
                CookieHelper.Remove("LoginUserName");
            }

            Task.Factory.StartNew(() =>
            {
                AuthRoleBLL.SingleModel.UpdateLoginTime(admin);
            });

            result.code = 1;
            result.msg  = "登陆成功";
            result.obj  = new { loginToken = account.Id, authToken = DESEncryptTools.DESEncrypt(admin.Id.ToString()), url = $"/pin/main?Id={app.Id}&appId={app.Id}" };
            return(Json(result));
        }
        public IActionResult AuthLogin(LoginDto body)
        {
            var User = _BaseService.GetListWriteBy <Users>(x => x.UserName == body.UserName);

            if (User.Count <= 0)
            {
                return(Ok(new ApiNResponse(code: CodeAndMessage.用户名不存在, message: "The user name does not exist")));
            }
            if (User.Where(x => x.UserName == body.UserName && x.PassWord == HashPass.HashString(body.PassWord, "MD5")).Count() <= 0)
            {
                return(Ok(new ApiNResponse(code: CodeAndMessage.密码错误, message: "Password error")));
            }

            if (User.Where(x => x.UserName == body.UserName && x.PassWord == HashPass.HashString(body.PassWord, "MD5") && x.CreateTime.AddHours(2) < DateTime.Now && x.LoginType == LoginType.LimitWeb).Count() > 0)
            {
                return(Ok(new ApiNResponse(code: CodeAndMessage.注册时间已经超过2小时, message: "The registration time has exceeded 2 hours. Please re-register")));
            }

            UserInfo userInfo = new UserInfo();

            foreach (var item in User)
            {
                userInfo = new UserInfo()
                {
                    id       = item.Id,
                    AuthRole = new List <AuthRole>()
                    {
                        item.AuthRole
                    },
                    Email     = item.Email,
                    LoginType = new List <LoginType>()
                    {
                        item.LoginType
                    },
                    CreateTime = item.CreateTime
                };
            }
            string   token     = Guid.NewGuid().ToString();
            AuthRole AuthRoles = userInfo.AuthRole.First();

            switch (AuthRoles)
            {
            case Models.AuthRole.Admin:
                AuthRedis.GetUserById(userInfo.id, LoginType.FreeWeb);
                AuthRedis.SetToken(userInfo, token, LoginType.FreeWeb);
                break;

            case Models.AuthRole.User:
                AuthRedis.GetUserById(userInfo.id, LoginType.LimitWeb);
                AuthRedis.SetToken(userInfo, token, LoginType.LimitWeb);
                break;

            default:
                break;
            }
            return(Ok(new ApiResponse(new { token, AuthRoles })));
        }
示例#8
0
        private void btnDeleteRole_Click(object sender, EventArgs e)
        {
            if (dgvRoles.SelectedRows.Count == 0)
            {
                return;
            }
            AuthRole role = dgvRoles.SelectedRows[0].DataBoundItem as AuthRole;

            mApplicationController.DeleteAuthRole(role);
        }
 private void ReviseRoleRole(TreeNode node)
 {
     if (node.Checked)
     {
         AuthRole role = (AuthRole)node.Tag;
         if (!mRole.HasRole(role, false) && !mRole.Equals(role))
         {
             mRole.Children.Add(role);
         }
     }
 }
        private void btnCreateRole_Click(object sender, EventArgs e)
        {
            BOUser      current_user = AccountantPool.Instance.CurrentAccountant.User;
            AuthRole    role         = current_user.CreateAuthRole();
            FrmAuthRole frm          = new FrmAuthRole(role);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                ViewModel();
            }
        }
示例#11
0
        public ActionResult Account(int?aId = null, int?roleId = null)
        {
            AuthRole role = null;

            if (roleId.HasValue)
            {
                role = AuthRoleBLL.SingleModel.GetByAId(aId.Value, roleId: roleId.Value);
            }
            List <AuthGroup> group = AuthGroupBLL.SingleModel.GetListByAId(aId: aId.Value);

            return(View(Tuple.Create(role, group)));
        }
示例#12
0
 public object UpsertRole(AuthRole role)
 {
     if (GetRoleByName(role.RoleName) is FakeRole r)
     {
         _roles.Remove(r);
         _roles.Add(r);
         return(r.RoleName);
     }
     else
     {
         _roles.Add(role as FakeRole);
         return(role.RoleName);
     }
 }
示例#13
0
    public AuthRole GetSelectRole()
    {
        AuthRole oAuthRole = null;

        if (this.trvGroup.SelectedNode != null && this.trvGroup.SelectedNode.Value != "")
        {
            string      sRoleID = trvGroup.SelectedNode.Value;
            ObjectQuery oQuery  = new ObjectQuery();

            //IList lstAuthRole = AuthSvr.AuthConfigSrv.GetRoleAuthConfig(sRoleID);//GetAuthRoleByRoleID(sRoleID);
            //oAuthRole = lstAuthRole != null && lstAuthRole.Count > 0 ? lstAuthRole[0] as AuthRole : null;
            oAuthRole = GetAuthRoleByRoleID(sRoleID);
        }
        return(oAuthRole);
    }
 private bool SubRoleCheckAccess(AuthItem item)
 {
     foreach (TreeNode node in tvAuthRoles.Nodes)
     {
         if (node.Checked)
         {
             AuthRole role = (AuthRole)node.Tag;
             if (role.CheckAccess(item))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#15
0
        public static AuthorizationResponse GetAuthorizations(this Authorization request,
                                                              Factory factory, IRequestContext requestContext)
        {
            var          httpRequest = requestContext.Get <IHttpRequest>();
            IAuthSession session     = httpRequest.GetSession();

            if (!session.HasRole(RoleNames.Admin))
            {
                request.UserId = int.Parse(session.UserAuthId);
            }

            List <AuthRole>       roles       = new List <AuthRole>();
            List <AuthPermission> permissions = new List <AuthPermission>();

            List <AuthRoleUser>       aur     = new List <AuthRoleUser>();
            List <AuthRole>           rol     = new List <AuthRole>();
            List <AuthPermission>     per     = new List <AuthPermission>();
            List <AuthRolePermission> rol_per = new List <AuthRolePermission>();

            factory.Execute(proxy =>
            {
                aur = proxy.Get <AuthRoleUser>(q => q.UserId == request.UserId);
                //proxy.GetByUserIdFromCache<AuthRoleUser>(request.UserId); // causa problemas .net !!! no en mono
                rol     = proxy.GetFromCache <AuthRole>();
                per     = proxy.GetFromCache <AuthPermission>();
                rol_per = proxy.GetFromCache <AuthRolePermission>();

                foreach (var r in aur)
                {
                    AuthRole ar = rol.First(x => x.Id == r.AuthRoleId);
                    roles.Add(ar);
                    rol_per.Where(q => q.AuthRoleId == ar.Id).ToList().ForEach(y => {
                        AuthPermission up = per.First(p => p.Id == y.AuthPermissionId);
                        if (permissions.FindIndex(f => f.Name == up.Name) < 0) // .IndexOf(up) <0)
                        {
                            permissions.Add(up);
                        }
                    });
                }
                ;
            });

            return(new AuthorizationResponse()
            {
                Permissions = permissions,
                Roles = roles,
            });
        }
示例#16
0
        private void InsertRoleItem(AuthRole _obj)
        {
            foreach (AuthItem item in _obj.ForbiddenItems)
            {
                Dictionary <string, DbFieldEntry> fields = new Dictionary <string, DbFieldEntry>();
                fields["RoleID"]      = DbMgr.CreateIntFieldEntry(_obj.RoleID);
                fields["ItemID"]      = DbMgr.CreateIntFieldEntry(item.ItemID);
                fields["Description"] = DbMgr.CreateStringFieldEntry(string.Format("{0} can act on {1}", _obj.RoleName, item.ItemName));

                DbInsertStatement statement = DbMgr.CreateInsertClause();
                statement
                .InsertColumns(fields)
                .Into("AuthRoleItem");
                ExecuteNonQuery(statement);
            }
        }
示例#17
0
        private void InsertRoleRole(AuthRole _obj)
        {
            foreach (AuthRole child_role in _obj.Children)
            {
                Dictionary <string, DbFieldEntry> fields = new Dictionary <string, DbFieldEntry>();
                fields["ParentRoleID"] = DbMgr.CreateIntFieldEntry(_obj.RoleID);
                fields["ChildRoleID"]  = DbMgr.CreateIntFieldEntry(child_role.RoleID);
                fields["Description"]  = DbMgr.CreateStringFieldEntry(string.Format("{0} is superset of {1}", _obj.RoleName, child_role.RoleName));

                DbInsertStatement statement = DbMgr.CreateInsertClause();
                statement
                .InsertColumns(fields)
                .Into("AuthRoleRole");
                ExecuteNonQuery(statement);
            }
        }
        private void dgvRoles_DoubleClick(object sender, EventArgs e)
        {
            int RoleID;

            if (WinFormUtil.DataGridView_GetSelectedID(dgvRoles, out RoleID))
            {
                BOUser   current_user = AccountantPool.Instance.CurrentAccountant.User;
                AuthRole role         = current_user.GetAuthRole(RoleID);
                if (role != null)
                {
                    FrmAuthRole frm = new FrmAuthRole(role);
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        ViewModel();
                    }
                }
            }
        }
示例#19
0
        public static Response <AuthRole> Put(this AuthRole request,
                                              Factory factory,
                                              IHttpRequest httpRequest)
        {
            factory.Execute(proxy => {
                proxy.DeleteFromCache <AuthRole>();
                proxy.Update(request);
            });

            List <AuthRole> data = new List <AuthRole>();

            data.Add(request);

            return(new Response <AuthRole>()
            {
                Data = data
            });
        }
示例#20
0
        /// <summary>
        /// Creates an AuthZAttribute object depending on authorization parameters.
        /// </summary>
        /// <param name="displayName">Display name of a user. Cannot be null for non anon AuthZ</param>
        /// <param name="householdID">HouseholdID of a user. Value is 0 for anon and user AuthZ</param>
        /// <param name="role">Enumeration of user authorization privileges</param>
        /// <param name="admin">Enumeration of admin authorization privileges</param>
        /// <returns></returns>
        public AuthZAttribute CreateAuthZ(string displayName, int householdID, AuthRole role, AuthAdmin admin)
        {
            try
            {
                bool[] adminAuthZ = GetAdminAuthZ(admin);
                switch (role)
                {
                case AuthRole.user:
                    if ((displayName == null))
                    {
                        throw new ArgumentException("User display name is invalid");
                    }
                    return(_authZFactory.CreateUserAuthZ(displayName, adminAuthZ));

                case AuthRole.host:
                    if ((displayName == null) || (householdID == 0))
                    {
                        throw new ArgumentException("Host display name or householdID is invalid");
                    }
                    return(_authZFactory.CreateHostAuthZ(displayName, householdID, adminAuthZ));

                case AuthRole.cohost:
                    if ((displayName == null) || (householdID == 0))
                    {
                        throw new ArgumentException("CoHost display name or householdID is invalid");
                    }
                    return(_authZFactory.CreateCoHostAuthZ(displayName, householdID, adminAuthZ));

                case AuthRole.tenant:
                    if ((displayName == null) || (householdID == 0))
                    {
                        throw new ArgumentException("Host display name or householdID is invalid");
                    }
                    return(_authZFactory.CreateTenantAuthZ(displayName, householdID, adminAuthZ));

                default:
                    return(_authZFactory.CreateAnonAuthZ());
                }
            }
            catch (ArgumentException)
            {
                return(_authZFactory.CreateAnonAuthZ());
            }
        }
示例#21
0
    public void SetMenuAndRoleLInk()
    {
        string sMsg    = string.Empty;
        IList  lstMenu = new ArrayList();
        //IList lstMenuIDs = new ArrayList();
        IList      lstAuthConfig = new ArrayList();
        AuthRole   oRole         = GetSelectRole();
        string     sIDs          = string.Empty;
        AuthConfig oAuthConfig   = null;

        try
        {
            if (oRole != null)
            {
                lstMenu = GetCheckMenus();
                if (lstMenu != null)
                {
                    foreach (Menus oMenus in lstMenu)
                    {
                        oAuthConfig          = new AuthConfig();
                        oAuthConfig.IsHas    = true;
                        oAuthConfig.Roles    = oRole;
                        oAuthConfig.RoleName = oRole.RoleName;
                        oAuthConfig.Menus    = oMenus;
                        oAuthConfig.RoleName = oMenus.Name;
                        lstAuthConfig.Add(oAuthConfig);
                    }
                }
                AuthSvr.AuthConfigSrv.SaveAuthConfig(oRole.Id, lstAuthConfig);
                sMsg = "关联保存成功";
            }
            else
            {
                sMsg = "请选择角色节点";
            }
        }
        catch (Exception ex)
        {
            sMsg = "保存失败:" + ex.Message;
        }
        MessageBox(sMsg);
    }
示例#22
0
        public async Task <IActionResult> Post(string email, [FromBody] AuthRole authRole)
        {
            if (ModelState.IsValid)
            {
                var role = await _roleManager.FindByIdAsync(authRole.Id);

                if (role == null)
                {
                    return(null);
                }

                role.Name        = authRole.Name;
                role.Description = authRole.Description;
                await _roleManager.UpdateAsync(role);

                return(Created($"api/role/{authRole.Name}", authRole));
            }

            return(BadRequest(ModelState));
        }
示例#23
0
        protected override OpResult _Delete(AuthRole _obj)
        {
            RemoveRoleItem(_obj);
            RemoveRoleRole(_obj);

            DbDeleteStatement statement = DbMgr.CreateDeleteClause();

            statement.DeleteFrom("AuthRole").Criteria.IsEqual("AuthRole", "RoleID", _obj.RoleID);
            ExecuteNonQuery(statement);

            statement = DbMgr.CreateDeleteClause();
            statement.DeleteFrom("AuthRoleRole").Criteria.IsEqual("AuthRoleRole", "ChildRoleID", _obj.RoleID);
            ExecuteNonQuery(statement);

            statement = DbMgr.CreateDeleteClause();
            statement.DeleteFrom("AuthUser").Criteria.IsEqual("AuthUser", "RoleID", _obj.RoleID);
            ExecuteNonQuery(statement);

            return(OpResult.NotifyDeleteAction(OpResult.ResultStatus.ExistsAndDeleted, _obj));
        }
示例#24
0
        public async Task <ActionResult> EditingPopup_Update([DataSourceRequest] DataSourceRequest request, RoleEdit theRole)
        {
            if (theRole != null && ModelState.IsValid)
            {
                AuthRole newRole = await _roleManager.FindByIdAsync(theRole.Id);

                if (newRole == null)
                {
                    return(BadRequest());
                }

                newRole.Name        = theRole.Name;
                newRole.Description = theRole.Description;

                await _roleManager.UpdateAsync(newRole);

                return(Json(new[] { newRole }.ToDataSourceResult(request, ModelState)));
            }

            return(BadRequest());
        }
示例#25
0
        async public Task <ApiResult> _Add([FromForm] string Name, [FromForm] string Remark, [FromForm] string TenantId, [FromForm] DateTime CreateTime, [FromForm] DateTime UpdateTime, [FromForm] bool IsDeleted, [FromForm] int Sort, [FromForm] int[] mn_AdmRoutes_Id, [FromForm] int[] mn_Users_Id, [FromForm] int[] mn_OrgPosts_Id)
        {
            var item = new AuthRole();

            item.Name       = Name;
            item.Remark     = Remark;
            item.TenantId   = TenantId;
            item.CreateTime = CreateTime;
            item.UpdateTime = UpdateTime;
            item.IsDeleted  = IsDeleted;
            item.Sort       = Sort;
            using (var ctx = fsql.CreateDbContext())
            {
                await ctx.AddAsync(item);

                //关联 AdmRoute
                var mn_AdmRoutes = mn_AdmRoutes_Id.Select((mn, idx) => new AuthRole.AuthRoleAdmRoute {
                    AdmRouteId = mn, RoleId = item.Id
                }).ToArray();
                await ctx.AddRangeAsync(mn_AdmRoutes);

                //关联 AuthUser
                var mn_Users = mn_Users_Id.Select((mn, idx) => new AuthRole.AuthRoleUser {
                    UserId = mn, RoleId = item.Id
                }).ToArray();
                await ctx.AddRangeAsync(mn_Users);

                //关联 OrgPost
                var mn_OrgPosts = mn_OrgPosts_Id.Select((mn, idx) => new AuthRole.AuthRolePost {
                    OrgPostId = mn, RoleId = item.Id
                }).ToArray();
                await ctx.AddRangeAsync(mn_OrgPosts);

                await ctx.SaveChangesAsync();
            }
            return(ApiResult <object> .Success.SetData(item));
        }
示例#26
0
        public static Response <AuthRole> Get(this AuthRole request,
                                              Factory factory,
                                              IHttpRequest httpRequest)
        {
            return(factory.Execute(proxy => {
                long?totalCount = null;

                var paginador = new Paginador(httpRequest);

                var visitor = ReadExtensions.CreateExpression <AuthRole>();
                var predicate = PredicateBuilder.True <AuthRole>();

                if (!request.Name.IsNullOrEmpty())
                {
                    predicate = q => q.Name.Contains(request.Name);
                }


                visitor.Where(predicate);
                if (paginador.PageNumber.HasValue)
                {
                    visitor.Select(r => Sql.Count(r.Id));
                    totalCount = proxy.Count(visitor);
                    visitor.Select();
                    int rows = paginador.PageSize.HasValue? paginador.PageSize.Value:BL.ResponsePageSize;
                    visitor.Limit(paginador.PageNumber.Value * rows, rows);
                }


                return new Response <AuthRole>()
                {
                    Data = proxy.Get(visitor),
                    TotalCount = totalCount
                };
            }));
        }
示例#27
0
        public void DeleteAuthRole(AuthRole role)
        {
            if (!mAccountant.CanDeleteAuthRole(role))
            {
                if (MessageBox.Show(
                        "Other roles and users have inherited this role, delete this role will also delete them,\r\n do you still want to delete?",
                        "Delete Warning",
                        MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }
            else if (MessageBox.Show(
                         "Do you want to delete?",
                         "Delete Warning",
                         MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            BORole model = mAccountant.OpenAuthRole(role);

            model.Delete();
        }
 public IApiResultModel Edit(AuthRole authRole)
 {
     return(authRoleService.Edit(authRole));
 }
 public IApiResultModel Add(AuthRole authRole)
 {
     return(authRoleService.Add(authRole));
 }
 public static bool IsInRole(this IPrincipal user, AuthRole role)
 {
     return user.IsInRole(role.ToString());
 }
 public async Task AddAsync(AuthRole role)
 => await _dbContext.AuthRoles.AddAsync(role);