[web2py] Re: Preventing login after Auth.register; Adding groups to the register form
I managed to get both of those problems sorted. Thank you for your input! Attached below is the rough code I used: @auth.requires_membership('administrators') def create(): # set up groups to be put into groups = db().select(db.auth_group.ALL) group_fields = [] group_lookup = {} # create the fields and a lookup table for the ids of the groups if we want to add them for g in groups: name = "is_in_group_%s" % g.role group_fields.append(Field(name, "boolean", label=g.role.capitalize())) group_lookup[name] = g.id # create the form form = SQLFORM.factory(db.auth_user, Field("password_two", "password", requires=IS_EXPR('value==%s' % repr(request.vars.get("password", None)), error_message=auth.messages.mismatched_password), label="Verify Password"), *group_fields) # if all good if form.accepts(request.vars): response.flash = 'User "%s" added successfully!' % request.vars["username"] # create an ignore list of input names to seperate the user data from the rest ignore_list = group_lookup.keys() + ["password_two", "_formname"] # seperate the user_data user_data = {} for k in request.vars: if k not in ignore_list: user_data[k] = request.vars[k] # create the new user new_user = db.auth_user.insert(**user_data) # process the membership information for g in group_lookup.keys(): if request.vars.get(g, None).lower() == "on": auth.add_membership(group_lookup[g], new_user) elif form.errors: response.flash = 'An error has occurred.' else: response.flash = 'Please fill out the form.' return dict(form=form) On Apr 22, 3:40 pm, mdipierro wrote: > auth.resiter() form is not thought for person A to register person B > but for person A to register itself. > > You can use appadmin to register another person or you have to create > your own interface for example via > > form=crud.create(db.auth_user) > > You can also make your form more complex > > form=SQLFORM.factory(db.auth_user,Field('group1'),Field('group2')): > if form.accepts(request.vars): > insert form.vars into db.auth_user > if form.vars.group1. auth.add_membership() > if form.vars.group2. auth.add_membership() > > On Apr 21, 10:00 pm, rohfle wrote: > > > When I said "logging on", I meant the process of login, not logging > > events. > > > Elaborating on the original questions: > > 1) For example, I login as an administrator and I register a user name > > named bob. When I click submit to register bob, the currently logged- > > in user gets switched from administrator to "bob" after being added to > > the database. Can I stop this switch from occurring? > > > 2) I want to extend the register form from looking in HTML like: > > [username] > > [firstname] > > [lastname] > > [password] > > [verify password] > > > > to: > > [username] > > [firstname] > > [lastname] > > [password] > > [verify password] > > > [x] group1 > > [ ] group2 > > > > where group1 and group2 come from the table auth_group. > > > Sorry I should have made these things clearer. > > > On Apr 22, 2:13 pm, mdipierro wrote: > > > > 1) Yes. Look at the bottom of this page: > > > >http://www.web2py.com/book/default/section/8/2 > > > > If you set a log message to None, the log is not performed. > > > > 2) Not sure I understand. You can do > > > > auth.settings.register_onaccept=lambda form: do_something_with(form) > > > > On Apr 21, 8:14 pm, rohfle wrote: > > > > > Couple of questions about web2py Auth: > > > > > 1) Can I stop Auth.register from logging on as the newly created user > > > > after registration? > > > > 2) Is there a way to add group membership to form returned by > > > > Auth.register? > > > > > -- > > > > Subscription > > > > settings:http://groups.google.com/group/web2py/subscribe?hl=en
[web2py] Re: Preventing login after Auth.register; Adding groups to the register form
It is in the book but it is called form_factory. web2py support both names. On Apr 21, 11:22 pm, Kuba Kucharski wrote: > > form=SQLFORM.factory(db.auth_user,Field('group1')): > > btw this > ( I mean concatenating/passing "table definition" like f.e > "db.some_table" along with Field('some_field') in the > SQLFORM.factory() ) > is not in the book(?) and it doesn't look google-able to me anywhere else > > this maybe obvious from programmer point of view, but not always for a > web2py-framework user? > maybe it deserves to be there because this "let's squeeze everything > we can from python" - philosophy.. is one of those things that makes > web2py so cool. > and SQLFORM.factory() subsection is pretty short. > > or.. are we trying to fit to much into the book, and soon we will need > beginner's and advanced book. normal/extended/with python explanatory > etc. > > this is a question for all of you: > > How far should we go with the book/web2pyslices/etc w/o marking > sections/subsections beginner/advanced(maybe some other markers) so we > could easily split/sort them later? > > -- > Subscription settings:http://groups.google.com/group/web2py/subscribe?hl=en
Re: [web2py] Re: Preventing login after Auth.register; Adding groups to the register form
> form=SQLFORM.factory(db.auth_user,Field('group1')): btw this ( I mean concatenating/passing "table definition" like f.e "db.some_table" along with Field('some_field') in the SQLFORM.factory() ) is not in the book(?) and it doesn't look google-able to me anywhere else this maybe obvious from programmer point of view, but not always for a web2py-framework user? maybe it deserves to be there because this "let's squeeze everything we can from python" - philosophy.. is one of those things that makes web2py so cool. and SQLFORM.factory() subsection is pretty short. or.. are we trying to fit to much into the book, and soon we will need beginner's and advanced book. normal/extended/with python explanatory etc. this is a question for all of you: How far should we go with the book/web2pyslices/etc w/o marking sections/subsections beginner/advanced(maybe some other markers) so we could easily split/sort them later? -- Subscription settings: http://groups.google.com/group/web2py/subscribe?hl=en
[web2py] Re: Preventing login after Auth.register; Adding groups to the register form
auth.resiter() form is not thought for person A to register person B but for person A to register itself. You can use appadmin to register another person or you have to create your own interface for example via form=crud.create(db.auth_user) You can also make your form more complex form=SQLFORM.factory(db.auth_user,Field('group1'),Field('group2')): if form.accepts(request.vars): insert form.vars into db.auth_user if form.vars.group1. auth.add_membership() if form.vars.group2. auth.add_membership() On Apr 21, 10:00 pm, rohfle wrote: > When I said "logging on", I meant the process of login, not logging > events. > > Elaborating on the original questions: > 1) For example, I login as an administrator and I register a user name > named bob. When I click submit to register bob, the currently logged- > in user gets switched from administrator to "bob" after being added to > the database. Can I stop this switch from occurring? > > 2) I want to extend the register form from looking in HTML like: > [username] > [firstname] > [lastname] > [password] > [verify password] > > to: > [username] > [firstname] > [lastname] > [password] > [verify password] > > [x] group1 > [ ] group2 > > where group1 and group2 come from the table auth_group. > > Sorry I should have made these things clearer. > > On Apr 22, 2:13 pm, mdipierro wrote: > > > 1) Yes. Look at the bottom of this page: > > >http://www.web2py.com/book/default/section/8/2 > > > If you set a log message to None, the log is not performed. > > > 2) Not sure I understand. You can do > > > auth.settings.register_onaccept=lambda form: do_something_with(form) > > > On Apr 21, 8:14 pm, rohfle wrote: > > > > Couple of questions about web2py Auth: > > > > 1) Can I stop Auth.register from logging on as the newly created user > > > after registration? > > > 2) Is there a way to add group membership to form returned by > > > Auth.register? > > > > -- > > > Subscription > > > settings:http://groups.google.com/group/web2py/subscribe?hl=en
[web2py] Re: Preventing login after Auth.register; Adding groups to the register form
When I said "logging on", I meant the process of login, not logging events. Elaborating on the original questions: 1) For example, I login as an administrator and I register a user name named bob. When I click submit to register bob, the currently logged- in user gets switched from administrator to "bob" after being added to the database. Can I stop this switch from occurring? 2) I want to extend the register form from looking in HTML like: [username] [firstname] [lastname] [password] [verify password] to: [username] [firstname] [lastname] [password] [verify password] [x] group1 [ ] group2 where group1 and group2 come from the table auth_group. Sorry I should have made these things clearer. On Apr 22, 2:13 pm, mdipierro wrote: > 1) Yes. Look at the bottom of this page: > > http://www.web2py.com/book/default/section/8/2 > > If you set a log message to None, the log is not performed. > > 2) Not sure I understand. You can do > > auth.settings.register_onaccept=lambda form: do_something_with(form) > > On Apr 21, 8:14 pm, rohfle wrote: > > > Couple of questions about web2py Auth: > > > 1) Can I stop Auth.register from logging on as the newly created user > > after registration? > > 2) Is there a way to add group membership to form returned by > > Auth.register? > > > -- > > Subscription settings:http://groups.google.com/group/web2py/subscribe?hl=en
[web2py] Re: Preventing login after Auth.register; Adding groups to the register form
1) Yes. Look at the bottom of this page: http://www.web2py.com/book/default/section/8/2 If you set a log message to None, the log is not performed. 2) Not sure I understand. You can do auth.settings.register_onaccept=lambda form: do_something_with(form) On Apr 21, 8:14 pm, rohfle wrote: > Couple of questions about web2py Auth: > > 1) Can I stop Auth.register from logging on as the newly created user > after registration? > 2) Is there a way to add group membership to form returned by > Auth.register? > > -- > Subscription settings:http://groups.google.com/group/web2py/subscribe?hl=en