public async Task <ActionResult <dynamic> > login([FromBody] CttUser userData) { CttUser loggedUser = authService.login(userData.Email, userData.Pass); if (loggedUser == null) { return(BadRequest()); } var token = TokenService.GenerateToken(loggedUser); var userDTO = new //DTO Should be a proper DTO class... { Email = loggedUser.Email, FullName = loggedUser.FullName, BirthDate = loggedUser.BirthDate, Nif = loggedUser.Nif, CcNumber = loggedUser.CcNumber, Locality = loggedUser.Locality, Iban = loggedUser.Iban, Phone = loggedUser.Phone }; return(Ok(new { user = userDTO, token = token })); }
public CttUser registerUser(CttUser user) { dbContext.Add(user); dbContext.SaveChanges(); return(getUser(user.Email)); }
public IActionResult updateUserDetails([FromBody] CttUser user) { CttUser updatedUser = authService.updateUser(user); if (updatedUser == null) { return(BadRequest()); } return(Ok(updatedUser)); }
public IActionResult register([FromBody] CttUser user) { bool isEmailFree = authService.isEmailFree(user.Email); if (isEmailFree) { return(Ok(0)); //0 = No Error; } return(Ok(1)); //1 = Error; }
public CttUser updateUser(CttUser user) { bool isNull = user.GetType().GetProperties() .All(p => p.GetValue(user) != null); if (isNull) { return(null); } return(_authRepository.updateUser(user)); }
//string hashedPassword = hash(password); //_authRepository.registerNewEmail(email, hashedPassword); public CttUser registerUser(CttUser user) { CttUser persistedUser = _authRepository.getUser(user.Email); if (persistedUser != null) { return(null); } user.Pass = hash(user.Pass); return(_authRepository.registerUser(user)); }
public CttUser login(string email, string password) { CttUser user = _authRepository.getUser(email); bool isPassCorrect = false; if (user != null) { isPassCorrect = verify(password, user.Pass); } return(isPassCorrect ? user : null); }
public static string GenerateToken(CttUser user) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(Settings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Email, user.Email.ToString()), }), Expires = DateTime.UtcNow.AddHours(2), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); return(tokenHandler.WriteToken(token)); }
public IActionResult registerUserDetails([FromBody] CttUser user) { CttUser persistedUser = authService.registerUser(user); return(Ok(persistedUser)); }
public CttUser updateUser(CttUser user) { dbContext.Update(user); return(getUser(user.Email)); }
public bool isEmailFree(string email) { CttUser user = _authRepository.getUser(email); return(user == null); }