public ISignInResponse SignIn(SignInDto signInDto) { var user = ValidateSignIn(signInDto); user.LastLoginOn = _systemClock.GetCurrentTime(); user.LastUpdatedOn = _systemClock.GetCurrentTime(); var token = JwtHelper.GenerateJSONWebToken(_config, user); user.Token = Hash.Create(token, user.Salt); _repository.User.Update(user); _repository.Save(); var response = new SignInResponse { Id = user.Id, Token = token, CreationOn = user.CreationOn, LastLoginOn = user.LastLoginOn, LastUpdatedOn = user.LastUpdatedOn }; return(response); }
public ISignUpResponse SignUp(SignUpDto signUpDto) { ValidateSignUp(signUpDto); var salt = Salt.Create(); var user = new User { Name = signUpDto.Name, Email = signUpDto.Email, Salt = salt, Password = Hash.Create(signUpDto.Password, salt), Telephones = TelephoneMapper.MapToTelephone(signUpDto.Telephones), LastLoginOn = _systemClock.GetCurrentTime(), LastUpdatedOn = _systemClock.GetCurrentTime(), CreationOn = _systemClock.GetCurrentTime(), }; var token = JwtHelper.GenerateJSONWebToken(_config, user); user.Token = Hash.Create(token, salt); _repository.User.Create(user); _repository.Save(); var response = new SignUpResponse { Id = user.Id, Name = signUpDto.Name, Email = signUpDto.Email, Password = signUpDto.Password, Telephones = signUpDto.Telephones, Token = token, CreationOn = user.CreationOn, LastLoginOn = user.LastLoginOn, LastUpdatedOn = user.LastUpdatedOn }; return(response); }