implement imap authentication
authormh <mh@immerda.ch>
Mon, 2 May 2011 11:57:04 +0000 (13:57 +0200)
committermh <mh@immerda.ch>
Mon, 2 May 2011 12:10:36 +0000 (14:10 +0200)
We are now able to authenticate agains an imap server. A possible
setting would look like:

  authentication_method :imap, :imap_server => 'imap.example.com', \
    :imap_port => 993

lib/coquelicot/auth/imap.rb [new file with mode: 0644]
public/javascripts/coquelicot.auth.imap.js [new file with mode: 0644]
views/auth/imap.haml [new file with mode: 0644]

diff --git a/lib/coquelicot/auth/imap.rb b/lib/coquelicot/auth/imap.rb
new file mode 100644 (file)
index 0000000..99c638e
--- /dev/null
@@ -0,0 +1,16 @@
+require 'net/imap'
+module Coquelicot
+  module Auth
+    module Imap
+      def authenticate(params)
+        p = params['upload_token'].is_a?(Hash) ? params['upload_token'] : params
+        imap = Net::IMAP.new(settings.imap_server, settings.imap_port, true)
+        imap.login(p['imap_user'],p['imap_password'])
+        imap.logout
+        true
+      rescue
+        false
+      end
+    end
+  end
+end
\ No newline at end of file
diff --git a/public/javascripts/coquelicot.auth.imap.js b/public/javascripts/coquelicot.auth.imap.js
new file mode 100644 (file)
index 0000000..e321064
--- /dev/null
@@ -0,0 +1,10 @@
+function authenticationData(){
+       return {
+               imap_user: $('#imap_user').val(),
+               imap_password: $('#imap_password').val()
+       };
+}
+
+function authenticationFocus(){
+       $('#imap_user').focus();
+}
diff --git a/views/auth/imap.haml b/views/auth/imap.haml
new file mode 100644 (file)
index 0000000..780bcb1
--- /dev/null
@@ -0,0 +1,5 @@
+.field
+      %label{ :for => 'imap_user' } E-mail User:
+      %input.input{ :type => 'text', :id => 'imap_user', :name => 'imap_user' }
+      %label{ :for => 'imap_password' } Password:
+      %input.input{ :type => 'password', :id => 'imap_password', :name => 'imap_password' }      
\ No newline at end of file