Sorry for all these self replies. I have it narrowed down to the register 
form. I have all the other auth forms working properly.

My register form handling looks like this:

    if 'register' in request.args(0):
        # parse the referring URL to see if we can pre-populate the 
course_id field in
        # the registration form


        form.vars.course_id = '' # set it to be empty if we can't 
pre-populate
        ref = request.env.http_referer
        if ref:
            if '_next' in ref:
                ref = ref.split("_next")
                url_parts = ref[1].split("/")
            else:
                url_parts = ref.split("/")


            for i in range(len(url_parts)):
                if "static" in url_parts[i]:
                    course_id = url_parts[i+1]
                    form.vars.course_id = course_id
                break

I'm setting form.vars.course_id based on some application logic. However, I 
can't figure out how to get the pre-populated value to display. It seems 
like I should have a call to form.process() to actually populate the form 
widget(*), but if I put such a call in, the register form breaks: it adds 
an entry to auth_users, but includes a registration key, and the page does 
not redirect properly. (In other words, I get the "success" flash, but the 
browser stays on the registration page and the user is not automatically 
logged in.)

What exactly do I need to do to pre-populate a value in this registration 
form?

* I did exactly this to pre-populate some values in the user "profile" form 
and it worked perfectly.

On Thursday, June 27, 2013 8:43:32 AM UTC-5, Isaac Dontje Lindell wrote:
>
> def user(): 
>     form = auth()
>
>     if 'register' in request.args(0):
>         # parse the referring URL to see if we can prepopulate the 
> course_id field in
>         # the registration form
>         ref = request.env.http_referer
>         if ref:
>             if '_next' in ref:
>                 ref = ref.split("_next")
>                 url_parts = ref[1].split("/")
>             else:
>                 url_parts = ref.split("/")
>
>             for i in range(len(url_parts)):
>                 if "static" in url_parts[i]:
>                     course_id = url_parts[i+1]
>                     form.vars.course_id = course_id
>                 break
>
>         # we can't prepopulate, just set it to empty
>         else:
>             form.vars.course_id = ''
>
>
>     if 'login' in request.args(0):
>         # add info text re: using local auth. CSS styled to match text on 
> Janrain form
>         sign_in_text = TR(TD('Sign in with your RSI account', _colspan='3'
> ), _id='sign_in_text')
>         form[0][0].insert(0, sign_in_text)
>
>
>     if 'profile' in request.args(0):
>         form.vars.course_id = auth.user.course_name
>
>     try:
>         if form.process().accepted:
>             # auth.user session object doesn't automatically update when 
> the DB gets updated
>             auth.user.update(form.vars)
>             auth.user.course_name = db(db.auth_user.id == auth.user.id).
> select()[0].course_name
>
>             redirect(URL('default','index'))
>     except AttributeError:
>         # Janrain login form wrapped in the ExtendedLoginForm doesn't 
> have the process() method
>         # (which makes sense because we have no ability to process the 
> Janrain form)
>         pass
>
>
>     return dict(form=form)
>
> Above is the contents of my user controller. I have been trying to use the 
> ExtendedLoginForm to integrate Janrain (which works perfectly - I can 
> register/login with Janrain without a problem. However, I still can't get 
> local registration working. I've actually switched back to just using the 
> local Auth form right now for testing but am still getting the wrong 
> behavior.
>
> If I remove all the code from the user controller except the lines  
>     form = auth()
>     return dict(form=form)
> everything works as expected. Obviously this indicates a problem with my 
> code, I'm just not sure what exactly. What I'm trying to do in most of 
> these cases is prepopulate one of the fields in the auth form (specifically 
> the course_id field).
>
> On Thursday, June 27, 2013 8:21:41 AM UTC-5, Isaac Dontje Lindell wrote:
>>
>> Sorry, should have specified. Version 2.4.6-stable
>>
>> On Thursday, June 27, 2013 1:31:14 AM UTC-5, Massimo Di Pierro wrote:
>>>
>>> Which web2py version?
>>>
>>> On Wednesday, 26 June 2013 11:16:11 UTC-5, Isaac Dontje Lindell wrote:
>>>>
>>>> I have this in my db.py model:
>>>>
>>>> ## configure auth policy
>>>> auth.settings.registration_requires_verification = False
>>>> auth.settings.registration_requires_approval = False
>>>> auth.settings.reset_password_requires_verification = True
>>>>
>>>> If I register for the application (at %app%/default/user/register), it 
>>>> goes through (I get a "Success" flash and an entry is added to the 
>>>> auth_user table.)  However, every time I register, a registration_key is 
>>>> added to the auth_user entry. The user is prevented from logging in until 
>>>> I 
>>>> remove the registration key from the auth_user row manually.
>>>>
>>>> It's my understanding that the first 2 lines above should stop a 
>>>> registration_key from being added or created - the user should be able to 
>>>> log in immediately.
>>>>
>>>> What am I missing?
>>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to