summaryrefslogtreecommitdiff
path: root/certs/app
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-09-27 22:36:21 +0200
committerAzul <azul@riseup.net>2012-09-27 22:36:21 +0200
commit1208257bcc0e2a6648b68433a7b7e24791f92583 (patch)
treec676f2030bef20705e46421b478b7f9305bcf13e /certs/app
parente17a2a676e0ce585ef9eaa9077887bfe1bc1173f (diff)
adding in leap web certs - merging repos
Diffstat (limited to 'certs/app')
-rw-r--r--certs/app/assets/images/leap_web_certs/.gitkeep0
-rw-r--r--certs/app/assets/javascripts/leap_web_certs/.gitkeep0
-rw-r--r--certs/app/assets/stylesheets/leap_web_certs/.gitkeep0
-rw-r--r--certs/app/controllers/.gitkeep0
-rw-r--r--certs/app/controllers/certs_controller.rb9
-rw-r--r--certs/app/helpers/.gitkeep0
-rw-r--r--certs/app/helpers/certs_helper.rb2
-rw-r--r--certs/app/mailers/.gitkeep0
-rw-r--r--certs/app/models/.gitkeep0
-rw-r--r--certs/app/models/cert.rb57
-rw-r--r--certs/app/views/.gitkeep0
11 files changed, 68 insertions, 0 deletions
diff --git a/certs/app/assets/images/leap_web_certs/.gitkeep b/certs/app/assets/images/leap_web_certs/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/certs/app/assets/images/leap_web_certs/.gitkeep
diff --git a/certs/app/assets/javascripts/leap_web_certs/.gitkeep b/certs/app/assets/javascripts/leap_web_certs/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/certs/app/assets/javascripts/leap_web_certs/.gitkeep
diff --git a/certs/app/assets/stylesheets/leap_web_certs/.gitkeep b/certs/app/assets/stylesheets/leap_web_certs/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/certs/app/assets/stylesheets/leap_web_certs/.gitkeep
diff --git a/certs/app/controllers/.gitkeep b/certs/app/controllers/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/certs/app/controllers/.gitkeep
diff --git a/certs/app/controllers/certs_controller.rb b/certs/app/controllers/certs_controller.rb
new file mode 100644
index 0000000..6988a38
--- /dev/null
+++ b/certs/app/controllers/certs_controller.rb
@@ -0,0 +1,9 @@
+class CertsController < ApplicationController
+
+ # GET /cert
+ def show
+ @cert = Cert.pick_from_pool
+ render :text => @cert.zipped, :content_type => 'text/plain'
+ end
+
+end
diff --git a/certs/app/helpers/.gitkeep b/certs/app/helpers/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/certs/app/helpers/.gitkeep
diff --git a/certs/app/helpers/certs_helper.rb b/certs/app/helpers/certs_helper.rb
new file mode 100644
index 0000000..94e76b8
--- /dev/null
+++ b/certs/app/helpers/certs_helper.rb
@@ -0,0 +1,2 @@
+module CertsHelper
+end
diff --git a/certs/app/mailers/.gitkeep b/certs/app/mailers/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/certs/app/mailers/.gitkeep
diff --git a/certs/app/models/.gitkeep b/certs/app/models/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/certs/app/models/.gitkeep
diff --git a/certs/app/models/cert.rb b/certs/app/models/cert.rb
new file mode 100644
index 0000000..40efde9
--- /dev/null
+++ b/certs/app/models/cert.rb
@@ -0,0 +1,57 @@
+class Cert < CouchRest::Model::Base
+
+ use_database 'certs'
+
+ timestamps!
+
+ property :random, Float, :accessible => false
+
+ before_validation :set_random, :attach_zip, :on => :create
+
+ validates :random, :presence => true,
+ :numericality => {:greater_than => 0, :less_than => 1}
+
+ validates :zip_attachment, :presence => true
+
+ design do
+ view :by_random
+ end
+
+ class << self
+ def sample
+ self.by_random.startkey(rand).first || self.by_random.first
+ end
+
+ def pick_from_pool
+ cert = self.sample || self.create!
+ cert.destroy
+ return cert
+ rescue RESOURCE_NOT_FOUND
+ retry if Cert.by_random.count > 0
+ raise RECORD_NOT_FOUND
+ end
+
+ end
+
+ def set_random
+ self.random = rand
+ end
+
+ def attach_zip
+ file = File.open(Rails.root.join("config", "cert"))
+ self.create_attachment :file => file, :name => zipname
+ end
+
+ def zipname
+ 'cert.txt'
+ end
+
+ def zip_attachment
+ attachments[zipname]
+ end
+
+ def zipped
+ read_attachment(zipname)
+ end
+
+end
diff --git a/certs/app/views/.gitkeep b/certs/app/views/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/certs/app/views/.gitkeep