In California, you have to have a Handgun Safety Certificate before you can buy any handgun. The certificate is good for 5 years.
Basically, it is nothing more than a test on safe gun handling and storage requirements. Among other things, it enumerates the gun owner's legal responsibilities.
OK, that covers the certificate. At the time you pick up a handgun, you have to demonstrate that you can load and unload the weapon including, in the case of a semiauto, proving that the chamber is empty.
In theory, every new gun owner is fully aware of the functioning of a handgun, knows the requirements for storage and is fully aware of their legal responsibilities plus has demonstrated at least a minimal capability in safe gun handling.
All new handguns come with a locking device. For rifles and shotguns, you have to certify that you have a compliant gun safe or storage cabinet.
It's a start...
"No matter how cynical you become, it's never enough to keep up." - Lily Tomlin