sakefox posted on 2009-03-25 01:34:56 #
Was bored and thought i would try to add a invite code system into access_user, but running in to a mind block.
What i am having a problem with is how to do the registration process so that if it's not set to invite only it will still accept the registration with or without a code and process the registration. Unfortunately i can't think of a way to process it without putting the same code in the same registration process.
I thought about putting a check into the validation function and fail there before processing the registration, but not sure if that would be the best solution.
I tried this, but it's just a simple pass/fail so doesn't really process anything unless its invite only. Just need something to push in the right direction...
function register_user($account, $password, $confirm, $email, $invite) {
if ($this->get_setting("register")) {
if ($this->get_setting("invite_only") && $this->validate_invite($invite, $email)) {
}else {
$this->the_msg = $this->messages(46);
}
}else {
$this->the_msg = $this->messages(44);
}
}
simple check of the code. I am going to rewrite this.
function validate_invite($code, $email) {
if (strlen($code) == 32) {
$inv_sql = sprintf("SELECT invite_code, sendto FROM %s WHERE invite_code = %s", $this->table_invitation, $code);
$inv_res = mysql_query($inv_sql);
$chk_code = mysql_result($inv_res, 0, "invite_code");
$chk_email = mysql_result($chk_email, 0, "sendto");
if (mysql_num_rows($inv_res) == 1) {
if ($chk_code == $code && $chk_email == $email) {
return true;
}else {
return false;
}
}else {
return false;
}
}else {
return false;
}
}
The most popular forum posts:
Comments / discussions
sakefox posted on 2009-03-25 04:24:46 #
i was playing with this and came out with adding another function, but not sure if its the best way to do thins. This is what i was thinking
add another var say var $reg_status = false
then the function
function reg($email, $code){
if($this->get_setting("invite_only") && $this->validate_invite($code, $email)){
//allow reg to process
$reg_status = true;
}else {
if(!this->get_setting("invite_only")){
//allow reg to process
$reg_status = true;
}else {
//reg is invite only and code invalid. fail registration
$reg_status = false;
}
and in the registration function have a pass fail check
function register_user($account, $password, $confirm, $email, $invite) {
if ($this->get_setting("register")) {
if($this->reg($email, $code){
//put reg code here
}else {
//fail here
$this->the_msg = $this->message(##);
}
}else {
$this->the_msg = $this->messages(44);
}
}
PS: I know i am not good at coding nor claim to...this is why i ask someone who is =P but i think i am in the right direction. am i?
Olaf posted on 2009-03-25 05:57:24 #
Hi,
I get your right that you want register users by yourself?
What is the process you like to use?
sakefox posted on 2009-03-25 06:27:46 #
it's using the already existing registration system in the access_user class. Just adding another field of the invite code. When the invite only option is turned on you would need to have a valid invitation code to be able to register. When the invite only option is off the invite code field would be a optional field while registering.
Just trying to find the best way and placement of the code to do this.
Olaf posted on 2009-03-25 06:32:29 #
How about do a registration (by admin) and sending some activation mail?
This way you can be sure that the email address is valid too
sakefox posted on 2009-03-25 08:21:43 #
that's already built in. a activation email is sent when someone registers so the email would have to be valid before they can activate there account.
The back reason i thought of doing a invitation addon was for if you wanted to do some beta testings on your site you could generate some invites and then only them people would be able to register for accounts since it would check the invite code to the email it was sent to, but also have the invite system always active and use it as a referral system as well. You could then using the same system give some kind of benefit to members inviting people in since it would all be part of the same system. I do plan on putting a config in so that you can easily limit how many invites one person can send and a few other things to it.
The more automated the system is the more time you can have for something else.
I just don't know if the way i am going about it is the best way to add this part of if there is a easier and better way to do it.
Olaf posted on 2009-03-26 21:11:19 #
If the invite code is always the same it's easy to validate (outside the class) otherwise you should store the registration code in the "information" field.
Create your custom function outside the main class and don't change the table structure (because of later updates)