コード例 #1
0
        public async Task <IActionResult> GetlevelOC()
        {
            string token = Request.Headers["Authorization"];
            var    ocID  = Extensions.GetDecodeTokenByProperty(token, "LevelId").ToInt();

            return(Ok(await _levelService.GetlevelOC(ocID)));
        }
コード例 #2
0
ファイル: AuthController.cs プロジェクト: SyPham/kpi-vue
        public async Task <IActionResult> Login([FromBody] UserForLoginDto userForLoginDto)
        {
            var user = await _authService.FindByNameAsync(userForLoginDto.Username);

            var result = await _authService.Login(userForLoginDto.Username, userForLoginDto.Password);

            if (result == null)
            {
                return(Unauthorized());
            }
            var userprofile = new UserProfileDto()
            {
                User = new UserForReturnLogin
                {
                    Username = user.Username,
                    Role     = user.Role,
                    ID       = user.ID,
                    Alias    = user.Alias,
                    ListOCs  = await _levelService.GetListID(user.LevelID),
                    LevelOC  = await _levelService.GetlevelOC(user.LevelID),
                    IsActive = user.IsActive
                },
                Menus = JsonConvert.SerializeObject(await _authService.GetMenusAsync(user.Role))
            };
            await _hubContext.Clients.All.SendAsync("updateCount");

            return(Ok(new
            {
                token = GenerateJwtToken(new Models.ViewModels.Auth.UserLang
                {
                    ID = result.ID,
                    Username = result.Username,
                    Alias = result.Alias,
                    Permission = result.Permission,
                    LevelID = result.LevelID,
                    LevelOC = await _levelService.GetlevelOC(user.LevelID),
                    IsActive = result.IsActive,
                    Lang = "en"
                }),
                user = userprofile,
            }));
        }