Exemplo n.º 1
0
        public IActionResult Login([FromBody] EgitmenDTO userDto)
        {
            var user = _userService.Authenticate(userDto.eMail, userDto.password);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_appSettings.Secret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, user.Id.ToString())
                }),
                Expires            = DateTime.UtcNow.AddDays(7),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token       = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);


            // return basic user info (without password) and token to store client side
            return(Ok(new
            {
                Id = user.Id,
                Username = user.Ad + user.SoyadAd,
                FirstName = user.Ad,
                LastName = user.SoyadAd,
                Token = tokenString
            }));
        }
Exemplo n.º 2
0
        public async Task <JsonResult> Sil([FromBody] EgitmenDTO egiDTO)
        {
            Egitmen egi = new Egitmen();

            egi = map.Map(egiDTO, egi);
            egiRep.Delete(egi);
            await egiRep.Commit();

            return(Json(egiDTO));
        }
Exemplo n.º 3
0
        public async Task <JsonResult> Ekle([FromBody] EgitmenDTO egiDTO)
        {
            Egitmen egi = new Egitmen();

            egi    = map.Map(egiDTO, egi);
            egi.Id = 0;
            egiRep.Add(egi);
            await egiRep.Commit();

            return(Json(egiDTO));
        }
Exemplo n.º 4
0
        public IActionResult Register([FromBody] EgitmenDTO userDto)
        {
            // map dto to entity
            Egitmen user = new Egitmen();

            user        = _mapper.Map <Egitmen>(userDto);
            user.IlceId = 1;


            // save
            _userService.Create(user, userDto.password);
            return(Ok(user));
        }