Beispiel #1
0
 public IActionResult AddUser(UserResource userResource)
 {
     try {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState.GetErrorMessages()));
         }
         else
         {
             var users = this.userRepo.FindByEmail(userResource.Email);
             if (users == null)
             {
                 Users user = mapper.Map <UserResource, Users>(userResource);
                 user.Password = EncryptionMD5.EncryptionByMD5(user.Password);
                 user.Email    = EncryptionMD5.EncryptionByMD5(userResource.Email);
                 var u = this.userRepo.AddUser(user);
                 return(Ok(new ApiResponse <Users> {
                     Status = true, Entry = u
                 }));
             }
             return(BadRequest(new ApiResponse <Users> {
                 Status = false, Entry = null
             }));
         }
     }
     catch (Exception ex) {
         logger.LogError(ex.Message);
         return(BadRequest(new ApiResponse <Users> {
             Status = false, Entry = null
         }));
     }
 }
Beispiel #2
0
 public IActionResult UserAuthenticate([FromBody] LoginResource user)
 {
     //Console.WriteLine("User name:{0}", user.Username);
     //Console.WriteLine("Password:{0}", user.Password);
     try {
         user.Email    = EncryptionMD5.EncryptionByMD5(user.Email);
         user.Password = EncryptionMD5.EncryptionByMD5(user.Password);
         var users = this._userRepo.FindByUserNameAndPassword(user.Email, user.Password);
         if (users != null)
         {
             var jwtToken = this._tokenHandler.GenerateJwtToken((users));
             return(Ok(new ApiResponse <JwtToken> {
                 Status = true, Entry = jwtToken
             }));
         }
         return(BadRequest(new ApiResponse <JwtToken> {
             Status = false, Entry = null
         }));
     }
     catch (Exception ex) {
         _logger.LogError(ex.Message);
         return(BadRequest(new ApiResponse <JwtToken> {
             Status = false, Entry = null
         }));
     }
     // if (IsValidUserAndPassword(user.UserName, user.Password))
     //    return new ObjectResult(GenerateToken(users));
     //return Unauthorized();
 }