Beispiel #1
0
        public async Task <ActionResult> LoginDeliveryMan(UserCredentialsForLoginDto credentials)
        {
            var user = await _userManager.FindByNameAsync(credentials.Email);

            if (user != null && await _userManager.CheckPasswordAsync(user, credentials.Password))
            {
                var deliveryMan = deliveryMenService.GetDeliveryManByIdentityId(user.Id);
                if (!deliveryMan.HasValidatedEmail)
                {
                    return(BadRequest(new
                    {
                        message = "Votre compte n'a pas encore été activé ! Vérifiez votre boite Emails."
                    }));
                }

                if (!deliveryMan.IsValidated)
                {
                    return(BadRequest(new
                    {
                        message = "Vous n'avez pas encore été accepté par l'administrateur !"
                    }));
                }

                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject = new ClaimsIdentity(new Claim[]
                    {
                        new Claim("UserID", user.Id.ToString())
                    }),
                    Expires            = DateTime.UtcNow.AddDays(365),
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_appSettings.JWT_Secret)), SecurityAlgorithms.HmacSha256Signature)
                };
                var tokenHandler  = new JwtSecurityTokenHandler();
                var securityToken = tokenHandler.CreateToken(tokenDescriptor);
                var token         = tokenHandler.WriteToken(securityToken);
                return(Ok(new { Token = token, Id = deliveryMan.Id }));
            }
            else
            {
                return(BadRequest(new { message = "Email ou mot de passe incorrect" }));
            }
        }
Beispiel #2
0
        public IActionResult ConfirmDeliveryManEmail(string userId, string code)
        {
            var deliveryMan = deliveryManService.GetDeliveryManByIdentityId(userId);

            if (!deliveryMan.HasValidatedEmail)
            {
                deliveryMan.HasValidatedEmail = true;
                deliveryManService.EditDeliveryMan(deliveryMan);

                return(View("ConfirmUserEmail"));
            }
            return(View("NotFound"));
        }