[IMP] base,web: set user tz to browser tz at first login

With this commit, the timezone (in the user's preferences) is
automatically set to the timezone of its browser the first time
this user logs in.

Task 2207715

closes odoo/odoo#55726

Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
This commit is contained in:
Aaron Bohy
2020-08-12 09:23:02 +00:00
parent f8e0c92bf4
commit 6eb4762fee
2 changed files with 10 additions and 0 deletions
+6
View File
@@ -464,6 +464,12 @@
<xpath expr="//head/meta[last()]" position="after">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
</xpath>
<xpath expr="//head" position="inside">
<script type="text/javascript">
const userTZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
document.cookie = `tz=${userTZ}; path=/`;
</script>
</xpath>
<xpath expr="//head/link[last()]" position="after">
<t t-call-assets="web.assets_common" t-js="false"/>
<t t-call-assets="web.assets_frontend" t-js="false"/>
+4
View File
@@ -643,6 +643,10 @@ class Users(models.Model):
raise AccessDenied()
user = user.with_user(user)
user._check_credentials(password)
tz = request.httprequest.cookies.get('tz') if request else None
if tz in pytz.all_timezones and (not user.tz or not user.login_date):
# first login or missing tz -> set tz to browser tz
user.tz = tz
user._update_last_login()
except AccessDenied:
_logger.info("Login failed for db:%s login:%s from %s", db, login, ip)