- sub (/action/register + %:username=&:password=&:confirm_password=&:name=&:email=&:phone=&:town=&:university=&:level=) {
- return reply 'Parameter too long' if grep { length > 200 } values %_;
- return reply 'Bad username. Allowed characters are letters, digits and underscores, and the username must be between 2 and 20 characters long.' unless $_{username} =~ USER_REGEX;
- return reply 'Username already in use' if db->user($_{username});
- return reply 'The two passwords do not match' unless $_{password} eq $_{confirm_password};
-
- db->users->create({id => $_{username}, name => $_{name}, email => $_{email}, phone => $_{phone}, town => $_{town}, university => $_{university}, level => $_{level}});
- db->user($_{username})->set_passphrase($_{password});
-
- purge '/us/';
- reply 'Registered successfully';
- },
-
- sub (/action/passwd + %:password=&:new_password=&:confirm_new_password=) {
- forbid !remote_user;
- return reply 'Incorrect password' unless remote_user->check_passphrase($_{password});
- return reply 'The two passwords do not match' unless $_{new_password} eq $_{confirm_new_password};
- remote_user->set_passphrase($_{new_password});
- reply 'Password changed successfully';
- },
-