/// <summary> /// 用户登陆,返回用户信息 /// </summary> /// <param name="qc"></param> /// <returns></returns> public ResponseResultBase GetToken(TokenGetPO qc) { var response = new ResponseResultBase(); var user = _userRepository.Find(x => x.Account == qc.Account && x.Password == qc.Password); if (user == null) { response.SetFailed("用户不存在", ErrorCode.Failed); return(response); } else if (user.IsDisabled) { response.SetFailed("账号已被禁用", ErrorCode.Failed); return(response); } var menuList = new List <string>(); var roleList = user.UserRoleList.Select(x => x.Role).ToList(); if (roleList != null && roleList.Count > 0) { menuList = roleList.SelectMany(x => x.RoleMenuList.Select(t => t.Menu.Url)).ToList(); } var claimsIdentity = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), new Claim("account", user.Account), new Claim(ClaimTypes.Name, user.Name), new Claim("isAdmin", user.IsAdmin.ToString()), new Claim("avatar", user.Avatar), new Claim("menus", JsonConvert.SerializeObject(menuList)) }); var token = this.GenerateToken(claimsIdentity); response.Data = token; return(response); }
public IActionResult Get([FromQuery] TokenGetPO qc) { var response = _tokenApp.GetToken(qc); return(Ok(response)); }