Beispiel #1
0
        /// <summary>
        /// 删除帐户(同时删除权限以及联盟和邮箱帐号等)
        /// </summary>
        /// <param name="accountID">用户ID</param>
        public void DeleteAccont(string accountID)
        {
            We7Helper.AssertNotNull(Assistant, "AccountHelper.Assistant");
            We7Helper.AssertNotNull(accountID, "DeleteAccont.accountID");

            //利用事务进行帐户的相关权限删除
            //IDatabase db = Assistant.GetDatabases()["We7.CMS.Common"];
            //IConnection ic = Assistant.GetConnections()[db];

            IConnection ic = Assistant.CreateConnetion(typeof(Account), true);//上边连接无效,此方法为重构方法

            //ic.IsTransaction = true;
            try
            {
                //删除Permissions
                Criteria c = new Criteria(CriteriaType.Equals, "OwnerID", accountID);
                Assistant.DeleteList <Permission>(ic, c);
                //删除AccountRole
                Criteria ca = new Criteria(CriteriaType.Equals, "AccountID", accountID);
                Assistant.DeleteList <AccountRole>(ic, ca);
                //最后删除当前帐户
                Account act = new Account();
                act.ID = accountID;
                Assistant.Delete(ic, act);
                OnUserDeleted(act);
                ic.Commit();
            }
            catch (Exception)
            {
                try { ic.Rollback(); }
                catch (Exception)
                { }
            }
            finally { ic.Dispose(); }
        }
Beispiel #2
0
        /// <summary>
        /// 获取一个用户
        /// </summary>
        /// <param name="accountID">用户ID</param>
        /// <param name="fields">返回的字段集合</param>
        /// <returns>用户对象</returns>
        public Account GetAccount(string accountID, string[] fields)
        {
            if (accountID == We7Helper.EmptyGUID)
            {
                Account sa = new Account();
                sa.ID        = accountID;
                sa.LastName  = "系统管理员";
                sa.LoginName = SiteConfigs.GetConfig().AdministratorName;
                return(sa);
            }
            else if (!string.IsNullOrEmpty(accountID))
            {
                We7Helper.AssertNotNull(accountID, "GetAccount.accountID");
                Criteria       c   = new Criteria(CriteriaType.Equals, "ID", accountID);
                List <Account> act = Assistant.List <Account>(c, null, 0, 1, fields);
                if (act.Count > 0)
                {
                    return(act[0]);
                }
            }

            Account a = new Account();

            a.ID        = accountID;
            a.LoginName = "";
            a.LastName  = "未知用户";
            return(a);
        }
Beispiel #3
0
 public void Initialize()
 {
     We7Helper.AssertNotNull(Assistant, "HelperFactory.Assistant");
     helpers.Clear();
     RemoveAllAssemblyGatherEvent();
     Load();
     IsInitialized = true;
 }
Beispiel #4
0
        /// <summary>
        /// 删除角色(同时删除权限)
        /// </summary>
        /// <param name="roleID">角色ID</param>
        public void DeleteRole(string roleID)
        {
            We7Helper.AssertNotNull(Assistant, "AccountHelper.Assistant");
            We7Helper.AssertNotNull(roleID, "DeleteRole.roleID");

            //利用事务进行帐户的相关权限删除
            IDatabase db = Assistant.GetDatabases()["We7.CMS.Common"];
            //IConnection ic = Assistant.GetConnections()[db];请注意别用此获去IC
            IConnection ic = db.DbDriver.CreateConnection(db.ConnectionString);

            ic.IsTransaction = true;

            try
            {
                //删除Permissions
                Criteria c = new Criteria(CriteriaType.Equals, "OwnerID", roleID);
                try
                {
                    Assistant.DeleteList <Permission>(ic, c);
                }
                catch (Exception)
                {
                }

                //删除AccountRole
                Criteria cr = new Criteria(CriteriaType.Equals, "RoleID", roleID);
                try
                {
                    Assistant.DeleteList <AccountRole>(ic, cr);
                }
                catch (Exception)
                {
                }

                //最后删除当前角色
                Role r = new Role();
                r.ID = roleID;
                Assistant.Delete(ic, r);

                ic.Commit();
            }
            catch (Exception ex)
            {
                ic.Rollback();
                throw ex;
            }
            finally { ic.Dispose(); }
        }
Beispiel #5
0
        /// <summary>
        /// 通过key获取站点配置的Value
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        string gettempsys(string key)
        {
            We7Helper.AssertNotNull(Assistant, "BaseHelper.Assistant");
            We7Helper.AssertNotNull(key, "BaseHelper.GetSystemParameter.key");

            Criteria           c    = new Criteria(CriteriaType.Equals, "ID", key);
            List <SiteSetting> sets = Assistant.List <SiteSetting>(c, null, 0, 1, new string[] { "ID", "Title", "Value", "SequenceIndex" });

            if (sets.Count > 0)
            {
                return(sets[0].Value);
            }
            else
            {
                return("");
            }
        }
Beispiel #6
0
        /// <summary>
        /// 删除帐户(同时删除权限以及联盟和邮箱帐号等)
        /// </summary>
        /// <param name="ic">连接</param>
        /// <param name="accountID">用户ID</param>
        public void DeleteAccont(IConnection ic, string accountID)
        {
            We7Helper.AssertNotNull(Assistant, "AccountHelper.Assistant");
            We7Helper.AssertNotNull(accountID, "DeleteAccont.accountID");

            //利用事务进行帐户的相关权限删除
            try
            {
                //删除Permissions
                Criteria c = new Criteria(CriteriaType.Equals, "OwnerID", accountID);
                try
                {
                    Assistant.DeleteList <Permission>(ic, c);
                }
                catch (Exception)
                {
                }

                //删除AccountRole
                Criteria ca = new Criteria(CriteriaType.Equals, "AccountID", accountID);
                try
                {
                    Assistant.DeleteList <AccountRole>(ic, ca);
                }
                catch (Exception)
                {
                }

                //最后删除当前帐户
                Account act = new Account();
                act.ID = accountID;
                Assistant.Delete(ic, act);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #7
0
        protected void Initialize()
        {
            ResetPasswordCheckBox.Checked = false;
            ResetPasswordSpan.Visible     = false;
            if (We7Helper.IsEmptyID(Security.CurrentAccountID))
            {
                UserTypeDropDownList.Items.Add(new ListItem("管理员", "0"));
            }
            UserTypeDropDownList.Items.Add(new ListItem("普通用户", "1"));

            if (We7Helper.IsEmptyID(CurrentAccountID))//新建
            {
                PassWordText.Visible = true;
                We7Helper.AssertNotNull(DepartmentID, "AccountDetail.p");
                if (!We7Helper.IsEmptyID(DepartmentID))
                {
                    Department dpt = AccountHelper.GetDepartment(DepartmentID, new string[] { "FullName" });
                    FullPathLabel.Text = dpt.FullName;
                    ParentTextBox.Text = DepartmentID;
                }
                else
                {
                    ParentTextBox.Text = We7Helper.EmptyGUID;
                }
                MailMessageTemplate mt = new MailMessageTemplate("UserEmailConfig.xml", "新建用户通知");
                MailBodyTextBox.Text = mt.Body;
                SaveButton.Value     = "创建账户";
                DeleteButtun.Visible = false;
            }
            else
            {
                ShowAccount(AccountHelper.GetAccount(CurrentAccountID, null));
                ResetPasswordSpan.Visible = true;
                MailMessageTemplate mt = new MailMessageTemplate("UserEmailConfig.xml", "账号审核通过通知");
                MailBodyTextBox.Text = mt.Body;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 添加一个用户
        /// </summary>
        /// <param name="act">用户对象</param>
        /// <returns>用户对象</returns>
        public Account AddAccount(Account act)
        {
            if (act.LoginName.Length < 3)
            {
                throw new Exception("用户名不能小于3位。");
            }

            if (act.Password.Length < 6)
            {
                throw new Exception("密码不能小于6位。");
            }

            if (GetAccountByLoginName(act.LoginName) != null)
            {
                throw new Exception(string.Format("登录名 {0} 已存在。", act.LoginName));
            }

            if (GetAccountByEmail(act.Email) != null)
            {
                throw new Exception(string.Format("邮件地址 {0} 已被使用。", act.Email));
            }

            We7Helper.AssertNotNull(Assistant, "AccountHelper.Assistant");
            We7Helper.AssertNotNull(act, "AddAccount.act");

            //利用事务进行帐户的相关权限删除
            //IDatabase db = Assistant.GetDatabases()["We7.CMS.Common"];
            //IConnection ic = Assistant.GetConnections()[db];
            //ic.IsTransaction = true;
            IConnection ic = Assistant.CreateConnetion(typeof(Account), true);//上边连接无效,此方法为重构方法

            try
            {
                act.ID      = We7Helper.CreateNewID();
                act.Created = DateTime.Now;
                if (GeneralConfigs.GetConfig().UserRegisterMode == "none")
                {
                    act.State = 1;
                }

                AccountRole ar = new AccountRole();
                ar.AccountID = act.ID;
                ar.RoleID    = "1";
                ar.RoleTitle = "注册用户";
                ar.ID        = We7Helper.CreateNewID();

                OnUserAdded(act);
                UpdateUserPassword(act);

                Assistant.Insert(ic, act, null);
                Assistant.Insert(ic, ar, null);

                ic.Commit();
                ic.Dispose();
                return(act);
            }
            catch (Exception ex)
            {
                ic.Rollback();
                ic.Dispose();
                throw ex;
            }
        }
Beispiel #9
0
 /// <summary>
 /// 初始化:加载dll中实体对象,对象字典清空
 /// </summary>
 public void Initialize()
 {
     We7Helper.AssertNotNull(Assistant, "HelperFactory.Assistant");
     helpers.Clear();
     Load();
 }