Implement SMTP mailing and fix some bugs

This commit is contained in:
Eugene Burmakin 2025-04-15 21:34:02 +02:00
parent 0e8030121a
commit d6b5ce0549
8 changed files with 30 additions and 9 deletions

View file

@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
# 0.25.5 - 2025-04-13
# 0.25.5 - 2025-04-15
## Removed
@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `rake points:migrate_to_lonlat` task now also tries to extract latitude and longitude from `raw_data` column before using `longitude` and `latitude` columns to fill `lonlat` column.
- Docker entrypoints are now using `DATABASE_NAME` environment variable to check if Postgres is existing/available.
## Added
- You can now provide SMTP settings in ENV vars to send emails.
# 0.25.4 - 2025-04-02

View file

@ -2,6 +2,8 @@
class HomeController < ApplicationController
def index
# redirect_to 'https://dawarich.app', allow_other_host: true and return unless SELF_HOSTED
redirect_to map_url if current_user
@points = current_user.tracked_points.without_raw_data if current_user

View file

@ -1,4 +1,6 @@
# frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
default from: ENV['SMTP_FROM']
layout 'mailer'
end

View file

@ -18,7 +18,7 @@ class Points::RawDataLonlatExtractor
# rubocop:disable Metrics/MethodLength
def extract_lonlat(point)
if point.raw_data['activitySegment']['waypointPath']['waypoints'][0]
if point.raw_data.dig('activitySegment', 'waypointPath', 'waypoints', 0)
# google_semantic_history_parser
[
point.raw_data['activitySegment']['waypointPath']['waypoints'][0]['lngE7'].to_f / 10**7,
@ -30,7 +30,7 @@ class Points::RawDataLonlatExtractor
point.raw_data['longitudeE7'].to_f / 10**7,
point.raw_data['latitudeE7'].to_f / 10**7
]
elsif point.raw_data['position']['LatLng']
elsif point.raw_data.dig('position', 'LatLng')
# google phone export
raw_coordinates = point.raw_data['position']['LatLng']
if raw_coordinates.include?('°')
@ -41,7 +41,7 @@ class Points::RawDataLonlatExtractor
elsif point.raw_data['lon'] && point.raw_data['lat']
# gpx_track_importer, owntracks
[point.raw_data['lon'], point.raw_data['lat']]
elsif point.raw_data['geometry']['coordinates'][0] && point.raw_data['geometry']['coordinates'][1]
elsif point.raw_data.dig('geometry', 'coordinates', 0) && point.raw_data.dig('geometry', 'coordinates', 1)
# geojson
[
point.raw_data['geometry']['coordinates'][0],

View file

@ -5,7 +5,7 @@
</div>
<% end %>
<% if !SELF_HOSTED && devise_mapping&.registerable? && controller_name != 'registrations' %>
<% if !SELF_HOSTED && defined?(devise_mapping) && devise_mapping&.registerable? && controller_name != 'registrations' %>
<div class='my-2'>
<%= link_to "Register", new_registration_path(resource_name) %>
</div>

View file

@ -126,7 +126,7 @@
</li>
<% else %>
<li><%= link_to 'Login', new_user_session_path %></li>
<% if !SELF_HOSTED && devise_mapping&.registerable? %>
<% if !SELF_HOSTED && defined?(devise_mapping) && devise_mapping&.registerable? %>
<li><%= link_to 'Register', new_user_registration_path %></li>
<% end %>
<% end %>

View file

@ -107,4 +107,17 @@ Rails.application.configure do
config.action_mailer.default_url_options = { host: hosts.first, port: 3000 }
config.hosts.concat(hosts) if hosts.present?
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: ENV['SMTP_SERVER'],
port: ENV['SMTP_PORT'],
domain: ENV['SMTP_DOMAIN'],
user_name: ENV['SMTP_USERNAME'],
password: ENV['SMTP_PASSWORD'],
authentication: 'plain',
enable_starttls: true,
open_timeout: 5,
read_timeout: 5
}
end

View file

@ -24,7 +24,7 @@ Devise.setup do |config|
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
config.mailer_sender = ENV['SMTP_FROM']
# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'