hi stifan,

add this to db.py :

auth.settings.extra_fields['auth_user']=[Field('geolat','float'),
                                         Field('geolng','float')]

db.auth_user._manual_entry = False

if not db.auth_user._manual_entry:
    db.auth_user.geolat.readable = False
    db.auth_user.geolat.writable = False 
    db.auth_user.geolng.readable = False
    db.auth_user.geolng.writable = False 

def check_user_geo(form):
    if session.lat and session.lng:
        return form
    else:
        mess = 'no geo data registration failed'
        redirect(URL('show_message',args=mess))

auth.settings.register_next = URL('update_user')
auth.settings.register_onvalidation.append(check_user_geo)

add this to user.html :

<script language="javascript">
function getLocation() {
    if(navigator.geolocation)
        {
        navigator.geolocation.getCurrentPosition(postLocation);
        }
    }
function postLocation(position) {
            jQuery.post( '{{=URL('set_location')}}',{lat: 
+position.coords.latitude, lng: +position.coords.longitude });
        }
{{if request.args(0)=='register' and not db.auth_user._manual_entry:}}
    getLocation();
{{pass}}
</script>

put this in default controller :

def set_location():
    session.lat = request.post_vars['lat']
    session.lng = request.post_vars['lng']

def update_user():
    row = db(db.auth_user.id == auth.user_id).select().first()
    row.geolat = session.lat
    row.geolng = session.lng
    row.update_record()
    mess = 'registration succeeded'
    redirect(URL('show_message',args=mess))


Le lundi 26 octobre 2015 00:05:34 UTC+1, 黄祥 a écrit :
>
> hi, pierre,
>
> might i know how do you get the latitude and longitude value for your 
> form.vars?
>
> thanks and best regards,
> stifan
>
> On Monday, October 26, 2015 at 12:45:01 AM UTC+7, Pierre wrote:
>>
>> thanks this works : 
>>
>> auth.settings.register_onvalidation(check_geo)
>>
>> +
>>
>> def check_geo(form):
>>       if not form.vars.lat or not form.vars.lng:
>>             redirect(url('registration_failed'))
>>            
>>
>> Le dimanche 25 octobre 2015 13:34:36 UTC+1, Anthony a écrit :
>>>
>>> First, note that auth.settings.login_after_registration is only relevant 
>>> when auth.settings.registration_requires_verification = True, as that is 
>>> the only case where it makes sense to differentiate whether login should be 
>>> allowed immediately or not (when registration does not require 
>>> verification, the user can immediately login manually, so no reason not to 
>>> do it automatically).
>>>
>>> Anyway, if "geolocation user acceptance" is something that can be 
>>> handled automatically at time of registration, then just use an 
>>> auth.settings.register_onvalidation callback to do the check, and simply 
>>> reject the registration if the check fails. On the other hand, if some 
>>> manual approval process is required, then you should set 
>>> auth.settings.registration_requires_approval 
>>> = True, and that will disable login until the registration has been 
>>> approved by an admin.
>>>
>>> Anthony
>>>
>>> On Sunday, October 25, 2015 at 6:29:12 AM UTC-4, Pierre wrote:
>>>>
>>>> Yes ok but this is not what I want :
>>>>
>>>>
>>>> extracted from web2py book:
>>>>
>>>> "
>>>>
>>>> If you want to allow people to register and automatically log them in 
>>>> after registration but still want to send an email for verification so 
>>>> that 
>>>> they cannot login again after logout, unless they completed the 
>>>> instructions in the email, you can accomplish it as follows:
>>>>
>>>> auth.settings.registration_requires_verification = True
>>>> auth.settings.login_after_registration = True
>>>>
>>>> "
>>>> here is the problem :
>>>> I added some extra fields to auth_user to provide geolocation data 
>>>> howewer I cannot predict "geolocation user acceptance" so my idea was to 
>>>> simply delete the user account in case geolocation is refused. but this 
>>>> cannot be done since new user is logged in automatically (he cannot log 
>>>> out 
>>>> if his account is deleted). Now I think about a different strategy using 
>>>> permissions and roles like "cannot login till geolocation data provided". 
>>>> This seems like a lot of complexity to solve a simple task ?
>>>>
>>>> Le dimanche 25 octobre 2015 03:55:34 UTC+1, DenesL a écrit :
>>>>>
>>>>>
>>>>> You also need
>>>>>
>>>>> settings.registration_requires_verification = True
>>>>>
>>>>>
>>>>>
>>>>> On Saturday, October 24, 2015 at 8:30:52 PM UTC-4, Pierre wrote:
>>>>>>
>>>>>> Hi everyone,
>>>>>>
>>>>>> I tried to do it with no success with this:
>>>>>>
>>>>>> auth.settings.login_after_registration = False
>>>>>>
>>>>>> thanks for your help
>>>>>>
>>>>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to