User registration in API, cleanup of Users API handler

New API call in users:
`/api/users?action=register&username=matt&password=test`

Some general cleanup to reduce redundancy, and make it return immediately in error cases.