-
Notifications
You must be signed in to change notification settings - Fork 4
npp_usr_create_account
Jurek Muszyński edited this page Mar 28, 2024
·
4 revisions
Creates user account. New user will have auth_level set to NPP_DEFAULT_USER_AUTH_LEVEL.
npp_usr_xxx functions directly read the query string / payload data.
Request must contain the following parameters:
If no NPP_USERS_BY_xxx compilation switch is present or NPP_USERS_BY_LOGIN is present:
- login (mandatory)
- email (optionally)
If NPP_USERS_BY_EMAIL compilation switch is present:
- email (mandatory)
and also mandatory:
- passwd (password)
- rpasswd (repeat password)
and optionally:
- name
- phone
- lang
- tz
- about
Create account form can contain hidden input named message to spoof robots. If it's not empty, the function will return ERR_ROBOT.
Returns OK or one of the error codes:
- ERR_INVALID_REQUEST
- ERR_WEBSITE_FIRST_LETTER
- ERR_USERNAME_TOO_SHORT
- ERR_USERNAME_CHARS
- ERR_USERNAME_TAKEN
- ERR_EMAIL_FORMAT_OR_EMPTY
- ERR_PASSWORD_TOO_SHORT
- ERR_PASSWORD_DIFFERENT
- ERR_ROBOT
- ERR_INT_SERVER_ERROR
void npp_app_main()
{
// ...
else if ( REQ("register") )
{
// show registration form with action="do_register"
render_register();
}
else if ( REQ("do_register") && REQ_POST )
{
ret = npp_usr_create_account();
if ( ret == OK )
RES_LOCATION("/login?msg=%d", MSG_WELCOME_NEED_ACTIVATION);
else
RES_LOCATION("/register?msg=%d", ret);
}
}
Requires NPP_USERS compilation switch.
Registration forms are often targeted by bots. See the more advanced example how to protect your application against them.