Example #1
0
        public async Task <IActionResult> Get(string account)
        {
            bool checkExistUser = await _systemManagementService.CheckExistUser(account);

            if (!checkExistUser)
            {
                return(NotFound());
            }
            var userFromService = await _authService.GetUser(account);

            var claims = new[]
            {
                new Claim(ClaimTypes.NameIdentifier, userFromService.USER_GUID.ToString()),
                new Claim(ClaimTypes.Name, userFromService.NAME)
            };

            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config.GetSection("AppSettings:Token").Value));

            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature);

            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(claims),
                Expires            = DateTime.Now.AddDays(1),
                SigningCredentials = creds
            };

            var tokenHandler = new JwtSecurityTokenHandler();

            var token = tokenHandler.CreateToken(tokenDescriptor);

            return(Ok(new
            {
                token = tokenHandler.WriteToken(token),
                user = userFromService
            }));
        }
Example #2
0
        public async Task <IActionResult> AddSystemRole(TB_EL_System_Role systemRole)
        {
            var checkExistUser = await _systemManagementService.CheckExistUser(systemRole.Account.Trim());

            if (!checkExistUser)
            {
                return(Ok(new { resultAdd = "notexistuser" }));
            }
            var checkDuplicateSystemRole = await _systemManagementService.CheckDuplicateSystemRole(systemRole.Account);

            if (checkDuplicateSystemRole)
            {
                return(Ok(new { resultAdd = "existsystemrole" }));
            }
            _systemManagementService.AddSystemRole(systemRole);
            if (await _systemManagementService.SaveAll())
            {
                return(Ok(new { resultAdd = "true" }));
            }
            else
            {
                return(Ok(new { resultAdd = "false" }));
            }
        }