Exemple #1
0
 public IActionResult Post([FromBody] MedicalRepresentative representative)
 {
     if (representative == null)
     {
         logger.Error("NULL object received in " + nameof(AuthController));
         return(StatusCode(500));
     }
     if (string.IsNullOrEmpty(representative.Email) || string.IsNullOrEmpty(representative.Password))
     {
         logger.Info("Email or password is null");
         return(BadRequest("Email/Password cannot be null"));
     }
     try
     {
         if (provider.Validate(representative))
         {
             TokenGenerator generator = new TokenGenerator(Configuration);
             string         token     = generator.GenerateToken();
             logger.Info("Token received");
             return(Ok(token));
         }
         logger.Error("Unauthorized access");
         return(Unauthorized("Invalid Credentials"));
     }
     catch (Exception e)
     {
         logger.Error("Internal server error in " + nameof(AuthController) + "\n" + e.Message);
         return(StatusCode(500));
     }
 }
Exemple #2
0
        public void ValidateTestFail()
        {
            var mock = new Mock <IMedicalRepresentative>();

            mock.Setup(x => x.GetMedicalRepresentatives()).Returns(medicicalrep);
            MedicalRepresentativeProvider prov = new MedicalRepresentativeProvider(mock.Object);
            MedicalRepresentative         obj  = new MedicalRepresentative {
                Name = "Prithwiman", Email = "*****@*****.**", Password = "******"
            };
            bool res = prov.Validate(obj);

            Assert.AreEqual(false, res);
        }