For the AIRCO website, user profiles had to be auto-generated on admin approval, and a mail generated to the user.
The site was already running on a Joomla installation making use of the Community Builder suite, but some extra tweaking was needed to hook the site up to the member application backend.
The Process:
Potential member completes application form
Admin approves form
Profile is auto-generated and details are mailed to the member as follows:
1. Convert the member's name to a valid username (the member can always edit this if it isn't what they want)
$username = ereg_replace("", "", $name ); //convert to alphanumeric
$username = trim($username); // remove any unnecessary whitespace
$username = substr($username, 0, 24); //ensure the length of the username doesn't exceed 24 characters
2. Ensure that the email address used is unique (this is tested on initial registration, but we re-test to be safe)
$query = "SELECT * FROM jos_users WHERE email = '$email'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
if($check 0):
//flag as duplicate and exit
endif;
3. Check for duplicate username, and if one exists add a number on the end, retest and increment number until we get a unique value:
$n = 0;
$username_flag = '';
while($username_flag != 'set'):
$query = "SELECT * FROM jos_users WHERE username = '$username'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
$n++;
if($check 0):
$username = $username.$n;
else:
$username_flag = 'set';
endif;
endwhile;
4. Everything ok? Then we add the data:
a. Add
jos_users - name, username, email, password (remember to encrypt this with md5), usertype, gid, registerDate, params
jos_core_acl_aro - section_value = users, value = id of the record you inserted into jos_users, name = name of the member (as entered into jos_users)
jos_core_acl_groups_aro_map - group_id = id of the group your member belongs to, in my case 19 - Author, aro_id = id of the record you inserted into jos_core_acl_aro
jos_comprofiler id & user_id = id of the record you inserted into jos_users, then any other values captured for custom fields.
5. Finally email the member:
$to = $email;//captured from application form
$subject = "Your profile";
$body = "Dear ".$name."\n";
$body .= "You are now a full Member.\n\n";
$body .= "MEMBER'S AREA LOG-IN DETAILS\n";
$body .= "Username: ".$username."\n";
$body .= "Password: ".$password."\n\n";
$from = "FROM: ".$SENDERS_EMAIL_HERE;
mail($to, $subject, $body, $from);
No hay comentarios:
Publicar un comentario