public async Task <IActionResult> LoginAsync(SecretDto dto) { var user = await _userApp.QueryFirst(p => p.Name == dto.UserName& p.Password == dto.Password); if (user == null) { return(Ok(new JwtResponseDto { Access = "用户不存在,无权访问", Type = "Bearer", err_code = 1, Data = new Profile { Name = dto.UserName, Auths = 0, Expires = 0 } })); } var jwt = _jwtApp.Create(user); return(Ok(new JwtResponseDto { Access = jwt.Token, Type = "Bearer", err_code = 0, Data = new Profile { Name = user.Name, Auths = jwt.Auths, Expires = jwt.Expires } })); }
public IActionResult LoginAsync([FromBody] SecretDto dto) { //获取用户信息 var user = _secretApp.GetCurrentUserAsync(dto.Account, dto.Password); if (user == null) { return(Ok(new JwtResponseDto { Access = "无权访问", Type = "Bearer", Profile = new Profile { Name = dto.Account, Auths = 0, Expires = 0 } })); } var jwt = _jwtApp.Create(user); return(Ok(new JwtResponseDto { Access = jwt.Token, Type = "Bearer", Profile = new Profile { Name = user.UserName, Auths = jwt.Auths, Expires = jwt.Expires } })); }
public JsonResult LoginAsync([FromBody] SecretDto dto) { //Todo:获取用户信息 //var user = new UserDto //{ // Id = Guid.NewGuid(), // UserName = "******", // Role = Guid.Empty, // Email = "*****@*****.**", // Phone = "13912345678", //}; var user = _loginApp.GetUserInfo(dto.UserName, dto.Password); if (user == null) { var datanull = new JwtResponseDto { Access = "无权访问", Type = "Bearer", Profile = new Profile { UserName = dto.UserName, Auths = 0, Expires = 0 } }; return(new JsonResult ( new { code = 20000, data = datanull } )); } var jwt = _jwtApp.Create(user); var data = new JwtResponseDto { Access = jwt.Token, Type = "Bearer", Profile = new Profile { RoleNames = user.RoleName, UserId = user.Id, UserName = user.UserName, Auths = jwt.AuthTime, Expires = jwt.ExpTime } }; return(new JsonResult (new { code = 20000, data })); }
public async Task <IActionResult> LoginAsync(SecretDto dto) { //Todo:获取用户信息 //var user = new UserDto //{ // Id = Guid.NewGuid(), // UserName = "******", // Role = Guid.Empty, // Email = "*****@*****.**", // Phone = "13912345678", //}; var user = await _secretApp.GetCurrentUserAsync(dto.UserName, dto.Password); if (user == null) { return(Ok(new JwtResponseDto { Access = "用户不存在,无权访问", Type = "Bearer", err_code = 1, Data = new Profile { Name = dto.UserName, Auths = 0, Expires = 0 } })); } var jwt = _jwtApp.Create(user); return(Ok(new JwtResponseDto { Access = jwt.Token, Type = "Bearer", err_code = 0, Data = new Profile { Name = user.UserName, Auths = jwt.Auths, Expires = jwt.Expires } })); }
public IActionResult Login([FromBody] SecretDto dto) { //Todo:获取用户信息 var user = new UserDto { Id = Guid.NewGuid(), UserName = "******", Role = Guid.Empty, Email = "*****@*****.**", Phone = "13912345678", }; if (user == null) { return(Ok(new JwtResponseDto { Access = "无权访问", Type = "Bearer", Profile = new Profile { Name = dto.Account, Auths = 0, Expires = 0 } })); } var jwt = _jwtApp.Create(user); return(Ok(new JwtResponseDto { Access = jwt.Token, Type = "Bearer", Profile = new Profile { Name = user.UserName, Auths = jwt.Auths, Expires = jwt.Expires } })); }
public IActionResult LoginSubmit(SecretDto dto) { //Todo:获取用户信息 var user = _homeBus.JwtSubmitLogin(dto.username, dto.password); if (user == null) { return(Ok( new AjaxResult { Success = false, Msg = "用户名或密码错误!", Data = new JwtResponseDto { Access = "用户名或密码错误!", Type = "Bearer", Profile = new Profile { UserName = dto.username, Auths = 0, Expires = 0 } }, ErrorCode = 0 })); } var jwt = _jwtApp.Create(user); #region 登录系统的操作记录单写,主要是登录系统时,Token还没有传递 //获取Ip地址的临时写法,这个写法不准确,没考虑代理 string ipAddress = HttpContextCore.Current.Connection.RemoteIpAddress.ToString(); Base_SysUserOperationLog sysUserOperationLog = new Base_SysUserOperationLog { Id = GuidHelper.GenerateKey(), LogType = EnumType.LogType.用户操作.ToString(), LogContent = $"[{DateTime.Now.ToCstTime().ToString("yyyy-MM-dd HH:mm:ss")}][{ipAddress}]地址的[" + user.RealName + "]用户操作记录:登录系统", OpTime = DateTime.Now.ToCstTime(), OpUserName = user.RealName }; Task.Run(() => { try { Base_SysUserOperationLogBusiness _base_SysUserOperationLogBusiness = new Base_SysUserOperationLogBusiness(); _base_SysUserOperationLogBusiness.Insert(sysUserOperationLog); } catch { } }); #endregion return(Ok( new AjaxResult { Success = true, Msg = "登录成功!", Data = new JwtResponseDto { Access = jwt.Token, Type = "Bearer", Profile = new Profile { UserId = user.UserId, UserName = user.UserName, RealName = user.RealName, Auths = jwt.Auths, Expires = jwt.Expires } }, ErrorCode = 0 })); }