[web2py] Re: Custom authentication provider

2013-01-08 Thread Niphlod
hypothesis 2 is off the table

BTW: saying that you have a method that returns a dict and stating that 
that method doesn't update a field lacks of the key point.. 
*Who*writes/updates the auth_user table in your custom class ?

On Tuesday, January 8, 2013 5:36:39 PM UTC+1, Ignacio Ocampo wrote:

 Hi,

 I'm working with my own authentication provider as: *
 auth.settings.login_form=MyAuth()*, all *works correctly*.

 I need an additional field from default auth_user table definition, I 
 used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 
 'text')]*, works correctly (the value of this field is provided by 
 MyAuth() to reference another system, ergo, in web2py it's would be treated 
 as a simple text).

 The final schema is:

 CREATE TABLE auth_user(
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 first_name CHAR(128),
 last_name CHAR(128),
 email CHAR(512),
 password CHAR(512),
 registration_key CHAR(512),
 reset_password_key CHAR(512),
 registration_id CHAR(512)
 , *employee_id* TEXT);

 In MyAuth() class, I have the method get_user(self), which web2py call in 
 the login process to get user details. At the end of this method, I return:

 user = dict(first_name=response['attributes']['cn'][0], 
 last_name=response['attributes']['cn'][0], 
 username=response['attributes']['uid'][0], 
 registration_id=response['attributes']['uid'][0], *employee_id*
 =response['attributes']['*employee_id*'][0])

 All fields are updated correctly, except the *employee_id*, that is the 
 additional field.

 *Hypothesis 1*: I don't know if web2py is updating only default fields 
 from the auth_user table (and because employee_id are not default field, 
 it's no updated).
 *Hypothesis 2*: The name of the additional field *employee_id* is 
 malformed (because the last part _id is used to reference another table 
 and commonly is INT type and web2py don't know how to handle this, since 
 there is no the *employee* table).

 Thank you.


-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
I only return a dict in the get_user, web2py does all the work.

web2py call the get_user method, and web2py update the auth_user table with 
the dict values.

I don't write/update the auth_user table in my custom class.

On Tuesday, January 8, 2013 11:05:04 AM UTC-6, Niphlod wrote:

 hypothesis 2 is off the table

 BTW: saying that you have a method that returns a dict and stating that 
 that method doesn't update a field lacks of the key point.. 
 *Who*writes/updates the auth_user table in your custom class ?

 On Tuesday, January 8, 2013 5:36:39 PM UTC+1, Ignacio Ocampo wrote:

 Hi,

 I'm working with my own authentication provider as: *
 auth.settings.login_form=MyAuth()*, all *works correctly*.

 I need an additional field from default auth_user table definition, I 
 used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 
 'text')]*, works correctly (the value of this field is provided by 
 MyAuth() to reference another system, ergo, in web2py it's would be treated 
 as a simple text).

 The final schema is:

 CREATE TABLE auth_user(
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 first_name CHAR(128),
 last_name CHAR(128),
 email CHAR(512),
 password CHAR(512),
 registration_key CHAR(512),
 reset_password_key CHAR(512),
 registration_id CHAR(512)
 , *employee_id* TEXT);

 In MyAuth() class, I have the method get_user(self), which web2py call in 
 the login process to get user details. At the end of this method, I return:

 user = dict(first_name=response['attributes']['cn'][0], 
 last_name=response['attributes']['cn'][0], 
 username=response['attributes']['uid'][0], 
 registration_id=response['attributes']['uid'][0], *employee_id*
 =response['attributes']['*employee_id*'][0])

 All fields are updated correctly, except the *employee_id*, that is the 
 additional field.

 *Hypothesis 1*: I don't know if web2py is updating only default fields 
 from the auth_user table (and because employee_id are not default field, 
 it's no updated).
 *Hypothesis 2*: The name of the additional field *employee_id* is 
 malformed (because the last part _id is used to reference another table 
 and commonly is INT type and web2py don't know how to handle this, since 
 there is no the *employee* table).

 Thank you.



-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
I see that only the first time that user login, web2py saves the 
employee_id.

If I logout and login, and I change the employee_id value (I write this in 
external file to see the value), web2py does not update the field.

On Tuesday, January 8, 2013 11:08:34 AM UTC-6, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.

 I don't write/update the auth_user table in my custom class.

 On Tuesday, January 8, 2013 11:05:04 AM UTC-6, Niphlod wrote:

 hypothesis 2 is off the table

 BTW: saying that you have a method that returns a dict and stating that 
 that method doesn't update a field lacks of the key point.. 
 *Who*writes/updates the auth_user table in your custom class ?

 On Tuesday, January 8, 2013 5:36:39 PM UTC+1, Ignacio Ocampo wrote:

 Hi,

 I'm working with my own authentication provider as: *
 auth.settings.login_form=MyAuth()*, all *works correctly*.

 I need an additional field from default auth_user table definition, I 
 used: *auth.settings.extra_fields['auth_user'] = [Field('**employee_id**', 
 'text')]*, works correctly (the value of this field is provided by 
 MyAuth() to reference another system, ergo, in web2py it's would be treated 
 as a simple text).

 The final schema is:

 CREATE TABLE auth_user(
 id INTEGER PRIMARY KEY AUTOINCREMENT,
 first_name CHAR(128),
 last_name CHAR(128),
 email CHAR(512),
 password CHAR(512),
 registration_key CHAR(512),
 reset_password_key CHAR(512),
 registration_id CHAR(512)
 , *employee_id* TEXT);

 In MyAuth() class, I have the method get_user(self), which web2py call 
 in the login process to get user details. At the end of this method, I 
 return:

 user = dict(first_name=response['attributes']['cn'][0], 
 last_name=response['attributes']['cn'][0], 
 username=response['attributes']['uid'][0], 
 registration_id=response['attributes']['uid'][0], *employee_id*
 =response['attributes']['*employee_id*'][0])

 All fields are updated correctly, except the *employee_id*, that is the 
 additional field.

 *Hypothesis 1*: I don't know if web2py is updating only default fields 
 from the auth_user table (and because employee_id are not default field, 
 it's no updated).
 *Hypothesis 2*: The name of the additional field *employee_id* is 
 malformed (because the last part _id is used to reference another table 
 and commonly is INT type and web2py don't know how to handle this, since 
 there is no the *employee* table).

 Thank you.



-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Anthony
On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



Yes, but where are you telling web2py to update the auth_user table? Can 
you show the code?

Anthony

-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
Yes,

I only uses:

auth.settings.login_form=MyAuth(
   param1=value1,
   param2=value
)

It's all, I never call and writes/update in the auth_user anywhere.

In gluon/tools.py login function, web2py check if they would use their 
login form or from a central source (line 1955)

At line 2068 web2py determined that central authentication would be used.

At line 2075 web2py call: user = 
self.get_or_create_user(table_user._filter_fields(cas_user))

At line 1724, within get_or_create_user function, after that web2py 
determine that the user exists:

*update_keys = dict(registration_id=keys['registration_id']) #here is the 
BUG*

I solved it with:

*update_keys = dict(registration_id=keys['registration_id'], 
employee_id=keys['employee_id'])*

So, I think that we need to update the gluon/tools.py file, to improve the 
update of external fields.

On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony


-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Massimo Di Pierro
Perhaps I misunderstand the workflow. The solution cannot be to change an 
Auth function to handle a specific custom field.

The proper signature for the function is 

  get_or_create_user(self, keys, update_fields=['email'])

so if you want to pass employee_id to keys and expect it to update the 
record in case it is found you need to pass

  get_or_create_user(self, keys, update_fields=['email', 'employee_id'])

There are two options here:
1) allow some auth.settings.update_fields to be specified so the function 
is called with right parameters
2) change it so that update_fields defaults to keys.keys()

2) would solve the problem automatically but it may break something. Not 
sure.

Please open a ticket: http://code.google.com/p/web2py/issues/list
but let's discuss it some more.

Massimo




On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote:

 Yes,

 I only uses:

 auth.settings.login_form=MyAuth(
param1=value1,
param2=value
 )

 It's all, I never call and writes/update in the auth_user anywhere.

 In gluon/tools.py login function, web2py check if they would use their 
 login form or from a central source (line 1955)

 At line 2068 web2py determined that central authentication would be used.

 At line 2075 web2py call: user = 
 self.get_or_create_user(table_user._filter_fields(cas_user))

 At line 1724, within get_or_create_user function, after that web2py 
 determine that the user exists:

 *update_keys = dict(registration_id=keys['registration_id']) #here is the 
 BUG*

 I solved it with:

 *update_keys = dict(registration_id=keys['registration_id'], 
 employee_id=keys['employee_id'])*

 So, I think that we need to update the gluon/tools.py file, to improve the 
 update of external fields.

 On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony



-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
I only change the Auth function to solve this problem and to know how 
web2py works.

I see that get_or_create_user have a second parameter with fields that will 
be updated.

I think that if the developer uses web2py default Auth function, would be 
nice allow update fields through auth.settings.update_fields configuration.

Is viable? To open a new ticket.

Ignacio Ocampo

On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote:

 Perhaps I misunderstand the workflow. The solution cannot be to change an 
 Auth function to handle a specific custom field.

 The proper signature for the function is 

   get_or_create_user(self, keys, update_fields=['email'])

 so if you want to pass employee_id to keys and expect it to update the 
 record in case it is found you need to pass

   get_or_create_user(self, keys, update_fields=['email', 'employee_id'])

 There are two options here:
 1) allow some auth.settings.update_fields to be specified so the function 
 is called with right parameters
 2) change it so that update_fields defaults to keys.keys()

 2) would solve the problem automatically but it may break something. Not 
 sure.

 Please open a ticket: http://code.google.com/p/web2py/issues/list
 but let's discuss it some more.

 Massimo




 On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote:

 Yes,

 I only uses:

 auth.settings.login_form=MyAuth(
param1=value1,
param2=value
 )

 It's all, I never call and writes/update in the auth_user anywhere.

 In gluon/tools.py login function, web2py check if they would use their 
 login form or from a central source (line 1955)

 At line 2068 web2py determined that central authentication would be used.

 At line 2075 web2py call: user = 
 self.get_or_create_user(table_user._filter_fields(cas_user))

 At line 1724, within get_or_create_user function, after that web2py 
 determine that the user exists:

 *update_keys = dict(registration_id=keys['registration_id']) #here is 
 the BUG*

 I solved it with:

 *update_keys = dict(registration_id=keys['registration_id'], 
 employee_id=keys['employee_id'])*

 So, I think that we need to update the gluon/tools.py file, to improve 
 the update of external fields.

 On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony



-- 





[web2py] Re: Custom authentication provider

2013-01-08 Thread Ignacio Ocampo
I open a ticket http://code.google.com/p/web2py/issues/detail?id=1260

On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote:

 Perhaps I misunderstand the workflow. The solution cannot be to change an 
 Auth function to handle a specific custom field.

 The proper signature for the function is 

   get_or_create_user(self, keys, update_fields=['email'])

 so if you want to pass employee_id to keys and expect it to update the 
 record in case it is found you need to pass

   get_or_create_user(self, keys, update_fields=['email', 'employee_id'])

 There are two options here:
 1) allow some auth.settings.update_fields to be specified so the function 
 is called with right parameters
 2) change it so that update_fields defaults to keys.keys()

 2) would solve the problem automatically but it may break something. Not 
 sure.

 Please open a ticket: http://code.google.com/p/web2py/issues/list
 but let's discuss it some more.

 Massimo




 On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote:

 Yes,

 I only uses:

 auth.settings.login_form=MyAuth(
param1=value1,
param2=value
 )

 It's all, I never call and writes/update in the auth_user anywhere.

 In gluon/tools.py login function, web2py check if they would use their 
 login form or from a central source (line 1955)

 At line 2068 web2py determined that central authentication would be used.

 At line 2075 web2py call: user = 
 self.get_or_create_user(table_user._filter_fields(cas_user))

 At line 1724, within get_or_create_user function, after that web2py 
 determine that the user exists:

 *update_keys = dict(registration_id=keys['registration_id']) #here is 
 the BUG*

 I solved it with:

 *update_keys = dict(registration_id=keys['registration_id'], 
 employee_id=keys['employee_id'])*

 So, I think that we need to update the gluon/tools.py file, to improve 
 the update of external fields.

 On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony


On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote:

 Perhaps I misunderstand the workflow. The solution cannot be to change an 
 Auth function to handle a specific custom field.

 The proper signature for the function is 

   get_or_create_user(self, keys, update_fields=['email'])

 so if you want to pass employee_id to keys and expect it to update the 
 record in case it is found you need to pass

   get_or_create_user(self, keys, update_fields=['email', 'employee_id'])

 There are two options here:
 1) allow some auth.settings.update_fields to be specified so the function 
 is called with right parameters
 2) change it so that update_fields defaults to keys.keys()

 2) would solve the problem automatically but it may break something. Not 
 sure.

 Please open a ticket: http://code.google.com/p/web2py/issues/list
 but let's discuss it some more.

 Massimo




 On Tuesday, 8 January 2013 12:09:09 UTC-6, Ignacio Ocampo wrote:

 Yes,

 I only uses:

 auth.settings.login_form=MyAuth(
param1=value1,
param2=value
 )

 It's all, I never call and writes/update in the auth_user anywhere.

 In gluon/tools.py login function, web2py check if they would use their 
 login form or from a central source (line 1955)

 At line 2068 web2py determined that central authentication would be used.

 At line 2075 web2py call: user = 
 self.get_or_create_user(table_user._filter_fields(cas_user))

 At line 1724, within get_or_create_user function, after that web2py 
 determine that the user exists:

 *update_keys = dict(registration_id=keys['registration_id']) #here is 
 the BUG*

 I solved it with:

 *update_keys = dict(registration_id=keys['registration_id'], 
 employee_id=keys['employee_id'])*

 So, I think that we need to update the gluon/tools.py file, to improve 
 the update of external fields.

 On Tuesday, January 8, 2013 11:43:44 AM UTC-6, Anthony wrote:

 On Tuesday, January 8, 2013 12:08:34 PM UTC-5, Ignacio Ocampo wrote:

 I only return a dict in the get_user, web2py does all the work.

 web2py call the get_user method, and web2py update the auth_user table 
 with the dict values.



 Yes, but where are you telling web2py to update the auth_user table? Can 
 you show the code?

 Anthony


On Tuesday, January 8, 2013 1:23:45 PM UTC-6, Massimo Di Pierro wrote:

 Perhaps I misunderstand the workflow. The solution cannot be to change an 
 Auth function to handle a specific custom field.

 The proper signature for the function is 

   get_or_create_user(self, keys, update_fields=['email'])

 so if you want to pass employee_id to keys and expect it to update the 
 record in case it is found you need to pass