Example #1
0
        public IActionResult UpdatePassword([FromBody] UserCenterUpdatePasswordDto parm)
        {
            if (Convert.ToBoolean(AppSettings.Configuration["AppSettings:Demo"]))
            {
                ToResponse(StatusCodeType.Error, "当前为演示模式 , 您无权修改任何数据");
            }

            var userSession = _tokenManager.GetSessionInfo();

            var userInfo = _usersService.GetId(userSession.UserID);

            // 验证旧密码是否正确
            if (!PasswordUtil.ComparePasswords(userInfo.UserID, userInfo.Password, parm.CurrentPassword.Trim()))
            {
                return(ToResponse(StatusCodeType.Error, "旧密码输入不正确"));
            }

            // 更新用户密码
            var response = _usersService.Update(m => m.UserID == userInfo.UserID, m => new Sys_Users()
            {
                Password = PasswordUtil.CreateDbPassword(userInfo.UserID, parm.ConfirmPassword.Trim())
            });

            // 删除登录会话记录
            _tokenManager.RemoveAllSession(userInfo.UserID);

            return(ToResponse(response));
        }
Example #2
0
 public IActionResult Get(string id)
 {
     if (!string.IsNullOrEmpty(id))
     {
         return(toResponse(_usersService.GetId(id)));
     }
     return(toResponse(_usersService.GetAll()));
 }
Example #3
0
        /// <summary>
        /// 刷新用户所有Session信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public void RefreshSession(string userId)
        {
            if (!RedisServer.Session.Exists(userId))
            {
                return;
            }

            //取出 Session 列表所有 Key
            var keys = RedisServer.Session.HKeys(userId);

            if (keys.Length <= 0)
            {
                return;
            }

            var userInfo = _usersService.GetId(userId);

            foreach (var key in keys)
            {
                if (RedisServer.Session.Exists(key))
                {
                    //根据 Session 取出 UserInfo
                    var redisUserInfo = GetSessionItem <UserSessionVM>(key, "UserInfo");

                    //设置 Session 信息
                    var userSessionVM = new UserSessionVM()
                    {
                        UserID       = userInfo.UserID,
                        UserName     = userInfo.UserName,
                        NickName     = userInfo.NickName,
                        Email        = userInfo.Email,
                        Sex          = userInfo.Sex,
                        AvatarUrl    = userInfo.AvatarUrl,
                        QQ           = userInfo.QQ,
                        Phone        = userInfo.Phone,
                        ProvinceID   = userInfo.ProvinceID,
                        Province     = userInfo.Province,
                        CityID       = userInfo.CityID,
                        City         = userInfo.City,
                        CountyID     = userInfo.CountyID,
                        County       = userInfo.County,
                        Address      = userInfo.Address,
                        Remark       = userInfo.Remark,
                        IdentityCard = userInfo.IdentityCard,
                        Birthday     = userInfo.Birthday,
                        CreateTime   = userInfo.CreateTime,
                        Enabled      = userInfo.Enabled,
                        OneSession   = userInfo.OneSession,
                        Source       = redisUserInfo.Source,
                        KeepHours    = redisUserInfo.KeepHours,
                        UserPower    = _usersService.GetUserPowers(userInfo.UserID),
                        UserRelation = _usersService.GetUserRelation(userInfo.UserID),
                    };

                    RedisServer.Session.HSet(key, "UserInfo", userSessionVM);
                }
                else
                {
                    RedisServer.Session.HDel(userId, key);
                }
            }
        }