コード例 #1
0
ファイル: UserMasterController.cs プロジェクト: TimRowe/Rdp
        public string Add(OperateUserMasterModel addModel)
        {
            if (!ModelState.IsValid)
            {
                return(JSONHelper.ToJsonSuggest(ResSuggest.OperateFail + ResMessage.WrongFormat));
            }

            if (_userMasterService.GetCachedModel(addModel.UserID) != null)
            {
                return(JSONHelper.ToJsonSuggest(ResUserMaster.UserIDExist));
            }

            var userMasterModel = new UserMaster();
            var roleUserModel   = new RoleUser();
            var host            = "crm3.chowtaifook.sz";

            if (addModel.UserIDTemplate != "0" && addModel.UserIDTemplate != "")
            {
                var templateRoleUserModel = _roleUserService.GetCachedModel(t => t.UserID == addModel.UserIDTemplate);
                host = _userSiteService.GetUserSite(addModel.UserIDTemplate);   //获取服务器域名

                if (templateRoleUserModel == null)
                {
                    return(JSONHelper.ToJsonSuggest(ResUserMaster.EquelPrivilegeUserID + ResMessage.NotExist));
                }
                else
                {
                    roleUserModel.RoleID = templateRoleUserModel.RoleID;
                }
            }
            else if (string.IsNullOrEmpty(addModel.RoleID))
            {
                roleUserModel.RoleID    = short.Parse(addModel.RoleID);
                addModel.UserIDTemplate = _roleUserService.GetCachedModel(t => t.RoleID == short.Parse(addModel.RoleID)).UserID;
                host = _userSiteService.GetUserSite(addModel.UserIDTemplate);
            }
            else
            {
                return(JSONHelper.ToJsonSuggest(ResUserMaster.PlearsEnterEquelPrivilegeUserIDOrRoleID));
            }

            var randomCode = new RandomCode();

            addModel.Password = randomCode.GetRandomCode("1,2,3,4,5,6,7,8,9", 4) + randomCode.GetRandomCode("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", 4);

            userMasterModel = Mapper.Map <OperateUserMasterModel, UserMaster>(addModel);
            //userMasterModel.PasswordExprityDate = DateAndTime.DateAdd("d", 90, DateTime.Now.ToShortDateString());

            userMasterModel.PasswordExprityDate = DateTime.Now.AddDays(90);

            roleUserModel.UserID = addModel.UserID;

            var context       = ResUserMaster.LoginAddress + "http://" + host + "/Login.aspx " + ResUserMaster.UserID + ":" + userMasterModel.UserID + " " + ResUserMaster.Password + ":" + addModel.Password;
            var bllUserMaster = new UserMasterService();

            if (bllUserMaster.AddUserTemplate(userMasterModel, roleUserModel, addModel.UserIDTemplate, "ctfsystem", addModel.EmailAdd, ResUserMaster.COUPriviligeOpen, context, "HTML"))
            {
                return(JSONHelper.ToJsonSuggest(ResSuggest.AddSuccess));
            }
            else
            {
                return(JSONHelper.ToJsonSuggest(ResSuggest.AddFail));
            }
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: TimRowe/Rdp
        public JsonResult Login(LoginInfoModel loginInfo)
        {
            loginInfo.SiteUrl = Request.Host.ToString();
            UserMaster userMaster;

            //用户密码登陆
            if (loginInfo.Ip == null)
            {
                userMaster = _userMasterService.GetModel(p => p.UserID == loginInfo.UserId);

                if (userMaster == null)
                {
                    return(Json(new ResultInfo()
                    {
                        ErrorNo = -1, ErrorMsg = ResMessage.AccountNotExist
                    }));
                }

                if (userMaster.Password != DesEncrypt.Encrypt(loginInfo.Password))
                {
                    return(Json(new ResultInfo()
                    {
                        ErrorNo = -1, ErrorMsg = ResMessage.PasswordError + "<a href='javascript:void(0);' onclick='RetrievePassword();'>" + ResIndex.RetrievePassword + "</a>"
                    }));
                }
            }
            else
            {   //IP免登陆
                if (ViewBag.FromIpFreeLogin != true)
                {
                    var dt    = _userMasterService.Login(loginInfo.Ip);
                    var bFind = false;

                    foreach (DataRow row in dt.Rows)
                    {
                        if (row["User_ID"].ToString() == loginInfo.UserId)
                        {
                            bFind = true;
                        }
                    }

                    if (!bFind)
                    {
                        return(Json(new ResultInfo()
                        {
                            ErrorNo = -1, ErrorMsg = ResMessage.AccountInvaliable
                        }));
                    }
                }

                userMaster = _userMasterService.GetCachedModel(p => p.UserID == loginInfo.UserId);
                if (userMaster == null)
                {
                    return(Json(new ResultInfo()
                    {
                        ErrorNo = -1, ErrorMsg = ResMessage.AccountNotExist
                    }));
                }
            }
            //账户是否有效
            if (userMaster.StatusFlag != 0)
            {
                return(Json(new ResultInfo()
                {
                    ErrorNo = -1, ErrorMsg = ResMessage.AccountInvaliable
                }));
            }

            //网址是否有效
            var userSite = _userSiteService.GetModel(userMaster.UserID, loginInfo.SiteUrl);

            //if (userSite == null)
            //    return Json(new ResultInfo() { ErrorNo = -1, ErrorMsg = ResMessage.SiteTips });

            //密码是否过期
            if (userMaster.PasswordExprityDate < DateTime.Now)
            {
                return(Json(new ResultInfo()
                {
                    ErrorNo = -1, ErrorMsg = ResMessage.PasswordExpired + "<a href='javascript:void(0);' onclick='ModifyPassword();'>" + ResIndex.ModifyPassword + "</a>"
                }));
            }

            //清空旧缓存
            SessionManager.Logout();
            CookieManager.RemoveVersion();

            //加入角色和用户信息
            SessionManager.AddRoleUser(_roleUserService.GetCachedModel(p => p.UserID == loginInfo.UserId));
            SessionManager.AddUserMaster(userMaster);
            var domain = _domainService.GetModel(p => p.StatusFlag == 0);

            if (domain != null)
            {
                SessionManager.AddDomain(domain);
                CookieManager.AddVersion(domain.Version.ToString());
            }

            return(Json(new ResultInfo()
            {
                ErrorNo = 0, ErrorMsg = ""
            }));
        }