コード例 #1
0
ファイル: UserController.cs プロジェクト: war-man/YuebonCore
        public async Task <IActionResult> ModifyPassword(string oldpassword, string password, string password2)
        {
            CommonResult result = new CommonResult();

            try
            {
                if (string.IsNullOrEmpty(oldpassword))
                {
                    result.ErrMsg = "原密码不能为空!";
                }
                else if (string.IsNullOrEmpty(password))
                {
                    result.ErrMsg = "密码不能为空!";
                }
                else if (string.IsNullOrEmpty(password2))
                {
                    result.ErrMsg = "重复输入密码不能为空!";
                }
                else if (password == password2)
                {
                    var    userSinginEntity = userLogOnService.GetByUserId(CurrentUser.UserId);
                    string inputPassword    = MD5Util.GetMD5_32(DEncrypt.Encrypt(MD5Util.GetMD5_32(oldpassword).ToLower(), userSinginEntity.UserSecretkey).ToLower()).ToLower();
                    if (inputPassword != userSinginEntity.UserPassword)
                    {
                        result.ErrMsg = "原密码错误!";
                    }
                    else
                    {
                        string where = string.Format("UserId='{0}'", CurrentUser.UserId);
                        UserLogOn userLogOn = userLogOnService.GetWhere(where);

                        userLogOn.UserSecretkey      = MD5Util.GetMD5_16(GuidUtils.NewGuidFormatN()).ToLower();
                        userLogOn.UserPassword       = MD5Util.GetMD5_32(DEncrypt.Encrypt(MD5Util.GetMD5_32(password).ToLower(), userLogOn.UserSecretkey).ToLower()).ToLower();
                        userLogOn.ChangePasswordDate = DateTime.Now;
                        bool bl = await userLogOnService.UpdateAsync(userLogOn, userLogOn.Id);

                        if (bl)
                        {
                            result.ErrCode = ErrCode.successCode;
                        }
                        else
                        {
                            result.ErrMsg  = ErrCode.err43002;
                            result.ErrCode = "43002";
                        }
                    }
                }
                else
                {
                    result.ErrMsg = "两次输入的密码不一样";
                }
            }
            catch (Exception ex)
            {
                Log4NetHelper.Error("重置密码异常", ex);//错误记录
                result.ErrMsg = ex.Message;
            }
            return(ToJsonContent(result));
        }
コード例 #2
0
        public async Task <ActionResult> UpdateSelfPassWord(string id, string passWord, string newPassWord)
        {
            ContentResult contentResult = new ContentResult();
            //先验证旧密码是否正确 如果正确才能进行修改
            var user = await _userLogOnService.GetByUserId(id);

            //对密码进行加密 然后验证
            if (passWord == Encrypt.DecryptText(user.F_UserPassword, "dgq"))
            {
                user.F_UserPassword = Encrypt.EncryptText(newPassWord, "dgq");
                _userLogOnService.UpdatePassWord(user);
                contentResult.Content     = "ok";
                contentResult.StatusCode  = 200;
                contentResult.ContentType = "application/json";
            }
            else
            {
                contentResult.Content     = "原始密码错误!";
                contentResult.StatusCode  = 200;
                contentResult.ContentType = "application/json";
            }

            return(contentResult);
        }
コード例 #3
0
        public IActionResult GetUserInfo()
        {
            CommonResult      result            = new CommonResult();
            User              user              = _userService.Get(CurrentUser.UserId);
            YuebonCacheHelper yuebonCacheHelper = new YuebonCacheHelper();
            SystemType        systemType        = _systemTypeService.Get(CurrentUser.ActiveSystemId);
            YuebonCurrentUser currentSession    = new YuebonCurrentUser
            {
                UserId         = user.Id,
                Account        = user.Account,
                Name           = user.RealName,
                NickName       = user.NickName,
                AccessToken    = CurrentUser.AccessToken,
                AppKey         = CurrentUser.AppKey,
                CreateTime     = DateTime.Now,
                HeadIcon       = user.HeadIcon,
                Gender         = user.Gender,
                ReferralUserId = user.ReferralUserId,
                MemberGradeId  = user.MemberGradeId,
                Role           = _roleService.GetRoleEnCode(user.RoleId),
                MobilePhone    = user.MobilePhone,
                OrganizeId     = user.OrganizeId,
                DeptId         = user.DepartmentId,
                CurrentLoginIP = CurrentUser.CurrentLoginIP,
                IPAddressName  = CurrentUser.IPAddressName,
                TenantId       = ""
            };

            CurrentUser = currentSession;

            CurrentUser.ActiveSystemId  = systemType.Id;
            CurrentUser.ActiveSystem    = systemType.FullName;
            CurrentUser.ActiveSystemUrl = systemType.Url;

            List <MenuOutputDto> listFunction = new List <MenuOutputDto>();
            MenuApp menuApp = new MenuApp();

            if (Permission.IsAdmin(CurrentUser))
            {
                CurrentUser.SubSystemList = _systemTypeService.GetAllByIsNotDeleteAndEnabledMark().MapTo <SystemTypeOutputDto>();
                //取得用户可使用的授权功能信息,并存储在缓存中
                listFunction            = menuApp.GetFunctionsBySystem(CurrentUser.ActiveSystemId);
                CurrentUser.MenusRouter = menuApp.GetVueRouter("", systemType.EnCode);
            }
            else
            {
                CurrentUser.SubSystemList = _systemTypeService.GetSubSystemList(user.RoleId);
                //取得用户可使用的授权功能信息,并存储在缓存中
                listFunction            = menuApp.GetFunctionsByUser(user.Id, CurrentUser.ActiveSystemId);
                CurrentUser.MenusRouter = menuApp.GetVueRouter(user.RoleId, systemType.EnCode);
            }
            UserLogOn userLogOn = _userLogOnService.GetByUserId(CurrentUser.UserId);

            CurrentUser.UserTheme = userLogOn.Theme == null ? "default" : userLogOn.Theme;
            TimeSpan expiresSliding = DateTime.Now.AddMinutes(120) - DateTime.Now;

            yuebonCacheHelper.Add("User_Function_" + user.Id, listFunction, expiresSliding, true);
            List <string> listModules = new List <string>();

            foreach (MenuOutputDto item in listFunction)
            {
                listModules.Add(item.EnCode);
            }
            CurrentUser.Modules = listModules;
            yuebonCacheHelper.Add("login_user_" + user.Id, CurrentUser, expiresSliding, true);
            //该用户的数据权限
            List <String> roleDateList = _roleDataService.GetListDeptByRole(user.RoleId);

            yuebonCacheHelper.Add("User_RoleData_" + user.Id, roleDateList, expiresSliding, true);
            result.ResData = CurrentUser;
            result.ErrCode = ErrCode.successCode;
            result.Success = true;
            return(ToJsonContent(result, true));
        }