//generate a token public string GenerateJwtToken(OutputDtoQueryUser user) { //on va chercher le "secret" qu'on a configurer dans appsettings.json var securityKey = Encoding.UTF8.GetBytes("WOOOOOaaawWWWWW cest Mr Palermo qui lit ce secret WWWWaaaaAaaaa"); //on récupère ce qu'on veut utiliser pour créer le token var claims = new Claim[] { new Claim(ClaimTypes.Email, user.Email), new Claim(ClaimTypes.Name, user.Name), new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()), new Claim(ClaimTypes.Role, user.Role) }; //on précise quel algorithme on doit utiliser var credentials = new SigningCredentials(new SymmetricSecurityKey(securityKey), SecurityAlgorithms.HmacSha256); //on crée le token en spécifiant l'émetteur, les valeurs à utiliser, la date d'expiration, l'agorithme var token = new JwtSecurityToken("FitnessBattle", "FitnessBattle", claims, expires: DateTime.Now.AddDays(7), signingCredentials: credentials); //on renvoie le token return(new JwtSecurityTokenHandler().WriteToken(token)); }
public void GetUserById_AreNotSame() { _userRepository.GetById(1).Returns(new User(1, "name", "password", "email", "user")); var res = _userService.GetUserById(1); OutputDtoQueryUser expected = new OutputDtoQueryUser("otherName", "password", "email", "user"); expected.Id = 1; Assert.AreNotEqual(res, expected); }
public void GetUserPointsById_AreSame() { var res = _userService.GetUserPointsById(1); OutputDtoQueryUser outputDtoQueryUser = new OutputDtoQueryUser("name", "password", "email", "user"); outputDtoQueryUser.Id = 1; double expected = outputDtoQueryUser.Points; Assert.AreEqual(res, expected); }
protected bool Equals(OutputDtoQueryUser other) { return(Id == other.Id && Name == other.Name && Password == other.Password && Email == other.Email && Role == other.Role && Points.Equals(other.Points)); }