예제 #1
0
        public async Task <ActionResult <UserModel> > Login([FromBody] JObject data)
        {
            var user = await _context.Users.FirstOrDefaultAsync(a => a.Login == data["login"].ToString());

            var password = _encrypter.EncryptData(data["password"].ToString());

            if (user != null && user.Password == password)
            {
                var token = await _tokenService.GetToken(user.Id);

                return(Ok(new
                {
                    name = user.Name,
                    secondname = user.Secondname,
                    token = new JwtSecurityTokenHandler().WriteToken(token),
                    expiration = token.ValidTo
                }));
            }
            return(Unauthorized());
        }