[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:
@@ -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"/>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user