예제 #1
0
        public async Task <ActionResult <IEnumerable <AcUserInfoDto> > > GetUserInfo()
        {
            var res  = new MessageModel <IEnumerable <AcUserInfoDto> >();
            var list = await _acUserInfoServices.GetEntitys().ToListAsync();

            res.Data = _mapper.Map <IEnumerable <AcUserInfoDto> >(list);
            return(Ok(res));
        }
예제 #2
0
        public async Task <ActionResult <ActionResult <MessageModel <string> > > > Login(LoginDto loginDto)
        {
            MessageModel <string>   res        = new MessageModel <string>();
            JwtSecurityTokenHandler jwtHandler = new JwtSecurityTokenHandler();
            AcUserInfo user = await _acUserInfoServices.GetEntitys(a => a.Pwd == loginDto.Pwd && a.Account == loginDto.Account).FirstOrDefaultAsync();

            if (user == null)
            {
                return(NotFound(StyleCode.NotFound(res)));
            }
            string token = jwtHandler.WriteToken(new JwtSecurityToken
                                                     (issuer: _configuration["Authentication:Issuer"],
                                                     audience: _configuration["Authentication:Audience"],
                                                     claims: new Claim[]
            {
                new Claim("id", user.Id.ToString()),
            },
                                                     expires: DateTime.Now.AddDays(7),
                                                     signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration["Authentication:SigningKey"])), SecurityAlgorithms.HmacSha256)
                                                     ));

            res.Data = "Bearer " + token;
            return(Ok(res));
        }