]> git.openstreetmap.org Git - rails.git/commitdiff
Move email-related methods to mixin
authorAnton Khorev <tony29@yandex.ru>
Fri, 1 Sep 2023 16:33:22 +0000 (19:33 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 2 Sep 2023 10:43:41 +0000 (13:43 +0300)
app/controllers/concerns/email_methods.rb [new file with mode: 0644]
app/controllers/users_controller.rb

diff --git a/app/controllers/concerns/email_methods.rb b/app/controllers/concerns/email_methods.rb
new file mode 100644 (file)
index 0000000..471a61e
--- /dev/null
@@ -0,0 +1,27 @@
+module EmailMethods
+  extend ActiveSupport::Concern
+
+  private
+
+  def canonical_email(email)
+    local_part, domain = if email.nil?
+                           nil
+                         else
+                           email.split("@")
+                         end
+
+    local_part.sub!(/\+.*$/, "")
+
+    local_part.delete!(".") if %w[gmail.com googlemail.com].include?(domain)
+
+    "#{local_part}@#{domain}"
+  end
+
+  ##
+  # get list of MX servers for a domains
+  def domain_mx_servers(domain)
+    Resolv::DNS.open do |dns|
+      dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect { |mx| mx.exchange.to_s }
+    end
+  end
+end
index 9d4b3d258cce6c098d288a39c7ae13d2743eaab0..5ba1b702bf9f2bc84d55c44d220fbcd59d62e46e 100644 (file)
@@ -1,4 +1,5 @@
 class UsersController < ApplicationController
 class UsersController < ApplicationController
+  include EmailMethods
   include SessionMethods
   include UserMethods
 
   include SessionMethods
   include UserMethods
 
@@ -361,26 +362,4 @@ class UsersController < ApplicationController
 
     !blocked
   end
 
     !blocked
   end
-
-  def canonical_email(email)
-    local_part, domain = if email.nil?
-                           nil
-                         else
-                           email.split("@")
-                         end
-
-    local_part.sub!(/\+.*$/, "")
-
-    local_part.delete!(".") if %w[gmail.com googlemail.com].include?(domain)
-
-    "#{local_part}@#{domain}"
-  end
-
-  ##
-  # get list of MX servers for a domains
-  def domain_mx_servers(domain)
-    Resolv::DNS.open do |dns|
-      dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect { |mx| mx.exchange.to_s }
-    end
-  end
 end
 end