* Move frontend to root * Fix backend issues * Remove old routes * Setup Dockerfile * Fix today /tags multiplt requests issue * Fix race condition on today's inbox widget * Fix cors development issue * Fix CORS for Dockerfile * Fix dockerised settings for infinite loop * Fix translation issues * fixup! Fix translation issues --------- Co-authored-by: Your Name <you@example.com>
49 lines
1.2 KiB
Ruby
49 lines
1.2 KiB
Ruby
require 'json'
|
|
|
|
class Sinatra::Application
|
|
get '/api/current_user' do
|
|
content_type :json
|
|
|
|
if logged_in?
|
|
{ user: { email: current_user.email, id: current_user.id, language: current_user.language,
|
|
appearance: current_user.appearance, timezone: current_user.timezone } }.to_json
|
|
else
|
|
{ user: nil }.to_json
|
|
end
|
|
end
|
|
|
|
post '/api/login' do
|
|
content_type :json
|
|
request_payload = begin
|
|
JSON.parse(request.body.read)
|
|
rescue StandardError
|
|
nil
|
|
end
|
|
|
|
if request_payload
|
|
email = request_payload['email']
|
|
password = request_payload['password']
|
|
else
|
|
halt 400, { error: 'Invalid login parameters.' }.to_json
|
|
end
|
|
|
|
user = User.find_by(email: email)
|
|
if user&.authenticate(password)
|
|
session[:user_id] = user.id
|
|
status 200
|
|
{ user: { email: user.email, id: user.id, language: user.language, appearance: user.appearance,
|
|
timezone: user.timezone } }.to_json
|
|
else
|
|
halt 401, { errors: ['Invalid credentials'] }.to_json
|
|
end
|
|
end
|
|
|
|
get '/api/logout' do
|
|
session.clear
|
|
status 200
|
|
{ message: 'Logged out successfully' }.to_json
|
|
end
|
|
# session.clear
|
|
# redirect '/login'
|
|
# end
|
|
end
|