user registration flash message not returned

46 views
Skip to first unread message

Yebach

unread,
Feb 3, 2016, 10:59:52 AM2/3/16
to web2py-users
Hello

I cannot retrieve the session.flash message after user successfully registers

my controler  (default.py ) is the following

def user():
    
    if request.args(0)=='profile':
        #uporabnikov Id
        uid =  auth.user_id
        #preberem podatke za tega userja iz obeh tabel
        record = db((db.auth_user.organization==db.organizations.id) & (db.auth_user.id == uid)).select().as_list()[0]
        recordd = db((db.auth_user.organization==db.organizations.id) & (db.auth_user.id == uid)).select().first()
        
        #Skrijem nepotrebna polja
        fields_to_hide_org = ['id', 'o_usern', 'o_useru', 'o_daten','o_dateu', 'o_status', 'o_code', 'o_faxnumber',\
                          'o_rootid', 'o_parentid', 'o_levelid', 'o_positionx','o_positiony' ]
        
        for fieldname in fields_to_hide_org:
            field = db.organizations[fieldname]
            field.readable = field.writable = False
        
        fields_to_hide_user = ['email', 'password', 'organization']
        
        for fieldname in fields_to_hide_user:
            field = db.auth_user[fieldname]
            field.readable = field.writable = False
        
        #org_name =  db(db.organization.id == record["organization"]).select(db.organization.o_name).as_list()[0]["o_name"]
        
       
        #nastavim vrednsoti polj, ki so ze v bazi
        authfields = [field for field in db.auth_user if field.name != 'id']
        
        #print record
        for field in authfields:
            #print field
            field.default = recordd.auth_user[field.name]
        
        orgfields = [field for field in db.organizations if field.name != 'id']
        for field in orgfields:
            field.default = recordd.organizations[field.name]

            
#        db.auth_user.first_name.default = record["auth_user"]["first_name"]
#        db.auth_user.last_name.default = record["auth_user"]["last_name"]
#        db.organization.o_name.default = record["organization"]["o_name"]
        
        form=SQLFORM.factory(db.auth_user,db.organizations, keepvalues = True)
        
        orgid = record["organizations"]['id']
        #print orgid
        
        if form.process().accepted:
            #Updatam polja v bazi
            org_forma = db.organizations._filter_fields(form.vars)
            for key, value in org_forma.iteritems():
                #print key, value
                db(db.organizations._id==orgid).update(**{key:value})
                #db(db.organization.id==orgid).update(key = value)
            
            user_forma = db.auth_user._filter_fields(form.vars)
            for key, value in user_forma.iteritems():
                db(db.auth_user._id==orgid).update(**{key:value})
             
            
            response.flash=T('Thanks for filling the form')
            redirect(URL('index'))
            
        return dict(form=form)
    
    
    form = auth()
    
    """
    Tole je sedaj tukaj ker ni delal foreing kej na auth_user.organization 
    """    
    if request.args(0) == 'register':

        if form.process().accepted:
            database = str(db).rpartition('/')[-1].replace('">', '')
            host = request.http_host
            port = request.http_port
            app = request.application
            if host:
                name = '%s/%s' % (host, app)
            else:
                name = app
                
            userid =  form.vars.id
            email = form.vars.email
            add_organization(form, userid)
            formFile = os.path.join(request.folder, 'private', 'formular_woshi_2016-02-01.rtf')
            regKey = db(db.auth_user.id == userid).select(db.auth_user.registration_key).first()
            key = regKey.registration_key
            message_content = T('Click on the link ') + ' http://shift.workerscheduling.com' + URL(r=request,c='default',f='user',args=['verify_email']) +  '/%s ' % (key)  + T('to verify your email')  
            mail.send(to=[email],
                        subject='Woshi confirm registration',
                        message=message_content,
                        attachments = mail.Attachment(formFile, content_id='file')
                        )
            
           
            mail.send(to = dddd',
                      subject= 'New user registered in WoShi',
                      message = 'A new user with e-mail address ' + email + ' has registered to Woshi with url address ' + name + ' in database ' + database
                     ) 
            
            session.flash= "Please check your e-mail to confirm registration"
            redirect(URL('index'))
    
    
    return dict(form = form)      


You can see the default/index.html page on  http://shift.workerscheduling.com

Any suggestions?

Anthony

unread,
Feb 3, 2016, 11:16:45 AM2/3/16
to web2py-users
If you do:

form = auth()

then you cannot call form.process(), as auth() automatically calls .process() itself. Also, the auth.register() method automatically redirects after processing, so the rest of your code will not be reached anyway. If you want to do something after registration, specify a callback via auth.settings.register_onaccept.

Anthony

Vid Ogris

unread,
Feb 4, 2016, 3:21:02 AM2/4/16
to web...@googlegroups.com
DO you suggest I change my controller completely ?

where do I set auth.settings_register_onaccept? in db.py?

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/NwljExPCKAA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Lep pozdrav 

Vid Ogris


Vid Ogris

unread,
Feb 4, 2016, 4:52:10 AM2/4/16
to web...@googlegroups.com
I have a login form on my first index page. Could that be the problem. No matter what I cannot get the session.flash message to be presented. 


Richard Vézina

unread,
Feb 4, 2016, 9:54:49 AM2/4/16
to web2py-users
Did you upgrade recently?

Did you try to have a look at your layouts and change in class="flash" -> class="w2p_flash"

I had problem with flash message display when I upgrade recently and that was the cause of it.

Richard

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+un...@googlegroups.com.

Anthony

unread,
Feb 4, 2016, 12:03:06 PM2/4/16
to web2py-users
On Thursday, February 4, 2016 at 3:21:02 AM UTC-5, Yebach wrote:
DO you suggest I change my controller completely ?

I don't know about "completely," but at least fix the incorrect part.
 
where do I set auth.settings_register_onaccept? in db.py?

Anywhere after Auth has been defined but before the register action will get called. With all the other Auth settings in a model file is fine.

Anthony

Vid Ogris

unread,
Feb 5, 2016, 6:09:15 AM2/5/16
to web...@googlegroups.com
No matter where I set them auth.settings seems to have no effect (not even auth.settings.register_next = URL('index', it does not redirects). 
I set them after defining auth but no success
Is  it possible that this is because of my "custom" user function?

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/NwljExPCKAA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages