Multiple UserSelfRegistrations?

rjett

Joined: 2005-12-11
Posts: 24
Posted: Mon, 2006-04-17 15:42

Hello,
I am looking for some assistance - I'm getting better at customizing Gallery2.1, but am not an expert, so please forgive any novice errors in nomenclature or technical questions and descriptions.

Is it possible to have multiple UserSelfRegistration files that could provide users to be assigned to different groups when registering. I have a form that calls posts to the module to create a new user. I'd like to have different forms that carry the group designation so that depending on where the new user comes from, they are assigned to the correct group.

My thought is that within the register module, there would be:
UserSelfRegistrationGroup1, UserSelfRegistrationGroup2, etc.
OR
If there was another Hidden Field - that the UserSelfRegistration module could identify the field and place it in the correct group.

Ultimately, I have a mySql database that is keeping user data - I'd like to be sure that the users are replicated in gallery2.1 in a correct group. Both DBs are on the same server for now and have root access. This issue is addressing at the creation of the new user in outside DB, where the user verifies the information they used to create the account, when they verify, the form creates the identical user in gallery.

Now I know I'm getting greedy, but I just saw that there is an "extra fields" option, can this go to "users" and be entered from the create user manner?

THANK YOU SO MUCH FOR THE ASSISTANCE - I'M HAVING A BLAST GETTING THIS THING GOING!
Gallery version = 2.1 core 1.1.0
PHP version = 5.0.4 apache2handler
Webserver = Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.8 PHP/5.0.4 DAV/2 mod_perl/2.0.1 Perl/v5.8.7
Database = mysql 4.1.13, lock.system=database
Toolkits = Exif, NetPBM, Thumbnail, Gd, ImageMagick
Acceleration = none, partial/900
Operating system = Linux 2.6.9-1.667 #1 Tue Nov 2 14:41:25 EST 2004 i686
Default theme = matrix
Locale = en_US
Browser = Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1

Here is a copy of the form posting to UserSelfRegistration as it is without changes from the core module:
<form action="http://www.photoguardian.com/gallery2/main.php" method="post" id="userAdminForm"
enctype="application/x-www-form-urlencoded">
<div>
<input type="hidden" name="g2_returnName" value=""/>
<input type="hidden" name="g2_return" value="http://www.photoguardian.com/gallery2/main.php?g2_view=core.UserAdmin&amp;g2_subView=register.UserSelfRegistration&amp;g2_itemId=7"/>
<input type="hidden" name="g2_formUrl" value="http://!URL!/gallery2/main.php?g2_view=core.UserAdmin&amp;g2_subView=register.UserSelfRegistration&amp;g2_itemId=7"/>
<input type="hidden" name="g2_controller" value="register.UserSelfRegistration"/>
<input type="hidden" name="g2_form[formName]" value="UserSelfRegistration"/>
</div>

<table width="600" align="center" cellpadding="0" cellspacing="5" bordercolor="#990000" bgcolor="#FFCC00">
<tr heighth="60">
<td height="33" bgcolor="#990000"><div align="center"><font color="#990000" size="4"><strong><font color="#FFFFFF">CONFIRM
YOUR INFORMATION</font></strong></font></div></td>
</tr>
<tr valign="top">
<td width="550" bgcolor="#FFCC00">

<input type="hidden" size="32" name="g2_form[userName]" value="!ID!"/>
<input type="hidden" size="32" name="g2_form[fullName]" value="!FNAME!"/>
<input type="hidden" size="32" name="g2_form[email]" value="!EMAIL!"/>
<input type="hidden" size="32" name="g2_form[password1]" value="!PASSWORD!"/>
<input type="hidden" size="32" name="g2_form[password2]" value="!PASSWORD!"/>
</div>
<div class="gbBlock gcBackground1">
<input type="submit" class="inputTypeSubmit"
name="g2_form[action][create]" value="Yes, Information is Correct - Complete Registration"/>
<input type="submit" class="inputTypeSubmit"
name="g2_form[action][cancel]" value="Cancel"/>
</div> </div>
</td>
</tr>

</table>
</form>

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2006-04-18 02:07

what is the "outside DB"? is your G2 embedded? if you register the user in another application and want a matching user in G2 then you can use the GalleryEmbed API and not use register module at all.
if you do want to use G2 register module then the idea with a hidden input sounds good to me.. check for it with GalleryUtilities::getRequestVariables in the View class, put the value (or some default if none given) into the $template data, add the hidden input in the form. the Controller can check that value passed in with $form data and assign the appropriate group.

 
rjett

Joined: 2005-12-11
Posts: 24
Posted: Tue, 2006-04-18 02:29

The "outside DB" is a mySql db for a affiliate application software (plexum) and unfortunately I haven't been able to figure out how to embed G2. Sorry to be so inept at the embedding issue. I'll work on the register module some more and see what I can do and get back to you soon. Are you saying that the form that sends the info should have the group info as hidden info or does the $template have the group and the form posts to a different template for each group? Finally, I think I'm close to my limit on my capabilities as I have no PHP experience and I'm cutting my teeth on it with G2. Plus, I know you guys work tirelessly at G2 and it's great - but are there "hired guns" out there that can custom program?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2006-04-18 14:31

There's a services forum here for such requests, don't know how many people out there fulfill such requests..
the hidden form input should be a code for which group to use, from a fixed list, rather than the actual group id (don't want people to figure it out and register themself as a site admin..). code on the server side can change the code (string/int whatever) into an actual group id, and use some default or throw an error if the code is unknown/invalid.

 
rjett

Joined: 2005-12-11
Posts: 24
Posted: Tue, 2006-04-18 19:40

Mindless - thanks again for the info - although I have a few questions:
1. I have the form hidden field issue figured out, I can place an meaningless value placed in a hidden field "$plan" with value="unknown". then in the UserSelfRegistration.tpl I can place: $g_id = ($plan == "unkown") ? "2" : "1"; /*"2" = Registered Users, "1"= Basic
Is there more to make $g_id into a field that g2 will accept or will that work?
2. What I don't understand is how to code the GalleryUtilities::getRequestVariables like you say and where. Do I have to call this somehow in the UserSelfRegistration.tpl?

 
rjett

Joined: 2005-12-11
Posts: 24
Posted: Tue, 2006-04-18 19:46

more... this is what confuses me on how to do it:
check for it with GalleryUtilities::getRequestVariables in the View class

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2006-04-19 02:50

form->controller doesn't need ::getRequestVariables.. if you used {g->formVar var="plan"} as the input name then you'll get the value in $form['plan'] in your controller.
I was suggesting that the link from your external page have something in the URL like g2_plan=1.. the View class in UserSelfRegistration can check for that value using $plan = GalleryUtilities::getRequestVariables('plan'); I was assuming you're not hardcoding the value for the hidden input in the form, but want to set it based on a query param in the register link.

 
rjett

Joined: 2005-12-11
Posts: 24
Posted: Wed, 2006-04-19 14:05

Mindless - thanks again - I think I'm catching on. So the url in the form would look like this:
<input type="hidden" name="g2_return" value="http://www.url/gallery2/main.php?g2_view=core.UserAdmin&amp;g2_subView=register.UserSelfRegistration&amp;g2_itemId=7&amp;g2_plan=1"/>
<input type="hidden" name="g2_formUrl" value="http://!URL!/gallery2/main.php?g2_view=core.UserAdmin&amp;g2_subView=register.UserSelfRegistration&amp;g2_itemId=7&amp;g2_plan=1"/>

I would then add the following to the UserSelfRegistration.tpl and save in a folder ("Local"):
<input type="text" size="5" name="{g->formVar var="plan"}" value="$form['plan']"/>

Then I would add the following to UserSelfRegistration.inc:
$plan = GalleryUtilities::getRequestVariable('plan');
/* then create an if/else statement providing parameters for converting the number from the url to an actual group id */
if ($plan == '1') {
$g_id = '10'; /* for purposes here - plan 1 = 10, plan 2 = 20, etc.. */
} else if ($plan == '2') {
$g_id = '20';
} else ($plan == '3') {
$g_id = '30';
}
}

Does that sound about right. I'm concerned about making changes to a file that shouldn't be messed with as I did that at one point thinking that I was smart and it blew everything up and I had to delete and reinstall modules.

 
rjett

Joined: 2005-12-11
Posts: 24
Posted: Wed, 2006-04-19 14:06

more...
would the UserSelfRegistration.inc need to go in a "local" folder?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2006-04-19 16:06

getting closer, still not quite what i tried to describe.
remember that UserSelfRegistration.inc has 2 classes.. the view (at the bottom) which is for displaying the page and the controller which handles the form submission. so the flow goes:
{link on external page} -> view -> render page with your <input type="hidden" name="{g->formVar var="plan"}" value="{$form.plan}"/> -> submit form -> controller checks for valid $form['plan'] value and picks $groupId value to use later.

above you used <input type="text" for 'plan'.. you want a user-enterable text input for this? i didn't think that was the intent. i thought your external page would have a link with main.php?g2_view=core.UserAdmin......g2_plan=1, the View in the inc file would do $form['plan'] = GalleryUtilities::getRequestVariables('plan');, the tpl would do the hidden input shown in the previous paragraph, the controller has the "if" block you show above, checking $form['plan']

"local" works only for tpl files and files that urls link directly to, link js and css. doesn't work for php code like php/inc/class files.

 
rjett

Joined: 2005-12-11
Posts: 24
Posted: Wed, 2006-04-19 18:09

Ok, I got a little mixed up...
My original intent was putting all of the required information in the outside form thus skipping the UserSelfRegistration.tpl page. My last post completely went against that. So let me ask a few more - again I apologize for being so lost.

1. I am now only working with UserSelfRegistration.inc and the outside form call "Add_User_test.htm" - is this correct or do I need to edit another?
2. If I need to edit a class file - how can i do it? I am working with Dreamweaver and won't let me open class files.
2. Call on the form is still:
<input type="hidden" name="g2_return" value="http://URL/gallery2/main.php?g2_view=core.UserAdmin&amp;g2_subView=register.UserSelfRegistration&amp;g2_itemId=7&amp;g2_plan=1"/>
<input type="hidden" name="g2_formUrl" value="http://!URL!/gallery2/main.php?g2_view=core.UserAdmin&amp;g2_subView=register.UserSelfRegistration&amp;g2_itemId=7&amp;g2_plan=1"/>
3. I have the <input type="text" size="5" name="{g->formVar var="plan"}" value="$form['plan']"/> placed in the outside form.
4. I have attached my UserSelfRegistrationTest.inc file so you can see how I added.

I hope I'm not way off.
Thanks
RJett

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2006-04-19 22:10

take another pass over my instructions.. try to understand views and controllers.

 
rjett

Joined: 2005-12-11
Posts: 24
Posted: Wed, 2006-04-19 22:13

Thanks Mindless - I will try - you hit the nail on the head - I don't understand views and controllers. Did I make any headway at all or am I heading in the wrong direction?

Does it need to be:
<input type="hidden" size="5" name="{g->formVar var="plan"}" value="1"/>
Sorry about that - was doing some copy/paste.