Set time zone on login
Should be more reliable.
This commit is contained in:
parent
d2e07630d5
commit
d55dc53ade
4 changed files with 13 additions and 20 deletions
12
vedia.rb
12
vedia.rb
|
|
@ -133,6 +133,7 @@ post '/login' do
|
|||
end
|
||||
session.clear
|
||||
session[:user_id] = user.id
|
||||
session[:timezone] = params[:timezone]
|
||||
redirect '/'
|
||||
else
|
||||
@error = _("Incorrect email or password.")
|
||||
|
|
@ -140,10 +141,6 @@ post '/login' do
|
|||
end
|
||||
end
|
||||
|
||||
post '/timezone' do
|
||||
session[:timezone] = JSON.parse(request.body.read)['timezone']
|
||||
end
|
||||
|
||||
get '/reset' do
|
||||
erb :reset
|
||||
end
|
||||
|
|
@ -641,12 +638,7 @@ helpers do
|
|||
end
|
||||
|
||||
def format_date(timestamp)
|
||||
if session[:timezone]
|
||||
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F')}"
|
||||
else
|
||||
# Otherwise, format_date fails on first page after login. Not sure why...
|
||||
"#{timestamp.strftime('%F')}"
|
||||
end
|
||||
"#{TZInfo::Timezone.get(session[:timezone]).to_local(timestamp).strftime('%F')}"
|
||||
end
|
||||
|
||||
def format_date_and_time(timestamp)
|
||||
|
|
|
|||
|
|
@ -15,15 +15,6 @@
|
|||
<link rel="stylesheet" href="/bootstrap-icons.css">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
</head>
|
||||
<script>
|
||||
fetch('/timezone', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone })
|
||||
});
|
||||
</script>
|
||||
<body>
|
||||
<div class="container py-4">
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<p class="alert alert-warning mb-4"><%= @error %></p>
|
||||
<% end %>
|
||||
|
||||
<form action="/login" method="post" class="mb-5">
|
||||
<form action="/login" name="login" method="post" class="mb-5">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label"><%= _("Email") %></label>
|
||||
<input type="text" name="email" class="form-control">
|
||||
|
|
@ -14,6 +14,11 @@
|
|||
<input type="password" name="password" class="form-control">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><%= _("Login") %></button>
|
||||
<input type="hidden" name="timezone" value="UTC">
|
||||
</form>
|
||||
<p><a href="/signup"><%= _("Create account") %></a></p>
|
||||
<p><a href="/reset"><%= _("Reset password") %></a></p>
|
||||
|
||||
<script>
|
||||
document.login.timezone.value = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -14,4 +14,9 @@
|
|||
<input type="password" name="password" class="form-control">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary"><%= _("Login") %></button>
|
||||
<input type="hidden" name="timezone" value="UTC">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.login.timezone.value = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue