| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
require_once(dirname(dirname(__FILE__)).'/includes.php'); |
|---|
| 5 |
require_once($CFG->dirroot.'lib/lmslib.php'); |
|---|
| 6 |
$showform = false; |
|---|
| 7 |
$u = new StdClass; |
|---|
| 8 |
if (empty($USER->signingup)) { |
|---|
| 9 |
|
|---|
| 10 |
$alias = new StdClass; |
|---|
| 11 |
$alias->installid = optional_param('installid'); |
|---|
| 12 |
$alias->username = optional_param('username'); |
|---|
| 13 |
$alias->firstname = optional_param('firstname'); |
|---|
| 14 |
$alias->lastname = optional_param('lastname'); |
|---|
| 15 |
$alias->email = optional_param('email'); |
|---|
| 16 |
$signature = optional_param('signature'); |
|---|
| 17 |
|
|---|
| 18 |
$user = find_lms_user($alias->installid,$alias->username,$signature,'signupconfirmation',$alias->firstname,$alias->lastname,$alias->email); |
|---|
| 19 |
if (is_object($user)) { |
|---|
| 20 |
|
|---|
| 21 |
echo $user; |
|---|
| 22 |
|
|---|
| 23 |
} else if ($user != LMS_NO_SUCH_USER) { |
|---|
| 24 |
|
|---|
| 25 |
echo $user; |
|---|
| 26 |
|
|---|
| 27 |
} else { |
|---|
| 28 |
|
|---|
| 29 |
$showform = 1; |
|---|
| 30 |
$u->name = $alias->firstname.' '.$alias->lastname; |
|---|
| 31 |
$u->email = $alias->email; |
|---|
| 32 |
$USER->signingup = true; |
|---|
| 33 |
$USER->alias = $alias; |
|---|
| 34 |
} |
|---|
| 35 |
} else { |
|---|
| 36 |
|
|---|
| 37 |
$u->username = optional_param('username'); |
|---|
| 38 |
$u->password1 = optional_param('password1'); |
|---|
| 39 |
$u->password2 = optional_param('password2'); |
|---|
| 40 |
$u->email = optional_param('email'); |
|---|
| 41 |
$u->name = optional_param('name'); |
|---|
| 42 |
$mode = optional_param('mode'); |
|---|
| 43 |
|
|---|
| 44 |
$messages = array(); |
|---|
| 45 |
if ($mode == 'join') { |
|---|
| 46 |
|
|---|
| 47 |
if (!preg_match("/^[A-Za-z0-9]{3,12}$/",$u->username)) { |
|---|
| 48 |
$messages[] = __gettext("Error! Your username must contain letters and numbers only, cannot be blank, and must be between 3 and 12 characters in length."); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
if (record_exists('users','username',strtolower($u->username))) { |
|---|
| 52 |
$messages[] = __gettext("The username '$username' is already taken by another user. You will need to pick a different one."); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
if ($u->password1 != $u->password2 || strlen($u->password1) < 6 || strlen($u->password2) > 16) { |
|---|
| 56 |
$messages[] = __gettext("Error! Invalid password. Your passwords must match and be between 6 and 16 characters in length."); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
if (empty($u->name)) { |
|---|
| 60 |
$messages[] = __gettext("Error! You must enter your fullname"); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
if (empty($messages)) { |
|---|
| 64 |
|
|---|
| 65 |
$u->password = md5($u->password1); |
|---|
| 66 |
$ident = insert_record('users',$u); |
|---|
| 67 |
} |
|---|
| 68 |
} elseif ($mode == 'login') { |
|---|
| 69 |
$alias = $USER->alias; |
|---|
| 70 |
if (!authenticate_account($u->username, md5($u->password1))) { |
|---|
| 71 |
$messages[] = __gettext('Error! Your username and password does not match our record.'); |
|---|
| 72 |
} |
|---|
| 73 |
$USER->alias = $alias; |
|---|
| 74 |
$ident = $USER->ident; |
|---|
| 75 |
} elseif (!empty($mode)) { |
|---|
| 76 |
$messages[] = __gettext('Fatal Error! Unknown action requested.'); |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
if (empty($messages)) { |
|---|
| 80 |
$alias = $USER->alias; |
|---|
| 81 |
$alias->user_id = $ident; |
|---|
| 82 |
insert_record('users_alias',$alias); |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
if (!$comm = get_record_select('users','user_type = ? AND name = ?',array('community',$alias->installid))) { |
|---|
| 86 |
$comm = new StdClass; |
|---|
| 87 |
$comm->name = $alias->installid; |
|---|
| 88 |
$comm->username = $alias->installid; |
|---|
| 89 |
$comm->user_type = 'community'; |
|---|
| 90 |
$admin = get_admin(); |
|---|
| 91 |
$comm->owner = $admin->ident; |
|---|
| 92 |
$comm->ident = insert_record('users',$comm); |
|---|
| 93 |
} |
|---|
| 94 |
$f = new StdClass; |
|---|
| 95 |
$f->owner = $ident; |
|---|
| 96 |
$f->friend = $comm->ident; |
|---|
| 97 |
insert_record('friends',$f); |
|---|
| 98 |
$f->owner = $comm->ident; |
|---|
| 99 |
$f->friend = $ident; |
|---|
| 100 |
insert_record('friends',$f); |
|---|
| 101 |
|
|---|
| 102 |
unset($USER->signingup); |
|---|
| 103 |
unset($USER->alias); |
|---|
| 104 |
if ($mode == 'join') { |
|---|
| 105 |
$_SESSION['messages'][] = __gettext('Your account creation was successful!'); |
|---|
| 106 |
|
|---|
| 107 |
authenticate_account($u->username,$u->password); |
|---|
| 108 |
} |
|---|
| 109 |
redirect($CFG->wwwroot.$u->username); |
|---|
| 110 |
} |
|---|
| 111 |
$showform = true; |
|---|
| 112 |
} |
|---|
| 113 |
if (!empty($showform)) { |
|---|
| 114 |
define("context", "lmsjoin"); |
|---|
| 115 |
templates_page_setup(); |
|---|
| 116 |
|
|---|
| 117 |
$title = __gettext('Join up'); |
|---|
| 118 |
ob_start(); |
|---|
| 119 |
require_once($CFG->dirroot.'lms/join.html'); |
|---|
| 120 |
$body = ob_get_contents(); |
|---|
| 121 |
ob_end_clean(); |
|---|
| 122 |
|
|---|
| 123 |
$body = templates_draw( array( |
|---|
| 124 |
'context' => 'contentholder', |
|---|
| 125 |
'title' => $title, |
|---|
| 126 |
'body' => $body |
|---|
| 127 |
)); |
|---|
| 128 |
|
|---|
| 129 |
$title1 = __gettext('Login'); |
|---|
| 130 |
ob_start(); |
|---|
| 131 |
require_once($CFG->dirroot.'lms/login.html'); |
|---|
| 132 |
$body1 = ob_get_contents(); |
|---|
| 133 |
ob_end_clean(); |
|---|
| 134 |
|
|---|
| 135 |
$body .= templates_draw( array( |
|---|
| 136 |
'context' => 'contentholder', |
|---|
| 137 |
'title' => $title1, |
|---|
| 138 |
'body' => $body1 |
|---|
| 139 |
)); |
|---|
| 140 |
|
|---|
| 141 |
echo templates_page_draw(array($title, $body, ' ')); |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
?> |
|---|