Evitar redirecionamento para URL("default", "user", args="login") quando login falhar...

55 views
Skip to first unread message

Junior Phanter

unread,
Jun 9, 2017, 3:55:55 PM6/9/17
to web2py-users-brazil
Pessoal, eu preciso mudar as funções de login para outro controle diferente do "default", então eu fiz:

no model:


import os

myconf_phanterimages = AppConfig(reload=True)
db_phanterimages = DAL(myconf_phanterimages.get('db_phanterimages.uri'),
             pool_size=myconf.get('db_phanterimages.pool_size'),
             migrate_enabled=myconf.get('db_phanterimages.migrate'),
             check_reserved=['all'])

Auth_phanterimages = Auth(db_phanterimages, host_names=myconf.get('host.names'))

Auth_phanterimages.define_tables(username=False, signature=False)
Auth_phanterimages.settings.login_url = URL('phanterimages', 'user', args='login')
Auth_phanterimages.settings.logged_url = URL('phanterimages', 'user', args='profile')
Auth_phanterimages.settings.login_next = URL('phanterimages', 'index')
Auth_phanterimages.settings.logout_next = URL('phanterimages', 'index')
Auth_phanterimages.settings.profile_next = URL('phanterimages', 'index')
Auth_phanterimages.settings.register_next = URL('phanterimages', 'user', args='login')
Auth_phanterimages.settings.retrieve_username_next = URL('phanterimages', 'index')
Auth_phanterimages.settings.retrieve_password_next = URL('phanterimages', 'index')
Auth_phanterimages.settings.change_password_next = URL('phanterimages', 'index')
Auth_phanterimages.settings.request_reset_password_next = URL('phanterimages', 'user', args='login')
Auth_phanterimages.settings.reset_password_next = URL('phanterimages', 'user', args='login')
Auth_phanterimages.settings.verify_email_next = URL('phanterimages', 'user', args='login')


no controller:

@Auth_phanterimages.requires_login()
def index():
    """um monte de código"""
    return locals()


def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    http://..../[app]/default/user/retrieve_password
    http://..../[app]/default/user/change_password
    http://..../[app]/default/user/bulk_register
    use @auth.requires_login()
        @auth.requires_membership('group name')
        @auth.requires_permission('read','table name',record_id)
    to decorate functions that need access control
    also notice there is http://..../[app]/appadmin/manage/auth to allow administrator to manage users
    """
    return dict(form=Auth_phanterimages())


Quando faço login, tá tudo certo, quando saio, também... tá tudo trabalhando nos conformes, o problema é quando eu erro a senha de propósito então ele redireciona para o controller "default". Então eu modifiquei o arquivo tools.py do gluon e deixei assim (em vermelho):

                    if not user:
                        self.log_event(self.messages['login_failed_log'],
                                       request.post_vars)
                        # invalid login
                        session.flash = self.messages.invalid_login  #aqui é mensagem do request.flash
                        callback(onfail, None)
                        redirect(URL(request.controller, request.function, args=request.args, vars=request.get_vars),
                            client_side=settings.client_side)
Estava assim antes:
                       redirect(self.url(
args=request.args, vars=request.get_vars), client_side=settings.client_side

Resolveu meu problema, mas queria saber se é algum bug ou estou fazendo algo errado? Procurei na net eaAchei apenas um usuário com o mesmo problema na lista em inglês num post antigo, porém a solução que aconselharam a ele foi voltar para o controller "default" e encerrou o assunto. Alguém tem uma solução mais amigável sem mexer no código fonte do gluon.



Junior Phanter

unread,
Jun 9, 2017, 10:21:22 PM6/9/17
to web2py-us...@googlegroups.com
Saudações pessoal... pedi informação na lista em inglês e consegui resolver... irei compartilhar a solução com vcs...
pois bem, um rapaz lá, o Antony me disse que é só especificar o conttoler em:
auth=Auth(db, host_names=myconf.get('host.names'))

No meu caso ficou assim:

Auth_phanterimages = Auth(db_phanterimages, controller="phanterimages",host_names=myconf.get('host.names'))

Segue a solução do Antony na íntegra:

 Anthony

You need to specify the controller when initializing Auth:

Auth_phanterimages = Auth(db_phanterimages, controller='phanterimages',
                          host_names
=myconf.get('host.names'))

If you do that, you also don't have to bother with all of those URL settings, as they will automatically be constructed properly based on the new controller. Note, you can also specify a custom function via the "function" argument.

--
Você recebeu essa mensagem por estar inscrito no grupo web2py-users-brazil.
Para enviar uma mensagem ao grupo, envie email a: web2py-users-brazil@googlegroups.com
Para se desinscrever, envie email a: web2py-users-brazil+unsub...@googlegroups.com
Para mais opções, visite o site do grupo em: http://groups.google.com/group/web2py-users-brazil?hl=en
---
Você recebeu essa mensagem porque está inscrito no grupo "web2py-users-brazil" dos Grupos do Google.
Para cancelar inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para web2py-users-brazil+unsub...@googlegroups.com.
Para mais opções, acesse https://groups.google.com/d/optout.

Carlos Costa

unread,
Jun 10, 2017, 7:44:10 AM6/10/17
to web2py-us...@googlegroups.com
Boa!

Para se desinscrever, envie email a: web2py-users-brazil+unsubscribe...@googlegroups.com

Para mais opções, visite o site do grupo em: http://groups.google.com/group/web2py-users-brazil?hl=en
---
Você recebeu essa mensagem porque está inscrito no grupo "web2py-users-brazil" dos Grupos do Google.
Para cancelar inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para web2py-users-brazil+unsubscribe...@googlegroups.com.

Para mais opções, acesse https://groups.google.com/d/optout.

--
Você recebeu essa mensagem por estar inscrito no grupo web2py-users-brazil.
Para enviar uma mensagem ao grupo, envie email a: web2py-users-brazil@googlegroups.com
Para se desinscrever, envie email a: web2py-users-brazil+unsub...@googlegroups.com
Para mais opções, visite o site do grupo em: http://groups.google.com/group/web2py-users-brazil?hl=en
---
Você recebeu essa mensagem porque está inscrito no grupo "web2py-users-brazil" dos Grupos do Google.
Para cancelar inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para web2py-users-brazil+unsub...@googlegroups.com.
Para mais opções, acesse https://groups.google.com/d/optout.



--


Carlos J. Costa
Cientista da Computação  | BS Computer Science
Esp. Gestão em Telecom   |
PgC Telecom Mangement
<º))><

Marlysson Silva

unread,
Jul 8, 2017, 1:07:31 PM7/8/17
to web2py-users-brazil
Dica : Não altere os códigos do núcleo do framework .. 

Muito provavelmente tem uma forma de parametrizar na sua aplicação.

Como foi na resposta dada.
Reply all
Reply to author
Forward
0 new messages