1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<?php
namespace Bitweaver\Users;
use Bitweaver\HttpStatusCodes;
use Bitweaver\KernelTools;
use Bitweaver\Wiki\BitPage;
// Register the new user
$userClass = $gBitSystem->getConfig( 'user_class', 'RolePermUser' );
$newUser = new $userClass();
if( $newUser->preRegisterVerify( $pRegisterHash ) && $newUser->register( $pRegisterHash ) ) {
$gBitUser->mUserId = $newUser->mUserId;
if ( !empty( $_REQUEST['role'] ) ) {
$roleInfo = $gBitUser->getRoleInfo( $_REQUEST['group'] );
if ( empty($roleInfo) || $roleInfo['is_public'] != 'y' ) {
$errors[] = "You can't use this group";
$gBitSmarty->assign( 'errors', $errors );
} else {
$userId = $newUser->getUserId();
$gBitUser->addUserToRole( $userId, $_REQUEST['group'] );
$gBitUser->storeUserDefaultRole( $userId, $_REQUEST['group'] );
}
}
// set the user to private if necessary. defaults to public
if(!empty($_REQUEST['users_information']) && $_REQUEST['users_information'] == 'private'){
$newUser->storePreference('users_information','private');
}
// requires validation by email
if( $gBitSystem->isFeatureActive( 'users_validate_user' ) ) {
$gBitSmarty->assign('msg',KernelTools::tra('You will receive an email with information to login for the first time into this site'));
$gBitSmarty->assign('showmsg','y');
} else {
if( !empty( $_SESSION['loginfrom'] ) ) {
unset( $_SESSION['loginfrom'] );
}
// registration login, fake the cookie so the session gets updated properly.
if( empty($_COOKIE[$gBitUser->getSiteCookieName()] ) ) {
$_COOKIE[$gBitUser->getSiteCookieName()] = session_id();
}
// login with email since login is not technically required in the form, as it can be auto generated during store
$afterRegDefault = $newUser->login( $pRegisterHash['email'], $pRegisterHash['password'], false, false );
$url = $gBitSystem->getConfig( 'after_reg_url' )?BIT_ROOT_URI.$gBitSystem->getConfig( 'after_reg_url' ):$afterRegDefault;
// return to referring page
if( !empty( $_SESSION['returnto'] ) ) {
$url = $_SESSION['returnto'];
// forward to group post-registration page
} elseif ( !empty( $_REQUEST['group'] ) && !empty( $groupInfo['after_registration_page'] ) ) {
if ( $newUser->verifyId( $groupInfo['after_registration_page'] ) ) {
$url = BIT_ROOT_URI."index.php?content_id=".$groupInfo['after_registration_page'];
} elseif( strpos( $groupInfo['after_registration_page'], '/' ) === false ) {
$url = BitPage::getDisplayUrlFromHash( $groupInfo['after_registration_page'] );
} else {
$url = $groupInfo['after_registration_page'];
}
}
header( 'Location: '.$url );
exit;
}
} else {
$gBitSystem->setHttpStatus( HttpStatusCodes::HTTP_BAD_REQUEST );
$gBitSmarty->assign( 'errors', $newUser->mErrors );
}
|