Ejemplo n.º 1
0
        public async Task <ActionResult <ParticipantConnexionDto> > Login(ParticipantConnexionDto participantConnexionDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Participant participant = await _participant.GetParticipantByLoginAsync(participantConnexionDto.Login);

            if (participant == null)
            {
                return(BadRequest(new { message = "Wrong password or wrong mail" }));
            }

            string passwordHash = participant.Password;
            bool   verified     = BCrypt.Net.BCrypt.Verify(participantConnexionDto.Password, passwordHash);

            if (!verified)
            {
                return(BadRequest(new { message = "Wrong password or wrong mail" }));
            }


            var tokenJWT = GenerateJWToken(participant);

            return(Ok(new JwtSecurityTokenHandler().WriteToken(tokenJWT)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <QrCodeDto> > PostQrCode(QrCodeDto qrCodeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            // Get le login dans le token
            var    identity = HttpContext.User.Identity as ClaimsIdentity;
            string login    = identity.FindFirst("login").Value;

            // Requete db pour récupere l'id du login
            var participant = await _participantRepository.GetParticipantByLoginAsync(login);

            if (participant == null)
            {
                return(BadRequest(new { message = "No participant" }));
            }



            try
            {
                await _qrCodesRepository.CreateQrCodeAsync(qrCodeDto, participant.ParticipantID);
            } catch (DbUpdateException)
            {
                return(BadRequest(new { message = "The id already exist" }));
            }

            return(CreatedAtAction("GetQrCode", qrCodeDto));
        }