Re: [web2py] Re: Book clarification regarding verify_email & reset_password

2012-08-14 Thread Jonathan Lundell
On 14 Aug 2012, at 5:35 AM, Anthony  wrote:
> auth,messages.verify_email = ('Here I put my very long html code'
>  'I can write texts '
>  'I can put a tutorial '
> 'I can put an user agreement'
> 'ans so the final link'
> ' Click on the link'
> ' http://%(host)s/%(url)s/%(key)s 
> '
> " to verify your email')
> 
> or even...
> 
> 
> auth,messages.verify_email = template.render("my_verify_email_template.html", 
> {"mycontext": "myvalues"})
> 
> But can't you already do either of the above? As long as the resulting string 
> includes "%(key)s" somewhere, the current setup should work fine, no? In the 
> first case, for example, you could do:
> 
> auth.messages.verify_email = '''here I put my very long html code
> I can write text
> I can put a tutorial
> and so...the final link
> Click on the link
> http://%(host)s/%(url)s/%%(key)s
> to verify your email''' % dict(host='mysite.com', 
> url='default/user/verify_email')
> 
> Which will yield:
> 
> 'here I put my very long html code\nI can write text\nI can put a 
> tutorial\nand so...the final link\nClick on the 
> link\nhttp://mysite.com/default/user/verify_email/%(key)s\nto verify your 
> email'
> 
> which includes "%(key)s", which will be filled in by the register function.
> 

With Python 2.6+, you can also use str.format() to provide a second level of 
interpolation that's independent of %-interpolation. 

http://docs.python.org/library/stdtypes.html#str.format

-- 





Re: [web2py] Re: Book clarification regarding verify_email & reset_password

2012-08-14 Thread Anthony

>
> auth,messages.verify_email = ('Here I put my very long html code'
>  'I can write texts '
>  'I can put a tutorial '
> 'I can put an user agreement'
> 'ans so the final link'
> ' Click on the link'
> ' 
> http://%(host)s/%(url)s/%(key)s '
> " to verify your email')
>
> *or even...*
>
>
> auth,messages.verify_email = 
> template.render("my_verify_email_template.html", {"mycontext": "myvalues"})
>

But can't you already do either of the above? As long as the resulting 
string includes "%(key)s" somewhere, the current setup should work fine, 
no? In the first case, for example, you could do:

auth.messages.verify_email = '''here I put my very long html code
I can write text
I can put a tutorial
and so...the final link
Click on the link
http://%(host)s/%(url)s/%%(key)s
to verify your email''' % dict(host='mysite.com', url=
'default/user/verify_email')

Which will yield:

'here I put my very long html code\nI can write text\nI can put a 
tutorial\nand so...the final link\nClick on the 
link\nhttp://mysite.com/default/user/verify_email/%(key)s\nto verify your 
email'

which includes "%(key)s", which will be filled in by the register function.

Anthony

-- 





Re: [web2py] Re: Book clarification regarding verify_email & reset_password

2012-08-14 Thread Bruno Rocha
Thinking again I am guessing a better option for this...

(note: the problem here is not to get the 'key', the problem is to be able
to build the string and interpolate multiple keys on to it on different
running times)

I think this could be better.

auth,messages.verify_email = 'Click on the link http://%(host)s/%(url)s/%(key)s
to verify your email'

*So Auth would do:*

auth.settings.get_verify_email = lambda key, httphost, url:
auth.messages.verify_email \
  % dict(host=host, url=url, key=key)

auth.settings.verify_email_url = URL(..)
auth.settings.verify_email_host = request.env.http_host

self.settings.mailer.send(to=form.vars.email,
subject=self.messages.verify_email_subject,
message=self.settings.get_verify_email(key,
self.settings.verify_email_url, auth.settings.verify_email_host)
)

*Why this? just to let users to personalize the message string more easily.*

Example:

auth,messages.verify_email = ('Here I put my very long html code'
 'I can write texts '
 'I can put a tutorial '
'I can put an user agreement'
'ans so the final link'
' Click on the link'
' http://%(host)s/%(url)s/%(key)s
'
" to verify your email')

*or even...*


auth,messages.verify_email =
template.render("my_verify_email_template.html", {"mycontext": "myvalues"})


Customizing this message sin the current way is very difficult and lead on
errors because of string interpolation being done on the time of definition.

On Tue, Aug 14, 2012 at 12:14 AM, Anthony  wrote:

> I think maybe the book is just suggesting the "http://"; +
> request.env.http_host part of the URL might not be the correct host name
> if you're behind a proxy, so you should ensure you have the correct full
> URL. The remainder of the URL should be correct as is. Note, the example
> shown in the book is actually the default value for
> auth.settings.verify_email, so you don't really have to set it unless you
> need to change it.
>
> Anthony
>
> On Monday, August 13, 2012 9:31:25 PM UTC-4, Anthony wrote:
>>
>> Actually, the book is a bit confusing there -- the example code appears
>> to be complete as is.
>>
>> Anthony
>>
>> On Monday, August 13, 2012 9:09:46 PM UTC-4, JoeCodeswell wrote:
>>>
>>> Dear web2py folks,
>>>
>>> In the book it says in /chapter/29/9#Authentication:
>>>
>>>
>>> In Auth, by default, email verification is disabled. To enable email,
 append the following lines in the model where auth is defined:


 1.
 2.
 3.
 4.
 5.
 6.
 7.
 8.
 9.
 10.
 11.


 auth.settings.registration_**requires_verification = False
 auth.settings.registration_**requires_approval = False
 auth.settings.reset_password_**requires_verification = True
 auth.messages.verify_email = 'Click on the link http://' + \

 request.env.http_host + \
 URL(r=request,c='default',f='**user',args=['verify_email']) + \

 '/%(key)s to verify your email'
 auth.messages.reset_password = 'Click on the link http://' + \

 request.env.http_host + \
 URL(r=request,c='default',f='**user',args=['reset_password']) + \

 '/%(key)s to reset your password'

 You need to replace the string


 1.

 'Click on the link ...'

 in auth.messages.verify_email with the proper complete URL of the
 action verify_email.
>>>
>>>
>>>
>>>
>>> For both verify_email and reset_password:
>>>  Should I replace
>>>
>>> 'Click on the link http://'
>>> With:
>>> 'Click on the link http://myserver.com/myapp/'
>>> Or with:
>>> 'Click on the link http://myserver.com/myapp/defa**ult/user/verify_email'
>>> My guess is the first, but because the book says "proper complete URL", I 
>>> am not sure.
>>>
>>> Thanks in advance for the help.
>>>
>>> Love and peace,
>>>
>>> Joe
>>>
>>>
>>>
>>>
>>>  --
>
>
>
>

-- 





Re: [web2py] Re: Book clarification regarding verify_email & reset_password

2012-08-13 Thread Anthony

>
> auth.messages.verify_email = 'Click on the link 
> http://%(env)s/%(url)s/%(key)s to verify your email' \
>
>   % dict(env=request.env.http_host, url=URL(...), 
> key= lambda : lazy_get_the_key())
>
> Should this works? being lazy_get_the_key() a function which selects the 
> current user to interpolate.
>
>
The Auth code includes:

self.settings.mailer.send(to=form.vars.email,
subject=self.messages.verify_email_subject,
message=self.messages.verify_email
% dict(key=key))
 
So, the key is generated and provided by the code -- you don't have to fill 
it in yourself.

Anthony

-- 





Re: [web2py] Re: Book clarification regarding verify_email & reset_password

2012-08-13 Thread Bruno Rocha
Why not:


auth.messages.verify_email = 'Click on the link
http://%(env)s/%(url)s/%(key)s to verify your email' \

  % dict(env=request.env.http_host,
url=URL(...), key= lambda : lazy_get_the_key())

Should this works? being lazy_get_the_key() a function which selects
the current user to interpolate.





*Bruno Cezar Rocha** - @rochacbruno*
rochacbr...@gmail.com | Mobile: +55 (11) 99210-8821
www.CursoDePython.com.br | www.rochacbruno.com.br
Blog: Loading html elements dynamically with web2py and ajax

  Get a signature like this.

Click
here.



On Mon, Aug 13, 2012 at 10:31 PM, Anthony  wrote:

> Actually, the book is a bit confusing there -- the example code appears to
> be complete as is.
>
> Anthony
>
>
> On Monday, August 13, 2012 9:09:46 PM UTC-4, JoeCodeswell wrote:
>>
>> Dear web2py folks,
>>
>> In the book it says in /chapter/29/9#Authentication:
>>
>>
>> In Auth, by default, email verification is disabled. To enable email,
>>> append the following lines in the model where auth is defined:
>>>
>>>
>>> 1.
>>> 2.
>>> 3.
>>> 4.
>>> 5.
>>> 6.
>>> 7.
>>> 8.
>>> 9.
>>> 10.
>>> 11.
>>>
>>>
>>> auth.settings.registration_**requires_verification = False
>>> auth.settings.registration_**requires_approval = False
>>> auth.settings.reset_password_**requires_verification = True
>>> auth.messages.verify_email = 'Click on the link http://' + \
>>>
>>> request.env.http_host + \
>>> URL(r=request,c='default',f='**user',args=['verify_email']) + \
>>>
>>> '/%(key)s to verify your email'
>>> auth.messages.reset_password = 'Click on the link http://' + \
>>>
>>> request.env.http_host + \
>>> URL(r=request,c='default',f='**user',args=['reset_password']) + \
>>>
>>> '/%(key)s to reset your password'
>>>
>>> You need to replace the string
>>>
>>>
>>> 1.
>>>
>>> 'Click on the link ...'
>>>
>>> in auth.messages.verify_email with the proper complete URL of the
>>> action verify_email.
>>
>>
>>
>>
>> For both verify_email and reset_password:
>>  Should I replace
>>
>> 'Click on the link http://'
>> With:
>> 'Click on the link http://myserver.com/myapp/'
>> Or with:
>> 'Click on the link http://myserver.com/myapp/defa**ult/user/verify_email'
>> My guess is the first, but because the book says "proper complete URL", I am 
>> not sure.
>>
>> Thanks in advance for the help.
>>
>> Love and peace,
>>
>> Joe
>>
>>
>>
>>
>>  --
>
>
>
>

--