Пример #1
0
        public async Task <IActionResult> LoginJwt(SimpleLogin loginInfo)
        {
            var userIdStr = HttpContext.User.Claims.Where(x => x.Type == AuthConstants.JwtClaimTypes.Subject).Select(x => x.Value).FirstOrDefault() ?? "";
            var rv        = await DC.Set <FrameworkUser>().Where(x => x.ITCode.ToLower() == loginInfo.Account.ToLower() && (x.Password == Utils.GetMD5String(loginInfo.Password) || x.ITCode.ToLower() == userIdStr.ToLower()) && x.IsValid).Select(x => new { itcode = x.ITCode, id = x.GetID() }).SingleOrDefaultAsync();

            if (rv == null)
            {
                ModelState.AddModelError(" ", Localizer["Sys.LoginFailed"]);
                return(BadRequest(ModelState.GetErrorJson()));
            }
            LoginUserInfo user = new LoginUserInfo
            {
                ITCode = rv.itcode,
                UserId = rv.id.ToString()
            };
            await user.LoadBasicInfoAsync(Wtm);

            //其他属性可以通过user.Attributes["aaa"] = "bbb"方式赋值

            Wtm.LoginUserInfo = user;
            if (loginInfo.IsReload == false)
            {
                var authService = HttpContext.RequestServices.GetService(typeof(ITokenService)) as ITokenService;

                var token = await authService.IssueTokenAsync(Wtm.LoginUserInfo);

                return(Content(JsonSerializer.Serialize(token), "application/json"));
            }
            else
            {
                return(Ok(user));
            }
        }
Пример #2
0
        public async Task <IActionResult> LoginJwt(SimpleLogin loginInfo)
        {
            var rv = await DC.Set <FrameworkUser>().Where(x => x.ITCode.ToLower() == loginInfo.Account.ToLower() && x.Password == Utils.GetMD5String(loginInfo.Password.ToLower())).Select(x => new { itcode = x.ITCode, id = x.ID }).SingleOrDefaultAsync();

            if (rv == null)
            {
                return(BadRequest(Localizer["Sys.LoginFailed"].Value));
            }
            LoginUserInfo user = new LoginUserInfo
            {
                ITCode = rv.itcode,
                UserId = rv.id.ToString()
            };
            await user.LoadBasicInfoAsync(Wtm);

            Wtm.LoginUserInfo = user;

            var authService = HttpContext.RequestServices.GetService(typeof(ITokenService)) as ITokenService;

            var token = await authService.IssueTokenAsync(Wtm.LoginUserInfo);

            return(Content(JsonSerializer.Serialize(token), "application/json"));
        }
Пример #3
0
        public async Task <IActionResult> LoginJwt(SimpleLogin loginInfo)
        {
            string code = await DC.Set <FrameworkUserBase>().Where(x => x.ITCode.ToLower() == loginInfo.Account.ToLower() && x.Password == Utils.GetMD5String(loginInfo.Password.ToLower())).Select(x => x.ITCode).SingleOrDefaultAsync();

            //如果没有找到则输出错误
            if (string.IsNullOrEmpty(code))
            {
                return(BadRequest(Localizer["Sys.LoginFailed"].Value));
            }
            LoginUserInfo user = new LoginUserInfo
            {
                ITCode = code
            };
            //读取角色,用户组,页面权限,数据权限等框架配置信息
            await user.LoadBasicInfoAsync(Wtm);

            Wtm.LoginUserInfo = user;

            var authService = HttpContext.RequestServices.GetService(typeof(ITokenService)) as ITokenService;

            var token = await authService.IssueTokenAsync(Wtm.LoginUserInfo);

            return(Content(JsonSerializer.Serialize(token), "application/json"));
        }