public PensionCredentials GetPensioner(PensionCredentials cred) { List <PensionCredentials> rList = GetList(); PensionCredentials penCred = rList.FirstOrDefault(user => user.Username == cred.Username && user.Password == cred.Password); return(penCred); }
/// <summary> /// Finding User with matching credentials /// </summary> /// <param name="login"></param> /// <returns></returns> public PensionCredentials AuthenticateUser(PensionCredentials login) { _log4net.Info("Validating the User!"); //Validate the User Credentials PensionCredentials usr = repo.GetPensionerCred(login); return(usr); }
public PensionCredentials GetPensionerCred(PensionCredentials cred) { if (cred == null) { return(null); } PensionCredentials pensioner = provider.GetPensioner(cred); return(pensioner); }
public void GetPensioner_Returns_Null(string uname, string pass) { Mock <IPensionProvider> mock = new Mock <IPensionProvider>(); mock.Setup(p => p.GetList()).Returns(user); PensionProvider pro = new PensionProvider(); PensionCredentials cred = new PensionCredentials { Username = uname, Password = pass }; var penCred = pro.GetPensioner(cred); Assert.IsNull(penCred); }
public void GetPensionerCred_Returns_Object(string uname, string pass) { PensionCredentials cred = new PensionCredentials { Username = uname, Password = pass }; Mock <IPensionRepo> mock = new Mock <IPensionRepo>(); mock.Setup(p => p.GetPensionerCred(cred)).Returns(user[0]); //PensionProvider pro = new PensionProvider(); var penCred = mock.Object.GetPensionerCred(cred); Assert.IsNotNull(penCred); }
public string GenerateJSONWebToken(PensionCredentials userInfo) { _log4net.Info("Token Is Generated!"); var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"])); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken( issuer: _config["Jwt:Issuer"], audience: _config["Jwt:Issuer"], null, expires: DateTime.Now.AddMinutes(30), signingCredentials: credentials); return(new JwtSecurityTokenHandler().WriteToken(token)); }
public IActionResult Login([FromBody] PensionCredentials login) { AuthRepo auth_repo = new AuthRepo(_config, repo); _log4net.Info("Login initiated!"); IActionResult response = Unauthorized(); //login.FullName = "user1"; var user = auth_repo.AuthenticateUser(login); if (user == null) { return(NotFound()); } else { var tokenString = auth_repo.GenerateJSONWebToken(user); response = Ok(new { token = tokenString }); } return(response); }