Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Registers user
- $user = $modx->user;
- if ($user->get('id') == 0) {
- //New user, lets first do some checks to ensure that they have set a valid password
- $password = $hook->getValue('password');
- $password_confirm = $hook->getValue('password_confirm');
- //Nothing in password fields?
- if ($password == "" || $password_confirm == "") {
- $hook->addError('password','Please complete both password fields');
- return false;
- }
- //Do passwords match?
- if ($password != $password_confirm) {
- //Paswords don't match, error
- $hook->addError('password','Passwords do not match. Please try again');
- return false;
- }
- //Yes, they match, now, is it long enough?
- if (strlen($password) < 7) {
- //Pasword isn't log enough
- $hook->addError('password','Please create a password that is greater than 8.');
- return false;
- }
- //We have a valid password, now, lets build a user account.
- //Does this user already exist?
- $user = $modx->getObject('modUser', array ('username' => $hook->getValue('email')));
- if ($user) {
- //User exisits... error
- $hook->addError('personal', "We're sorry, " . $hook->getValue('email') . " has already been registered");
- return false;
- }
- $user = $modx->newObject('modUser', array ('username' => $hook->getValue('email')));
- $user->set('password', $password);
- $userProfile = $modx->newObject('modUserProfile');
- $userProfile->set('fullname', $hook->getValue('fname') . ' ' . $hook->getValue('lname'));
- $userProfile->set('email', $hook->getValue('email'));
- $userProfile->set('mobilephone', $hook->getValue('mobile'));
- $user->addOne($userProfile);
- if ($user->save() == false){
- $hook->addError('email','Sorry, this email address is already registered. If you own this account, please log in.');
- return false;
- }
- $user->joinGroup(1, 2); //GROUP Name,Group role
- $modx->runProcessor('security/login',
- array(
- 'login_context' => $modx->context->get('key'),
- 'add_contexts' => '',
- 'username' => $hook->getValue('email'),
- 'password' => $password,
- 'returnUrl' => null,
- 'rememberme' => true
- )
- );
- }
- //Return, send forward, redirect? Anything can go here.
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement