Sessions management and Firefox langage

82 views
Skip to first unread message

Nicolas Hiblot

unread,
Sep 10, 2020, 4:37:40 AM9/10/20
to web2py-users
Hello All,

I will try  to present my problem simply :
I have a web2py application with a very simply homepage user.html

User and Password labels &  Login Button are automatically translatedby Firefox
in Firefox the detected langage

If a user enter login / password
I check user permissions and I show HTML page according to its permissions
by using some code already test as :

lastUserLogged = db(db.auth_event.description.contains('connect')).select(orderby=~db.auth_event.time_stamp,limitby=(0, 1)).first().user_id

and

lastUserName = db(db.auth_user.id == lastUserLogged).select(db.auth_user.username).first().username


In a native Firefox langage it's OK
But if I download new langage for Firefox restarts firefox and retry
all the permissions are allowed even if the user is not allowed to see HTML pages

Why ??
I don't know but if you can help me I appreciate ... sincerly


The HTML Page for the user.html


<body>
<style type="text/css">
body {
overflow:hidden;
}
#fond {
position:absolute;
top:0;
left:0;
}
#web2py_user_form {
position:absolute;
top:50px;
left:50px;
}
#auth_user_username__label{color:white;}
#auth_user_password__label{color:white;}
#auth_user_first_name__label{color:white;}
#auth_user_last_name__label{color:white;}
#auth_user_email__label{color:white;}
#auth_user_password_two__row{color:white;}

#fond,#fond img {
width:100%;
height:100%;
}
</style>
<div id="fond">
<img src='/me/static/theme/images/WALLPAPERS/wallpaper.jpg' alt="fond" />
</div>
<div id="web2py_user_form">
{{
=form
}}
</div>

<script language="javascript"><!--
jQuery("#web2py_user_form input:visible:enabled:first").focus();
{{if request.args(0)=='register':}}
web2py_validate_entropy(jQuery('#auth_user_password'),100);
{{elif request.args(0) in ('change_password','reset_password'):}}
web2py_validate_entropy(jQuery('#no_table_new_password'),100);
{{pass}}
//--></script>

</body>




Clemens

unread,
Sep 10, 2020, 4:59:51 AM9/10/20
to web2py-users

Language Settings
In Firefox there are two main user facing settings related to languages:
  • Web content: when you visit a web page, the browser will communicate to the server which languages you’d like to see content in. Technically, this is done by sending an Accept-Language HTTP header, which contains a list of locale codes in the user’s preferred order.
  • User interface: the language in which you want to see the browser (menus, preferences, etc.).
The difference between the two is not as intuitive as it might seem. A lot of users change the web content settings, and expect the user interface to change.

There you can see how to handle this. Hope, it helps!

Nicolas Hiblot

unread,
Sep 10, 2020, 5:50:33 AM9/10/20
to web2py-users
Thanks for your answer Clemens,
My problem is : I cannot control what the final user can do with its Firefox
So I would like to solve the problem directly with web2py
Because

1) I'm in native language : it works perfectly.  User is Utilisateur in French
2) I put English, german etc ... on a french Firefox installation : Utilisateur become sUser but when i'm login into my application : it does not work
3° I choose French : it's works again

So Firefox change is correct on my side
but queries of lastUserLoggued are not ...

Maybe i make something wrong in


lastUserLogged = db(db.auth_event.description.contains('connect')).select(orderby=~db.auth_event.time_stamp,limitby=(0, 1)).first().user_id
or
lastUserName = db(db.auth_user.id == lastUserLogged).select(db.auth_user.username).first().username

Regards

Nicolas

Nicolas Hiblot

unread,
Sep 10, 2020, 6:04:13 AM9/10/20
to web2py-users
Dear All;

Another solution should be the integration of the translation in the native web2py_user_form
Is it possible ?

Clemens

unread,
Sep 10, 2020, 6:21:24 AM9/10/20
to web2py-users
Well then, here's the solution that I'm using for the user to decide the language by him/herself:
auth.settings.extra_fields['auth_user']= [
    ...
    Field('lang', length=2, label=T('Language'), requires = IS_IN_SET(('EN', 'DE')), default='EN'),
    ... ]
(There the user can decide whether to use English or German)

By this, the user can maintain the language in his/her profile.

Then, in each controller I force the translator to the users language by:
T.force(auth.user.lang)

That's my favorite. I first thought, you would like to have automatic language selection by the browser. But letting the user to decide has the further advantage, that e.g. a German user working with an English browser can still have a German user interface.

Is this, what you are looking for?

Best regards
Clemens

Nicolas Hiblot

unread,
Sep 14, 2020, 5:02:46 AM9/14/20
to web2py-users
Dear Clemens

Sorry for the late answer .. it was my birthday on sunday ...
Well,

My web2py  application has a combo box with a lot of languages for a langage choice
with a T.force(configuration.language)
so the user can change the langage of the web2py application : no problem

My problem is
On the login page : there is no translation because I use a web2py_user_form (no translation)
So the translation is made by Firefox and not by web2py (only for this page)

If I change the Firefox langage : the langage is OK on the login page
but all the properties of my other pages crash
because of an error in

lastUserLogged = db(db.auth_event.description.contains('connect')).select(orderby=~db.auth_event.time_stamp,limitby=(0, 1)).first().user_id
or
lastUserName = db(db.auth_user.id == lastUserLogged).select(db.auth_user.username).first().username

because of the modification in Firefox ...

Dave S

unread,
Sep 19, 2020, 6:04:06 PM9/19/20
to web2py-users


On Monday, September 14, 2020 at 2:02:46 AM UTC-7, Nicolas Hiblot wrote:
Dear Clemens

Sorry for the late answer .. it was my birthday on sunday ...
Well,

My web2py  application has a combo box with a lot of languages for a langage choice
with a T.force(configuration.language)
so the user can change the langage of the web2py application : no problem

My problem is
On the login page : there is no translation because I use a web2py_user_form (no translation)
So the translation is made by Firefox and not by web2py (only for this page)


Do you use the T() function for your language-relevant strings?

 
If I change the Firefox langage : the langage is OK on the login page
but all the properties of my other pages crash
because of an error in

lastUserLogged = db(db.auth_event.description.contains('connect')).select(orderby=~db.auth_event.time_stamp,limitby=(0, 1)).first().user_id
or
lastUserName = db(db.auth_user.id == lastUserLogged).select(db.auth_user.username).first().username

because of the modification in Firefox ...


Does this generate tickets for the problems?  If so, please include the stack trace and relevant values from one of those tickets.

/dps
 
Reply all
Reply to author
Forward
0 new messages