예제 #1
0
        public void ProcessRequest(HttpContext context)
        {
            UserInfo tUser = new UserInfo();

            tUser                 = bllUser.ConvertRequestToModel <UserInfo>(tUser);
            tUser.UserType        = 2;
            tUser.RegIP           = ZentCloud.Common.MySpider.GetClientIP();
            tUser.Regtime         = DateTime.Now;
            tUser.LoginTotalCount = 0;
            tUser.IsSubAccount    = "1";
            tUser.WebsiteOwner    = bllUser.WebsiteOwner;
            tUser.LastLoginDate   = DateTime.Now;
            if (string.IsNullOrWhiteSpace(tUser.UserID) || string.IsNullOrWhiteSpace(tUser.Password))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "账户和密码不能为空";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            if (!string.IsNullOrWhiteSpace(tUser.Phone) && !ZentCloud.Common.MyRegex.PhoneNumLogicJudge(tUser.Phone))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入正确的手机号码";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            if (!string.IsNullOrWhiteSpace(tUser.Phone3) && !ZentCloud.Common.MyRegex.PhoneNumLogicJudge(tUser.Phone3))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入正确的手机号码";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            UserInfo oUser = bllUser.GetUserInfo(tUser.UserID, bllUser.WebsiteOwner);

            if (oUser != null)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "账户名已存在";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            if (!string.IsNullOrWhiteSpace(tUser.Phone))
            {
                oUser = bllUser.GetUserInfoByPhone(tUser.Phone, bllUser.WebsiteOwner);
                if (oUser != null)
                {
                    apiResp.code = (int)APIErrCode.OperateFail;
                    apiResp.msg  = "联系手机,已有账号";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (!string.IsNullOrWhiteSpace(tUser.Email) && !ZentCloud.Common.MyRegex.EmailLogicJudge(tUser.Email))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入正确的邮箱地址";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            if (!tUser.PermissionGroupID.HasValue)
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请选择角色";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            ZentCloud.BLLPermission.Model.PermissionGroupInfo perGroup = bllUser.Get <ZentCloud.BLLPermission.Model.PermissionGroupInfo>(string.Format(" GroupID={0}", tUser.PermissionGroupID));
            if (perGroup.GroupType == 4)
            {
                tUser.DistributionOwner = bllUser.WebsiteOwner;
            }
            BLLTransaction tran = new BLLTransaction();

            if (!bllUser.Add(tUser, tran))
            {
                tran.Rollback();
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "添加用户出错";
                bllUser.ContextResponse(context, apiResp);
                return;
            }

            var group = new BLLPermission.Model.UserPmsGroupRelationInfo()
            {
                UserID  = tUser.UserID,
                GroupID = tUser.PermissionGroupID.Value
            };

            if (!bllUser.Add(group, tran))//添加权限组
            {
                tran.Rollback();
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "添加权限组出错";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            tran.Commit();
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.msg    = "添加完成";
            bllUser.ContextResponse(context, apiResp);
        }
예제 #2
0
파일: Update.ashx.cs 프로젝트: uvbs/mmp
        public void ProcessRequest(HttpContext context)
        {
            int      uid   = int.Parse(context.Request["AutoID"]);
            UserInfo tUser = bllUser.GetUserInfoByAutoID(uid);
            long     oPermissionGroupID = tUser.PermissionGroupID.HasValue ? tUser.PermissionGroupID.Value : 0;
            string   oPhone             = tUser.Phone;
            string   oEmail             = tUser.Email;

            tUser = bllUser.ConvertRequestToModel <UserInfo>(tUser);
            if (string.IsNullOrWhiteSpace(tUser.UserID) || string.IsNullOrWhiteSpace(tUser.Password))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "账户和密码不能为空";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            //if (!string.IsNullOrWhiteSpace(tUser.Phone) && !ZentCloud.Common.MyRegex.PhoneNumLogicJudge(tUser.Phone))
            //{
            //    apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
            //    apiResp.msg = "请输入正确的手机号码";
            //    bllUser.ContextResponse(context, apiResp);
            //    return;
            //}
            if (!string.IsNullOrWhiteSpace(tUser.Email) && !ZentCloud.Common.MyRegex.EmailLogicJudge(tUser.Email))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入正确的邮箱地址";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            if (!tUser.PermissionGroupID.HasValue)
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请选择角色";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            BLLTransaction tran = new BLLTransaction();

            if (!bllUser.Update(tUser, tran))
            {
                tran.Rollback();
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "编辑用户出错";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            if (oPermissionGroupID != tUser.PermissionGroupID.Value)
            {
                var ogroup = new BLLPermission.Model.UserPmsGroupRelationInfo()
                {
                    UserID  = tUser.UserID,
                    GroupID = oPermissionGroupID
                };
                if (bllUser.Delete(ogroup) < 0)//删除权限组
                {
                    tran.Rollback();
                    apiResp.code = (int)APIErrCode.OperateFail;
                    apiResp.msg  = "删除旧权限组出错";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                var group = new BLLPermission.Model.UserPmsGroupRelationInfo()
                {
                    UserID  = tUser.UserID,
                    GroupID = tUser.PermissionGroupID.Value
                };

                if (bllUser.GetCount <BLLPermission.Model.UserPmsGroupRelationInfo>(string.Format("UserID='{0}' And GroupID={1}", group.UserID, group.GroupID)) == 0)
                {
                    if (!bllUser.Add(group))//添加权限组
                    {
                        tran.Rollback();
                        apiResp.code = (int)APIErrCode.OperateFail;
                        apiResp.msg  = "添加权限组出错";
                        bllUser.ContextResponse(context, apiResp);
                        return;
                    }
                }
            }
            tran.Commit();
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.msg    = "修改完成";
            bllUser.ContextResponse(context, apiResp);
        }