Beispiel #1
0
        //[Auth(FunctionKeys.User_ResetUserPassword)]
        public ActionResult ResetUserPassword()
        {
            string loginName = Request["data"];

            user_service.ResetSystemUserPasswordForAuthCenter(loginName, AuthMgr.EncryptPassword(loginName), CurrUser.UserSysNo, CurrUser.UserDisplayName);
            return(Json(new AjaxResult {
                Success = true, Message = "重置成功"
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Login()
        {
            string userName   = Request["UserName"];
            string userPwd    = Request["UserPwd"];
            string keepalive  = Request["keepalive"];
            string verifyCode = Request["VerifyCode"];

            if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(userPwd))
            {
                throw new BusinessException("请输入账号或密码");
            }
            if (string.IsNullOrWhiteSpace(verifyCode))
            {
                throw new BusinessException("请输入验证码");
            }

            string encrptedPassword = AuthMgr.EncryptPassword(userPwd);
            var    user             = AuthMgr.Login(userName, encrptedPassword, verifyCode, !string.IsNullOrEmpty(keepalive) && keepalive.ToLower() == "true");

            if (user != null)
            {
                if (user.ExData != null && !user.ExData.ToString().Equals("0"))
                {
                    var company = CompanyService.LoadCompany((int)user.ExData, false);
                    if (company == null || company.CompanyStatus != Entity.CompanyStatus.Authenticated)
                    {
                        AuthMgr.Logout();
                        throw new BusinessException("您所在的公司还未认证!");
                    }
                    if (company != null && company.AccountSysNo.HasValue && company.AccountSysNo.Value != user.UserSysNo)
                    {
                        AuthMgr.Logout();
                        throw new BusinessException("您没有权限登录此系统!");
                    }
                }
            }

            // SystemUserService systemUserServic = new SystemUserService();
            //  var loginUser= systemUserServic.LoadSystemUserBySysNo(user.UserSysNo, Entity.ConstValue.ApplicationID);
            //  if (loginUser != null)
            //  {

            // user.ExData = loginUser.MasterSysNo;
            //CookieHelper.SaveCookie<AuthUserModel>(LOGIN_COOKIE, user, 7 * 24 * 60);
            // }
            //}
            AjaxResult result = new AjaxResult
            {
                Success = true
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult ResetPwd(string loginname)
        {
            if (string.IsNullOrEmpty(loginname))
            {
                throw new BusinessException("未找到当前用户的相关信息");
            }
            var newpwd = AuthMgr.EncryptPassword(loginname);

            user_service.FindSystemUserPwd(loginname, newpwd, ConstValue.ApplicationID, CurrUser.MasterSysNo);
            return(Json(new AjaxResult {
                Success = true
            }));
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        public ActionResult SavePwd()
        {
            string OldPassword = Request["OldPassword"];
            string new1        = Request["new1"];
            string new2        = Request["new2"];

            if (new1 != new2)
            {
                throw new BusinessException("您输入的新密码与确认密码不匹配 ");
            }
            string            encrptedPassword  = AuthMgr.EncryptPassword(OldPassword);
            string            encrptednew1      = AuthMgr.EncryptPassword(new1);
            SystemUserService systemUserService = new SystemUserService();

            systemUserService.ResetSystemUserPassword(CurrUser.UserName, encrptedPassword, encrptednew1, AuthMgr.GetApplicationKey());
            //Rpc.Call<int>("AuthService.ResetSystemUserPassword", CurrUser.UserName, encrptedPassword, encrptednew1, AuthMgr.GetApplicationKey());
            AuthMgr.Logout();
            return(Json(new AjaxResult {
                Success = true, Message = "修改成功"
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #5
0
        public ActionResult SaveSystemUser()
        {
            string json = Request["data"];

            if (string.IsNullOrWhiteSpace(json))
            {
                throw new BusinessException("传入数据不能为空");
            }
            SystemUser user = JsonConvert.DeserializeObject <SystemUser>(json);

            user.Applications = new List <SystemApplication>()
            {
                new SystemApplication()
                {
                    ApplicationID = ConstValue.ApplicationID
                }
            };                                                                                                                         //默认招商系统
            user.EditUserSysNo = CurrUser.UserSysNo;
            user.EditUserName  = CurrUser.UserDisplayName;
            user.InDate        = DateTime.Now;
            if (user.SysNo > 0)
            {
                user.InUserSysNo = CurrUser.UserSysNo;
                user.InUserName  = CurrUser.UserDisplayName;
                user.InDate      = DateTime.Now;
                user_service.UpdateSystemUser(user);
            }
            else
            {
                user.CommonStatus  = CommonStatus.Actived;
                user.LoginPassword = AuthMgr.EncryptPassword(user.LoginName.Trim());
                user.InUserSysNo   = CurrUser.UserSysNo;
                user.InUserName    = CurrUser.UserDisplayName;
                user.SysNo         = user_service.InsertSystemUser(user);
            }

            return(Json(new AjaxResult {
                Success = true, Message = "保存成功", Data = user
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
 public JsonResult DoLogin(string account,string password,string keepalive)
 {
     string encrptedPassword = AuthMgr.EncryptPassword(password);
     AuthMgr.Login(account, encrptedPassword, "6666", !string.IsNullOrEmpty(keepalive) && keepalive.ToLower() == "true");
     return Json(new AjaxResult { Success = true, Message = "登录成功" }, JsonRequestBehavior.AllowGet);
 }
Beispiel #7
0
        /// <summary>
        /// 设为管理员 (注释掉)
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        //public ActionResult SetAdmin(int usersysno, int companysysno)
        //{
        //    AjaxResult result = new AjaxResult();
        //    if (usersysno <= 0 || companysysno <= 0)
        //    {
        //        throw new BusinessException("请选择正确的数据");
        //    }
        //    if (CurrUser.MasterSysNo.GetValueOrDefault() > 0)
        //    {
        //        companysysno = CurrUser.MasterSysNo.Value;
        //    }
        //    var company = CompanyService.LoadCompany(companysysno);
        //    if (company == null)
        //    {
        //        throw new BusinessException("未找到当前公司的相关信息");
        //    }
        //    var user = user_service.LoadSystemUser(usersysno);
        //    if (user == null)
        //    {
        //        throw new BusinessException("未找到当前用户的相关信息");
        //    }
        //    if (CurrUser.MasterSysNo.GetValueOrDefault() > 0 && user.MasterSysNo.Value != CurrUser.MasterSysNo.Value)
        //    {
        //        throw new BusinessException("未找到当前用户的相关信息");
        //    }
        //    if (user.CommonStatus == CommonStatus.DeActived)
        //    {
        //        throw new BusinessException("当前账号已被禁用,不能设为管理员");
        //    }
        //    company.AccountSysNo = usersysno;
        //    company.EditUserSysNo = CurrUser.UserSysNo;
        //    company.EditUserName = CurrUser.UserDisplayName;
        //    CompanyService.UpdateCompany(company);
        //    result.Success = true;
        //    return Json(result);
        //}

        public ActionResult SaveSystemUser(SystemUser user)
        {
            AjaxResult result = new AjaxResult();

            if (user == null || string.IsNullOrEmpty(user.LoginName))
            {
                throw new BusinessException("请输入正确的数据");
            }

            if (user.SysNo == 0)
            {
                if (string.IsNullOrEmpty(user.LoginPassword))
                {
                    user.LoginPassword = AuthMgr.EncryptPassword(user.LoginName);
                }
                else
                {
                    user.LoginPassword = AuthMgr.EncryptPassword(user.LoginPassword);
                }
                user.CellPhone = user.LoginName;
                SetEntityBaseUserInfo(user);
                if (CurrUser.MasterSysNo.GetValueOrDefault() > 0)
                {
                    user.MasterSysNo = CurrUser.MasterSysNo.Value;
                }
                var usersysno = user_service.InsertSystemUser(user);

                if (usersysno > 0)
                {
                    if (rolesysno != 0)
                    {
                        List <Role> roles = new List <Role> {
                            new Role
                            {
                                SysNo = rolesysno
                            }
                        };
                        usersrole.SaveUsersRole(usersysno, roles, ConstValue.ApplicationID);
                    }
                    result.Data    = usersysno;
                    result.Success = true;
                    return(Json(result));
                }
            }
            else
            {
                var userr = user_service.LoadSystemUser(user.SysNo);
                if (userr == null)
                {
                    throw new BusinessException("未找到当前用户的相关信息");
                }
                if (CurrUser.MasterSysNo.GetValueOrDefault() > 0 && CurrUser.MasterSysNo.Value != userr.MasterSysNo)
                {
                    throw new BusinessException("未找到当前用户的相关信息");
                }
                userr.UserFullName  = user.UserFullName;
                userr.CommonStatus  = user.CommonStatus;
                userr.EditUserSysNo = CurrUser.UserSysNo;
                userr.EditUserName  = CurrUser.UserDisplayName;
                user.EditDate       = DateTime.Now;
                user_service.UpdateSystemUser(userr);
                if (rolesysno > 0)
                {
                    var roles = usersrole.GetAllRolesByUserSysNo(userr.SysNo);
                    var role  = roles.Find(e => e.SysNo == rolesysno);
                    if (role == null)
                    {
                        roles.Add(new Role {
                            SysNo = rolesysno
                        });
                    }
                    usersrole.SaveUsersRole(userr.SysNo, roles, ConstValue.ApplicationID);
                }
                result.Data    = userr.SysNo;
                result.Success = true;
                return(Json(result));
            }

            result.Success = false;
            result.Message = "数据错误,请刷新后重试!";
            return(Json(result));
        }
Beispiel #8
0
        public ActionResult Save()
        {
            string json = Request["data"];

            if (string.IsNullOrWhiteSpace(json))
            {
                throw new BusinessException("传入数据不能为空");
            }
            Company entity = SerializationUtility.JsonDeserialize2 <Company>(json);

            SetEntityBaseUserInfo(entity);
            entity.CompanyStatus = CompanyStatus.Init;
            if (string.IsNullOrEmpty(entity.Name))
            {
                throw new BusinessException("请输入客户名称");
            }
            SystemUser customer = new SystemUser();

            //if (!string.IsNullOrEmpty(entity.ContactCellPhone))
            //{
            if (string.IsNullOrEmpty(entity.ContactName))
            {
                throw new BusinessException("请输入联系人姓名");
            }
            if (string.IsNullOrEmpty(entity.ContactCellPhone))
            {
                throw new BusinessException("请输入联系人手机号");
            }
            if (!WebPortalHelper.IsPhonenum(entity.ContactCellPhone))
            {
                throw new BusinessException("请输入正确的手机号!");
            }

            customer = SystemUserService.LoadSystemUserByLoginNameAndCellPhone(entity.ContactCellPhone, ConstValue.ApplicationID);
            // }

            Company company = CompanyService.LoadCompanyByName(entity.Name);

            if (entity.SysNo > 0)
            {
                Company curentcompany = CompanyService.LoadCompany(entity.SysNo, false);
                if (curentcompany == null)
                {
                    throw new BusinessException("未找到此公司的相关信息");
                }
                if (company != null && company.SysNo != curentcompany.SysNo)
                {
                    throw new BusinessException("系统中已存在当前客户,请重新输入客户名称!");
                }


                if (customer != null && customer.SysNo > 0 && ((!string.IsNullOrEmpty(entity.ContactCellPhone) && !string.Equals(customer.CellPhone, entity.ContactCellPhone)) || (entity.SysNo != customer.MasterSysNo)))
                {
                    throw new BusinessException("系统中已存在此手机号,请更换手机号重试!");
                }
                using (ITransaction it = TransactionManager.Create())
                {
                    //if (!string.IsNullOrEmpty(entity.ContactCellPhone))
                    //{
                    //    if (customer == null || !string.Equals(entity.ContactCellPhone, customer.CellPhone))
                    //    {
                    //        customer = new SystemUser();
                    //        customer.MasterSysNo = entity.SysNo;
                    //        customer.LoginName = customer.CellPhone = entity.ContactCellPhone;
                    //        customer.LoginPassword = AuthMgr.EncryptPassword(entity.ContactCellPhone);
                    //        customer.UserFullName = entity.ContactName;
                    //        customer.CommonStatus = CommonStatus.Actived;
                    //        SetEntityBaseUserInfo(customer);

                    //        var usersysno = user_service.InsertSystemUser(customer);
                    //        if (usersysno > 0)
                    //        {
                    //            if (rolesysno != 0)
                    //            {
                    //                List<Role> roles = new List<Role> { new Role { SysNo = rolesysno } };
                    //                usersrole.SaveUsersRole(usersysno, roles, ConstValue.ApplicationID);
                    //            }
                    //        }

                    //    }
                    //}
                    entity.CompanyStatus = curentcompany.CompanyStatus;
                    entity.AccountSysNo  = curentcompany.AccountSysNo;
                    if (curentcompany.CompanyStatus == CompanyStatus.Invalid)
                    {
                        entity.CompanyStatus = CompanyStatus.Init;
                    }
                    CompanyService.UpdateCompany(entity);
                    it.Complete();
                }
            }
            else
            {
                if (company != null)
                {
                    throw new BusinessException("系统中已存在当前客户,请重新输入客户名称!");
                }
                if (customer != null && customer.SysNo > 0)
                {
                    throw new BusinessException("系统中已存在此手机号,请更换手机号重试!");
                }
                if (!string.IsNullOrEmpty(entity.ContactCellPhone))
                {
                    customer               = new SystemUser();
                    customer.LoginName     = entity.LoginName;
                    customer.CellPhone     = "";
                    customer.LoginPassword = AuthMgr.EncryptPassword(entity.LoginName);
                    customer.UserFullName  = entity.ContactName;
                    customer.CommonStatus  = CommonStatus.Actived;
                    SetEntityBaseUserInfo(customer);
                }
                using (ITransaction it = TransactionManager.Create())
                {
                    entity.SysNo         = CompanyService.InsertCompany(entity);
                    customer.MasterSysNo = entity.SysNo;
                    if (!string.IsNullOrEmpty(entity.ContactCellPhone))
                    {
                        var usersysno = user_service.InsertSystemUser(customer);
                        if (usersysno > 0)
                        {
                            entity.AccountSysNo = usersysno;
                            CompanyService.UpdateCompany(entity);

                            if (rolesysno != 0)
                            {
                                List <Role> roles = new List <Role> {
                                    new Role {
                                        SysNo = rolesysno
                                    }
                                };
                                usersrole.SaveUsersRole(usersysno, roles, ConstValue.ApplicationID);
                            }
                        }
                    }
                    it.Complete();
                }
            }

            return(Json(new AjaxResult {
                Success = true, Message = "保存成功", Data = entity.SysNo
            }, JsonRequestBehavior.AllowGet));
        }