Permalink
Browse files

Converted to engine

  • Loading branch information...
1 parent b108af4 commit 3df7b66e76d524d1e5bd04443a3b69ab8585d0af @alsmola committed Sep 4, 2012
Showing with 12,524 additions and 391 deletions.
  1. +1 −1 .rvmrc
  2. +0 −1 Gemfile
  3. +0 −12 Gemfile.lock
  4. +20 −0 MIT-LICENSE
  5. +2 −0 README.md → README.rdoc
  6. +37 −4 Rakefile
  7. 0 app/assets/{javascripts/bootstrap.js.coffee → images/nopassword/.gitkeep}
  8. +0 −2 app/assets/javascripts/{ → nopassword}/application.js
  9. +0 −67 app/assets/stylesheets/bootstrap_and_overrides.css.less
  10. 0 app/assets/stylesheets/{ → nopassword}/application.css
  11. +0 −14 app/controllers/application_controller.rb
  12. +4 −0 app/controllers/nopassword/application_controller.rb
  13. +13 −0 app/controllers/nopassword/check_session.rb
  14. +58 −0 app/controllers/nopassword/nopassword_controller.rb
  15. +0 −53 app/controllers/nopassword_controller.rb
  16. +0 −10 app/helpers/main_helper.rb
  17. +11 −0 app/helpers/nopassword/application_helper.rb
  18. +0 −19 app/mailers/no_password_emails.rb
  19. +21 −0 app/mailers/nopassword/no_password_emails.rb
  20. +0 −67 app/models/login_session.rb
  21. +69 −0 app/models/nopassword/login_session.rb
  22. +1 −1 app/views/{ → nopassword}/no_password_emails/no_password_email.html.erb
  23. +0 −6 config/boot.rb
  24. +0 −23 config/initializers/secrets.rb
  25. +5 −6 config/routes.rb
  26. +1 −1 db/migrate/20120412041547_create_login_codes.rb
  27. +1 −1 db/migrate/20120810233403_add_requesting_geo_to_login_sessions.rb
  28. +1 −1 db/migrate/20120810233418_add_activating_geo_to_login_sessions.rb
  29. +0 −7 db/seeds.rb
  30. +4 −0 lib/nopassword.rb
  31. +32 −0 lib/nopassword/engine.rb
  32. +3 −0 lib/nopassword/version.rb
  33. +4 −0 lib/tasks/nopassword_tasks.rake
  34. +22 −0 nopassword.gemspec
  35. BIN public/assets/application.css.gz
  36. +0 −19 public/assets/application.js
  37. BIN public/assets/application.js.gz
  38. +0 −6 public/assets/manifest.yml
  39. BIN public/assets/twitter/bootstrap/glyphicons-halflings-2ed0cba6eca0f44737ab78f1e58bc11e.png
  40. BIN public/assets/twitter/bootstrap/glyphicons-halflings-white-4fbb6a0b9b4e61912f486ac494a858f1.png
  41. BIN public/assets/twitter/bootstrap/glyphicons-halflings-white.png
  42. BIN public/assets/twitter/bootstrap/glyphicons-halflings.png
  43. +0 −5 public/robots.txt
  44. +5 −3 script/rails
  45. +1 −0 test/dummy/Gemfile
  46. +261 −0 test/dummy/README.rdoc
  47. +7 −0 test/dummy/Rakefile
  48. BIN { → test/dummy}/app/assets/images/rails.png
  49. 0 app/assets/javascripts/main.js → test/dummy/app/assets/javascripts/application.js
  50. +48 −0 test/dummy/app/assets/stylesheets/application.css
  51. +4 −0 test/dummy/app/controllers/application_controller.rb
  52. 0 { → test/dummy}/app/helpers/application_helper.rb
  53. 0 public/assets/application.css → test/dummy/app/mailers/.gitkeep
  54. 0 public/favicon.ico → test/dummy/app/models/.gitkeep
  55. +1 −1 {app/views/nopassword → test/dummy/app/views/application}/index.html.erb
  56. +5 −2 { → test/dummy}/app/views/layouts/application.html.erb
  57. +1 −1 { → test/dummy}/config.ru
  58. +4 −7 { → test/dummy}/config/application.rb
  59. +10 −0 test/dummy/config/boot.rb
  60. 0 { → test/dummy}/config/database.yml
  61. +14 −0 test/dummy/config/email.yml
  62. +1 −1 { → test/dummy}/config/environment.rb
  63. +2 −2 { → test/dummy}/config/environments/development.rb
  64. +1 −1 { → test/dummy}/config/environments/production.rb
  65. +1 −1 { → test/dummy}/config/environments/test.rb
  66. 0 { → test/dummy}/config/initializers/backtrace_silencers.rb
  67. 0 { → test/dummy}/config/initializers/inflections.rb
  68. 0 { → test/dummy}/config/initializers/mime_types.rb
  69. +7 −0 test/dummy/config/initializers/secret_token.rb
  70. +2 −2 { → test/dummy}/config/initializers/session_store.rb
  71. +1 −1 { → test/dummy}/config/initializers/wrap_parameters.rb
  72. 0 { → test/dummy}/config/locales/en.yml
  73. +1 −0 test/dummy/config/passwords/.passw3rd-encryptionIV
  74. +1 −0 test/dummy/config/passwords/.passw3rd-encryptionKey
  75. +1 −0 test/dummy/config/passwords/email_password
  76. +4 −0 test/dummy/config/routes.rb
  77. BIN test/dummy/db/development.sqlite3
  78. +19 −0 test/dummy/db/migrate/20120903014052_create_login_codes.nopassword.rb
  79. +7 −0 test/dummy/db/migrate/20120903014053_add_requesting_geo_to_login_sessions.nopassword.rb
  80. +7 −0 test/dummy/db/migrate/20120903014054_add_activating_geo_to_login_sessions.nopassword.rb
  81. +2 −2 { → test/dummy}/db/schema.rb
  82. BIN test/dummy/db/test.sqlite3
  83. 0 test/{fixtures/login_sessions.yml → dummy/lib/assets/.gitkeep}
  84. 0 test/dummy/log/.gitkeep
  85. +8,844 −0 test/dummy/log/development.log
  86. +2,912 −0 test/dummy/log/test.log
  87. 0 { → test/dummy}/public/404.html
  88. 0 { → test/dummy}/public/422.html
  89. 0 { → test/dummy}/public/500.html
  90. BIN test/dummy/public/assets/rails.png
  91. 0 test/dummy/public/favicon.ico
  92. +6 −0 test/dummy/script/rails
  93. BIN test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953
  94. BIN test/dummy/tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016
  95. BIN test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705
  96. BIN test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
  97. BIN test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6
  98. BIN test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
  99. BIN test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
  100. BIN test/dummy/tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6
  101. +1 −0 test/dummy/tmp/pids/server.pid
  102. +8 −0 test/functional/nopassword/nopassword_controller_test.rb
  103. +0 −8 test/functional/nopassword_controller_test.rb
  104. +4 −1 test/{functional/login_test.rb → integration/navigation_test.rb}
  105. +6 −6 test/{unit → }/login_session_test.rb
  106. +8 −0 test/nopassword_test.rb
  107. +0 −12 test/performance/browsing_test.rb
  108. +7 −10 test/test_helper.rb
  109. +0 −4 test/unit/helpers/main_helper_test.rb
View
2 .rvmrc
@@ -1 +1 @@
-rvm use --create ruby-1.9.2-p320@nopassword
+rvm use --create ruby-1.9.3-p0@nopassword
View
@@ -9,7 +9,6 @@ group :assets do
gem 'coffee-rails', '~> 3.2.1'
gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
- gem 'twitter-bootstrap-rails'
end
gem 'jquery-rails'
gem 'bcrypt-ruby', '~> 3.0.0'
View
@@ -39,7 +39,6 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.1)
- commonjs (0.2.6)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
@@ -51,11 +50,6 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.6)
- less (2.2.1)
- commonjs (~> 0.2.6)
- less-rails (2.2.3)
- actionpack (>= 3.1)
- less (~> 2.2.0)
libv8 (3.3.10.4)
mail (2.4.4)
i18n (>= 0.4.0)
@@ -107,11 +101,6 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- twitter-bootstrap-rails (2.1.0)
- actionpack (>= 3.1)
- less-rails (~> 2.2.2)
- railties (>= 3.1)
- therubyracer (~> 0.10.1)
tzinfo (0.3.33)
uglifier (1.2.4)
execjs (>= 0.3.0)
@@ -131,5 +120,4 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
sqlite3
therubyracer
- twitter-bootstrap-rails
uglifier (>= 1.0.3)
View
@@ -0,0 +1,20 @@
+Copyright 2012 YOURNAME
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -2,3 +2,5 @@ NoPassword is a simple authentication and session engine that removes
the need for passwords. Instead, it uses tokens sent to an email
address, similar to most forgot password functionality. These tokens
created long-lived sessions that can be tracked and revoked easily.
+
+This project uses the MIT-LICENSE.
View
@@ -1,7 +1,40 @@
#!/usr/bin/env rake
-# Add your own tasks in files placed in lib/tasks ending in .rake,
-# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
+end
-require File.expand_path('../config/application', __FILE__)
+RDoc::Task.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Nopassword'
+ rdoc.options << '--line-numbers'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
-Nopassword::Application.load_tasks
+APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
+load 'rails/tasks/engine.rake'
+
+
+
+Bundler::GemHelper.install_tasks
+
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+
+task :default => :test
@@ -13,5 +13,3 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
-//= require twitter/bootstrap
-//= require main
@@ -1,67 +0,0 @@
-@import "twitter/bootstrap/bootstrap";
-body {
- padding-top: 60px;
- padding-left: 20px;
-}
-
-@import "twitter/bootstrap/responsive";
-
-// Set the correct sprite paths
-@iconSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings.png');
-@iconWhiteSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings-white.png');
-
-// Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines)
-// Note: If you use asset_path() here, your compiled boostrap_and_overrides.css will not
-// have the proper paths. So for now we use the absolute path.
-@fontAwesomeEotPath: '/assets/fontawesome-webfont.eot';
-@fontAwesomeWoffPath: '/assets/fontawesome-webfont.woff';
-@fontAwesomeTtfPath: '/assets/fontawesome-webfont.ttf';
-@fontAwesomeSvgPath: '/assets/fontawesome-webfont.svg';
-
-// Font Awesome
-@import "fontawesome";
-
-// Your custom LESS stylesheets goes here
-#send-login-email form {
- padding: 20px;
- background-color: gray;
- margin-top: 40px;
- margin-bottom: 40px;
- border-radius: 10px;
- border: 5px solid white;
- -moz-box-shadow: 0 0 2px 2px #888;
- -webkit-box-shadow: 0 2px 2px #888;
- box-shadow: 0 0 2px 2px #888;
-}
-
-#send-login-email input {
- font-size: 200%;
- line-height: 1em;
- height: 1.5em;
- width: 12em;
- margin-right: .5em;
-}
-
-.big {
- font-size: 18px;
- line-height: 24px;
-}
-
-.highlight td {
- background-color: #049cdb !important;
- color: white;
- font-weight: bold;
-}
-
-.table-sessions {
- width: auto;
- margin: auto;
-}
-
-.table-sessions button {
- min-width: 6em;
-}
-
-.logout {
- margin: 0;
-}
@@ -1,14 +0,0 @@
-class ApplicationController < ActionController::Base
- protect_from_forgery
- before_filter :check_valid_session
-
- def check_valid_session
- if session[:login_session]
- @current_session = LoginSession.find_by_id(session[:login_session])
- if !@current_session.active?
- session[:login_session] = nil
- redirect_to '/'
- end
- end
- end
-end
@@ -0,0 +1,4 @@
+module Nopassword
+ class ApplicationController < ActionController::Base
+ end
+end
@@ -0,0 +1,13 @@
+module Nopassword
+ module CheckSession
+ def check_valid_session
+ if session[:login_session]
+ @current_session = Nopassword::LoginSession.find_by_id(session[:login_session])
+ if !@current_session.active?
+ session[:login_session] = nil
+ redirect_to '/'
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,58 @@
+module Nopassword
+ class NopasswordController < ApplicationController
+ include CheckSession
+
+ EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/
+
+ before_filter :check_valid_session
+
+ def send_login_email
+ redirect_to '/' if !request.post?
+ email = request[:email]
+ remote_ip = request.remote_ip
+ user_agent = request.env["HTTP_USER_AGENT"]
+ host = request.host
+ if email =~ EMAIL_REGEX
+ LoginSession.create_session(email, remote_ip, user_agent, host)
+ flash[:notice] = "We sent an email to %{email}" % { :email => email }
+ else
+ flash[:notice] = "That doesn't look like a valid email address"
+ end
+ redirect_to '/'
+ end
+
+ def login
+ id = request[:id]
+ code = request[:code]
+ remote_ip = request.remote_ip
+ user_agent = request.env["HTTP_USER_AGENT"]
+ login_session = LoginSession.find_by_id(id)
+ if !login_session
+ flash[:notice] = "That's not a valid login link."
+ elsif login_session.activated? || login_session.terminated?
+ flash[:notice] = "That code is already used."
+ elsif login_session.expired?
+ flash[:notice] = "That code is old as shit."
+ elsif !login_session.activate_session(code, remote_ip, user_agent)
+ flash[:notice] = "That code sucked."
+ else
+ session[:login_session] = login_session.id
+ end
+ redirect_to '/'
+ end
+
+ def logout
+ @current_session.logout
+ session[:login_session] = nil
+ redirect_to '/'
+ end
+
+ def revoke
+ id = request[:id]
+ ls = LoginSession.find_by_id(id)
+ render :json => { :success => :false } unless ls
+ result = @current_session.revoke(ls)
+ render :json => { :success => !!result }
+ end
+ end
+end
@@ -1,53 +0,0 @@
-class NopasswordController < ApplicationController
-
- EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/
-
- def send_login_email
- redirect_to '/' if !request.post?
- email = request[:email]
- remote_ip = request.remote_ip
- user_agent = request.env["HTTP_USER_AGENT"]
- host = request.host
- if email =~ EMAIL_REGEX
- LoginSession.create_session(email, remote_ip, user_agent, host)
- flash[:notice] = "We sent an email to %{email}" % { :email => email }
- else
- flash[:notice] = "That doesn't look like a valid email address"
- end
- redirect_to '/'
- end
-
- def login
- id = request[:id]
- code = request[:code]
- remote_ip = request.remote_ip
- user_agent = request.env["HTTP_USER_AGENT"]
- login_session = LoginSession.find_by_id(id)
- if !login_session
- flash[:notice] = "That's not a valid login link."
- elsif login_session.activated? || login_session.terminated?
- flash[:notice] = "That code is already used."
- elsif login_session.expired?
- flash[:notice] = "That code is old as shit."
- elsif !login_session.activate_session(code, remote_ip, user_agent)
- flash[:notice] = "That code sucked."
- else
- session[:login_session] = login_session.id
- end
- redirect_to '/'
- end
-
- def logout
- @current_session.logout
- session[:login_session] = nil
- redirect_to '/'
- end
-
- def revoke
- id = request[:id]
- ls = LoginSession.find_by_id(id)
- render :json => { :success => :false } unless ls
- result = @current_session.revoke(ls)
- render :json => { :success => !!result }
- end
-end
View
@@ -1,10 +0,0 @@
-require 'browser'
-module MainHelper
- def active_sessions
- @current_session.active_sessions
- end
-
- def inactive_sessions
- @current_session.inactive_sessions
- end
-end
@@ -0,0 +1,11 @@
+module Nopassword
+ module ApplicationHelper
+ def friendly_time(time)
+ time_ago_in_words(time) + " ago"
+ end
+
+ def browser_name(ua)
+ Browser.new(:ua => ua).to_s.split(' ')[0].capitalize
+ end
+ end
+end
@@ -1,19 +0,0 @@
-class NoPasswordEmails < ActionMailer::Base
- include ApplicationHelper
-
- default :from => 'nopassword@alexsmolen.com',
- :return_path => 'nopassword@alexsmolen.com'
-
- def no_password_email(email, id, time, remote_ip, user_agent, geo, code, host)
- @id = id
- @time = time.strftime("%e %b %Y %H:%m")
- @remote_ip = remote_ip
- @user_agent = browser_name(user_agent)
- @geo = geo
- @code = code
- @email = email
- @host = host
- mail(:to => email,
- :subject => "Login request from #{host}")
- end
-end
Oops, something went wrong.

0 comments on commit 3df7b66

Please sign in to comment.