frame 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/Gemfile.lock +8 -1
  2. data/Rakefile +11 -0
  3. data/lib/generators/frame.rb +3 -3
  4. data/lib/generators/frame/admin/admin_generator.rb +6 -3
  5. data/lib/generators/frame/admin/templates/{pages.rb → app/admin/pages.rb} +0 -0
  6. data/lib/generators/frame/admin/templates/{pages_controller.rb → app/controllers/pages_controller.rb} +1 -1
  7. data/lib/generators/frame/admin/templates/{show.html.erb → app/views/pages/show.html.erb} +0 -0
  8. data/lib/generators/frame/devise/devise_generator.rb +17 -17
  9. data/lib/generators/frame/{omniauth/templates → devise/templates/app/views/layouts}/defaults.html.erb +1 -0
  10. data/lib/generators/frame/layout/layout_generator.rb +8 -14
  11. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_128.gif +0 -0
  12. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_128.png +0 -0
  13. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_16.gif +0 -0
  14. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_16.png +0 -0
  15. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_256.gif +0 -0
  16. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_256.png +0 -0
  17. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_32.gif +0 -0
  18. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_32.png +0 -0
  19. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_32_loading.gif +0 -0
  20. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_64.gif +0 -0
  21. data/lib/generators/frame/layout/templates/app/assets/images/econ_f_64.png +0 -0
  22. data/lib/generators/frame/layout/templates/app/assets/images/favicon.ico +0 -0
  23. data/lib/generators/frame/layout/templates/{application_helper.rb → app/helpers/application_helper.rb} +1 -1
  24. data/lib/generators/frame/layout/templates/{frame.css → app/stylesheets/frame.css} +0 -0
  25. data/lib/generators/frame/layout/templates/{application.html.erb → app/views/layouts/application.html.erb} +0 -0
  26. data/lib/generators/frame/layout/templates/{default_layout.html.erb → app/views/layouts/default_layout.html.erb} +0 -0
  27. data/lib/generators/frame/layout/templates/{defaults.html.erb → app/views/layouts/defaults.html.erb} +0 -0
  28. data/lib/generators/frame/omniauth/omniauth_generator.rb +76 -65
  29. data/lib/generators/frame/omniauth/templates/app/assets/images/facebook_32.png +0 -0
  30. data/lib/generators/frame/omniauth/templates/app/assets/images/facebook_64.png +0 -0
  31. data/lib/generators/frame/omniauth/templates/app/assets/images/github_32.png +0 -0
  32. data/lib/generators/frame/omniauth/templates/app/assets/images/github_64.png +0 -0
  33. data/lib/generators/frame/omniauth/templates/app/assets/images/google_32.png +0 -0
  34. data/lib/generators/frame/omniauth/templates/app/assets/images/google_64.png +0 -0
  35. data/lib/generators/frame/omniauth/templates/app/assets/images/twitter_32.png +0 -0
  36. data/lib/generators/frame/omniauth/templates/app/assets/images/twitter_64.png +0 -0
  37. data/lib/generators/frame/omniauth/templates/app/controllers/authentications_controller.rb +54 -0
  38. data/lib/generators/frame/omniauth/templates/app/controllers/registrations_controller.rb +23 -0
  39. data/lib/generators/frame/omniauth/templates/app/models/user.rb +54 -0
  40. data/lib/generators/frame/omniauth/templates/app/views/authentications/index.html.erb +13 -0
  41. data/lib/generators/frame/omniauth/templates/app/views/devise/sessions/new.html.erb +11 -0
  42. data/lib/generators/frame/omniauth/templates/app/views/registrations/edit.html.erb +47 -0
  43. data/lib/generators/frame/omniauth/templates/app/views/registrations/new.html.erb +25 -0
  44. data/lib/generators/frame/omniauth/templates/app/views/shared/_login_form.html.erb +14 -0
  45. data/lib/generators/frame/omniauth/templates/app/views/shared/_open_auth.html.erb +39 -0
  46. data/lib/generators/frame/omniauth/templates/config/initializers/omniauth.rb +13 -0
  47. data/lib/generators/frame/pages/pages_generator.rb +1 -1
  48. data/lib/generators/frame/secret/secret_generator.rb +5 -0
  49. data/lib/generators/frame/secret/templates/Rakefile +39 -0
  50. metadata +74 -16
  51. data/lib/generators/frame/devise/templates/defaults.html.erb +0 -47
  52. data/lib/generators/frame/layout/templates/econ64.gif +0 -0
  53. data/lib/generators/frame/layout/templates/favicon.ico +0 -0
  54. data/lib/generators/frame/omniauth/templates/omniauth.rb +0 -6
  55. data/lib/generators/frame/omniauth/templates/omniauth_callbacks_controller.rb +0 -38
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- frame (0.0.4)
4
+ frame (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -136,6 +136,11 @@ GEM
136
136
  omniauth (1.0.0)
137
137
  hashie (~> 1.2)
138
138
  rack
139
+ omniauth-facebook (1.4.0)
140
+ omniauth-oauth2 (~> 1.0.2)
141
+ omniauth-github (1.0.1)
142
+ omniauth (~> 1.0)
143
+ omniauth-oauth2 (~> 1.0)
139
144
  omniauth-google-oauth2 (0.1.7)
140
145
  omniauth (~> 1.0)
141
146
  omniauth-oauth2
@@ -234,6 +239,8 @@ DEPENDENCIES
234
239
  mysql2
235
240
  oauth2
236
241
  omniauth
242
+ omniauth-facebook
243
+ omniauth-github
237
244
  omniauth-google-oauth2
238
245
  omniauth-twitter
239
246
  rails (= 3.2.8)
data/Rakefile CHANGED
@@ -17,3 +17,14 @@ end
17
17
 
18
18
  desc "Run tests"
19
19
  task :default => :test
20
+
21
+ task :build_gem do
22
+ gem_version = ''
23
+ STDOUT.puts "What is the gem version (x.x.x)?"
24
+ gem_version = STDIN.gets.chomp
25
+ #gem_version = ask("What is the gem version (x.x.x)?")
26
+ system("gem build frame.gemspec")
27
+ system("gem push frame-#{gem_version}.gem")
28
+ system("git tag -a v#{gem_version} -m 'version #{gem_version}'")
29
+ system("git push --tags")
30
+ end
@@ -7,9 +7,9 @@ module Frame
7
7
  @_frame_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'frame', generator_name, 'templates'))
8
8
  end
9
9
 
10
- #def self.banner
11
- # "rails generate frame:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
- #end
10
+ def self.banner
11
+ "rails generate frame:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
+ end
13
13
 
14
14
  private
15
15
 
@@ -8,6 +8,9 @@ module Frame
8
8
 
9
9
  desc "Installs Active Admin."
10
10
 
11
+ # Need to seed the production environment with:
12
+ #AdminUser.create!(:email=>'test@test.com',:username=>'test',:password=>'password')
13
+
11
14
  def add_gems
12
15
  add_gem("sass-rails", :group => "test")
13
16
  add_gem("meta_search", :group => "test")
@@ -32,11 +35,11 @@ module Frame
32
35
  end
33
36
 
34
37
  def update_admin_form
35
- template 'pages.rb', 'app/admin/pages.rb'
38
+ template('app/admin/pages.rb')
36
39
  end
37
40
 
38
41
  def update_pages_controller
39
- template 'pages_controller.rb', 'app/controller/pages_controller.rb'
42
+ template('app/controllers/pages_controller.rb')
40
43
  end
41
44
 
42
45
  def cleanup_page_routes
@@ -52,7 +55,7 @@ module Frame
52
55
  remove_file filename
53
56
  end
54
57
  }
55
- template 'show.html.erb', 'app/views/pages/show.html.erb'
58
+ template('app/views/pages/show.html.erb')
56
59
  end
57
60
 
58
61
  private
@@ -15,7 +15,7 @@ class PagesController < ApplicationController
15
15
  format.html
16
16
  format.json { render json: @page }
17
17
  else
18
- format.html { redirect_to action: 'new' }
18
+ format.html { redirect_to :admin_root }
19
19
  format.json { render json: @page.errors, status: :unprocessable_entity }
20
20
  end
21
21
 
@@ -26,31 +26,25 @@ module Frame
26
26
  end
27
27
  end
28
28
 
29
- #def update_initializers
30
- # gsub_file 'config/initializers/devise.rb', /config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"/ do
31
- # default_mailer = "webmaster@proj_name.com"
32
- # mailer_sender = ask("What is the mail sender address? [#{default_mailer}]")
33
- # mailer_sender = default_mailer if mailer_sender.blank?
34
- # "config.mailer_sender = \"#{mailer_sender}\""
35
- # end
36
- #end
29
+ def update_initializers
30
+ gsub_file 'config/initializers/devise.rb', /config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"/ do
31
+ default_mailer = "webmaster@econtriver.com"
32
+ mailer_sender = ask("What is the mail sender address? [#{default_mailer}]")
33
+ mailer_sender = default_mailer if mailer_sender.blank?
34
+ "config.mailer_sender = \"#{mailer_sender}\""
35
+ end
36
+ end
37
37
 
38
38
  def add_default_layout
39
39
  template 'defaults.html.erb', 'app/views/layouts/defaults.html.erb'
40
40
  end
41
41
 
42
- def update_db
43
- if yes?("Would you like to migrate the database?")
44
- rake("db:migrate")
45
- end
46
- end
47
-
48
42
 
49
- private
43
+ #private
50
44
 
51
45
 
52
- def update_environmentss
53
- default_mailer = "proj_name.com"
46
+ def update_environments
47
+ default_mailer = "econtriver.com"
54
48
  action_mailer = ask("What is the action mailer domain (normally just the domain)? [#{default_mailer}]")
55
49
  action_mailer = default_mailer if action_mailer.blank?
56
50
  application(nil, :env => "production") do
@@ -64,6 +58,12 @@ module Frame
64
58
  end
65
59
  end
66
60
 
61
+ def update_db
62
+ if yes?("Would you like to migrate the database?")
63
+ rake("db:migrate")
64
+ end
65
+ end
66
+
67
67
  end
68
68
  end
69
69
  end
@@ -15,6 +15,7 @@
15
15
  <li class="right last lighter"><%%= current_user.email %></li>
16
16
  <%% else %>
17
17
  <%%= link_to '<li class="right hover">Sign in</li>'.html_safe, user_session_path %>
18
+ <%%= link_to '<li class="right hover">Sign up</li>'.html_safe, new_user_registration_path %>
18
19
  <%% end %>
19
20
  </ul>
20
21
  </nav>
@@ -10,40 +10,34 @@ module Frame
10
10
 
11
11
  class_option :force, :type => :boolean, :default => false, :desc => "Force file regeneration"
12
12
 
13
- #def add_gems
14
- # add_gem "mysql2"
15
- #end
16
- #Frame.Generators.PagesGenerator.add_gems
17
-
18
13
  def remove_index
19
14
  filename="public/index.html"
20
- if File.exists?("filename") and yes?("Would you like to remove '#{filename}'?")
15
+ if File.exists?(filename) and yes?("Would you like to remove '#{filename}'?")
21
16
  remove_file filename
22
17
  end
23
18
  end
24
- #Frame.Generators.PagesGenerator.remove_index
25
19
 
26
20
  def add_default_layout
27
- template 'defaults.html.erb', 'app/views/layouts/defaults.html.erb'
28
- template 'default_layout.html.erb', 'app/views/layouts/default_layout.html.erb'
21
+ template('app/views/layouts/defaults.html.erb')
22
+ template('app/views/layouts/default_layout.html.erb')
29
23
  end
30
24
 
31
25
  def add_page_helpers
32
- template 'application_helper.rb', 'app/helpers/application_helper.rb'
26
+ template('app/helpers/application_helper.rb')
33
27
  end
34
28
 
35
29
  def add_images
36
- template 'econ64.gif', 'app/assets/images/econ64.gif'
37
- template 'favicon.ico', 'app/assets/images/favicon.ico'
30
+ template('app/assets/images/econ_f_64.gif')
31
+ template('app/assets/images/favicon.ico')
38
32
  end
39
33
 
40
34
  def replace_html_app
41
35
  @title = Rails.application.class.parent_name
42
- template 'application.html.erb', 'app/views/layouts/application.html.erb'
36
+ template('app/views/layouts/application.html.erb')
43
37
  end
44
38
 
45
39
  def copy_css
46
- template 'frame.css', 'app/assets/stylesheets/frame.css'
40
+ template('app/assets/stylesheets/frame.css')
47
41
  add_if_missing('app/assets/stylesheets/application.css', " *= require frame\n", :after => " *= require_self\n")
48
42
  end
49
43
 
@@ -7,6 +7,6 @@ module ApplicationHelper
7
7
  end
8
8
 
9
9
  def logo
10
- image_tag("econ64.gif", {:alt => "eContriver", :class => "round", :style => "width: 64px; height: 64px"})
10
+ image_tag("econ_f_64.gif", {:alt => "eContriver", :class => "round", :style => "width: 64px; height: 64px"})
11
11
  end
12
12
  end
@@ -1,88 +1,99 @@
1
1
  require 'generators/frame'
2
2
  require 'rails/generators/migration'
3
- #require "omniauth-twitter"
4
3
 
5
4
  module Frame
6
5
  module Generators
7
6
  class OmniauthGenerator < Base
8
7
  include Rails::Generators::Migration
9
8
 
10
- desc "Installs Devises Omniauth."
9
+ desc "Installs Omniauth."
11
10
 
12
11
  def install_omniauth
12
+
13
13
  gem 'omniauth'
14
- gem 'oauth2'
15
14
  gem 'omniauth-twitter'
16
15
  gem 'omniauth-google-oauth2'
16
+ gem 'omniauth-github'
17
17
 
18
18
  Bundler.with_clean_env do
19
19
  run "bundle"
20
20
  end
21
+ end
21
22
 
22
- generate("migration AddColumnsToUsers provider:string uid:string")
23
- uncomment_lines('config/initializers/session_store.rb', "Tester::Application.config.session_store :active_record_store")
24
- generate("session_migration")
25
- rake("db:migrate")
26
-
27
- add_if_missing('app/models/user.rb', ":provider, :uid,", :after => " attr_accessible ")
28
- add_if_missing('app/models/user.rb', ":omniauthable, ", :after => " devise ")
29
-
30
- add_if_missing('config/routes.rb', ", :controllers => { :omniauth_callbacks => \"users/omniauth_callbacks\" }", :after => " devise_for :users")
31
-
32
- template 'omniauth.rb', 'config/initializers/omniauth.rb'
33
- template 'omniauth_callbacks_controller.rb', 'app/controllers/users/omniauth_callbacks_controller.rb'
34
-
35
- add_if_missing('app/models/user.rb', '
36
- def self.find_for_twitter_oauth(auth, signed_in_resource=nil)
37
- Rails.logger.debug "(DEBUG) auth: #{auth.to_yaml}"
38
- user = User.where(:provider => auth.provider, :uid => auth.uid).first
39
- unless user
40
- #name:auth.extra.raw_info.name,
41
- user = User.create(
42
- provider:auth.provider,
43
- uid:auth.uid,
44
- email:auth.info.email,
45
- password:Devise.friendly_token[0,20]
46
- )
47
- end
48
- user
49
- end', :before => "\nend")
50
-
51
- add_if_missing('app/models/user.rb', '
52
- def self.find_for_google_oauth(auth, signed_in_resource=nil)
53
- Rails.logger.debug "(DEBUG) auth: #{auth.to_yaml}"
54
- user = User.where(:provider => auth.provider, :uid => auth.uid).first
55
- unless user
56
- #name:auth.extra.raw_info.name,
57
- user = User.create(
58
- provider:auth.provider,
59
- uid:auth.uid,
60
- email:auth.info.email,
61
- password:Devise.friendly_token[0,20]
62
- )
63
- end
64
- user
65
- end', :before => "\nend")
66
-
67
- add_if_missing('Rakefile', "
68
- files = ['config/initializers/omniauth.rb','config/database.yml','config/initializers/secret_token.rb']
69
-
70
- domain = \"#{Rails.application.class.parent_name.downcase}.econtriver.com\"
71
- set :user, \"root\" # The server's user for deploys
72
- set :deploy_to, \"/srv/www/\#{domain}\"
73
-
74
- task :put_secret do
75
- files.each do |f|
76
- system(\"scp \#{f} \#{user}@\#{domain}:\#{File.join(deploy_to,'private',f)}\")
77
- end
78
- end
23
+ def direct_devise_to_registrations
24
+ add_if_missing('config/routes.rb', ", :controllers => {:registrations => 'registrations'}", :after => "devise_for :users")
25
+ end
79
26
 
80
- task :get_secret do
81
- files.each do |f|
82
- system(\"scp \#{user}@\#{domain}:\#{File.join(deploy_to,'private',f)} \#{f}\")
83
- end
84
- end", :after => "Tester::Application.load_tasks\n")
27
+ def generate_authentication_model
28
+ generate("model authentication user_id:integer provider:string uid:string")
29
+ add_if_missing('app/models/authentication.rb', "
30
+ belongs_to :user
31
+
32
+ def provider_name
33
+ if provider == 'open_id'
34
+ 'OpenID'
35
+ elsif provider == 'google_oauth2'
36
+ 'Google'
37
+ else
38
+ provider.titleize
39
+ end
40
+ end\n", :after => "class Authentication < ActiveRecord::Base\n")
41
+ end
42
+
43
+ # Leave the routes?
44
+ def generate_authentication_controller
45
+ generate('controller Authentications index create destroy')
46
+ template('app/controllers/authentications_controller.rb')
47
+ remove_file('app/views/authentications/index.html.erb')
48
+ remove_file('app/views/authentications/create.html.erb')
49
+ remove_file('app/views/authentications/destroy.html.erb')
50
+ # Need this index?
51
+ template('app/views/authentications/index.html.erb')
52
+ end
53
+
54
+ def generate_registration_controller
55
+ generate('controller Registrations edit new')
56
+ template('app/views/registrations/edit.html.erb')
57
+ template('app/views/registrations/new.html.erb')
58
+ template('app/controllers/registrations_controller.rb')
59
+ end
85
60
 
61
+ def add_routes
62
+ add_if_missing('config/routes.rb', "
63
+ match '/auth/failure' => 'authentications#failure'
64
+ match '/auth/:provider/callback' => 'authentications#create'
65
+ ", :after => "get \"authentications/destroy\"\n")
66
+ end
67
+
68
+ def add_username_to_user
69
+ generate("migration AddUsernameToUser username:string")
70
+ end
71
+
72
+ def update_user_model
73
+ template('app/models/user.rb')
74
+ end
75
+
76
+ def copy_images
77
+ template('app/assets/images/facebook_32.png')
78
+ template('app/assets/images/github_32.png')
79
+ template('app/assets/images/google_32.png')
80
+ template('app/assets/images/twitter_32.png')
81
+ template('app/assets/images/facebook_64.png')
82
+ template('app/assets/images/github_64.png')
83
+ template('app/assets/images/google_64.png')
84
+ template('app/assets/images/twitter_64.png')
85
+ end
86
+
87
+ def add_sign_in_to_devise
88
+ template('app/views/devise/sessions/new.html.erb')
89
+ template('app/views/shared/_open_auth.html.erb')
90
+ template('app/views/shared/_login_form.html.erb')
91
+ end
92
+
93
+ def update_db
94
+ if yes?("Would you like to migrate the database?")
95
+ rake("db:migrate")
96
+ end
86
97
  end
87
98
 
88
99
  end
@@ -0,0 +1,54 @@
1
+ class AuthenticationsController < ApplicationController
2
+ def index
3
+ @authentications = current_user.authentications if current_user
4
+ end
5
+
6
+ def create
7
+ omniauth = request.env["omniauth.auth"]
8
+ authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
9
+ if authentication
10
+ flash[:info] = "Signed in successfully."
11
+ sign_in_and_redirect(:user, authentication.user)
12
+ elsif current_user
13
+ current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
14
+ flash[:info] = "Authentication successful."
15
+ redirect_to authentications_url
16
+ else
17
+ user = User.new
18
+ user.apply_omniauth(omniauth)
19
+ if user.save
20
+ flash[:info] = "Signed in successfully."
21
+ sign_in_and_redirect(:user, user)
22
+ else
23
+ session[:omniauth] = omniauth.except('extra')
24
+ redirect_to new_user_registration_url
25
+ end
26
+ end
27
+ end
28
+
29
+ def failure
30
+ flash[:error] = "There was a problem authenticating with the selected service."
31
+ redirect_to new_user_registration_url
32
+ end
33
+
34
+ def destroy
35
+ if ( current_user.authentications.count == 1 && current_user.encrypted_password.empty? )
36
+ flash[:error] = "You must first set a password on the <a href=\"#{edit_user_registration_path}\">preferences page</a>".html_safe
37
+ else
38
+ @authentication = current_user.authentications.find(params[:id])
39
+ @authentication.destroy
40
+ flash[:success] = "Successfully destroyed authentication."
41
+ end
42
+ redirect_to authentications_url
43
+ end
44
+
45
+ protected
46
+
47
+ # This is necessary since Rails 3.0.4
48
+ # See https://github.com/intridea/omniauth/issues/185
49
+ # and http://www.arailsdemo.com/posts/44
50
+ def handle_unverified_request
51
+ true
52
+ end
53
+
54
+ end
@@ -0,0 +1,23 @@
1
+ class RegistrationsController < Devise::RegistrationsController
2
+
3
+ def create
4
+ super
5
+ session[:omniauth] = nil unless @user.new_record?
6
+ end
7
+
8
+ def edit
9
+ @authentications = current_user.authentications if current_user
10
+ super
11
+ end
12
+
13
+ private
14
+
15
+ def build_resource(*args)
16
+ super
17
+ if session[:omniauth]
18
+ @user.apply_omniauth(session[:omniauth])
19
+ @user.valid?
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,54 @@
1
+ class User < ActiveRecord::Base
2
+ validates :username, :presence => true, :uniqueness => true
3
+
4
+ # Include default devise modules. Others available are:
5
+ # :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
6
+ devise :database_authenticatable, :registerable,
7
+ :recoverable, :rememberable, :trackable, :validatable
8
+
9
+ has_many :authentications, :dependent => :destroy
10
+
11
+ attr_accessor :login
12
+ attr_accessible :email, :password, :password_confirmation, :username, :login, :remember_me
13
+
14
+ def self.find_for_authentication(warden_conditions)
15
+ conditions = warden_conditions.dup
16
+ login = conditions.delete(:login)
17
+ where(conditions).where(["lower(username) = :value OR lower(email) = :value", {:value => login.downcase}]).first
18
+ end
19
+
20
+ def update_with_password(params={})
21
+ if params[:password].blank?
22
+ params.delete(:password)
23
+ params.delete(:password_confirmation) if params[:password_confirmation].blank?
24
+ end
25
+ update_attributes(params)
26
+ end
27
+
28
+ def apply_omniauth(omniauth)
29
+ if (omniauth['info'] && omniauth['info']['email'])
30
+ self.email = omniauth['info']['email'] if email.blank?
31
+ end
32
+ if (omniauth['info'] && omniauth['info']['nickname'])
33
+ self.username = omniauth['info']['nickname'] if username.blank?
34
+ else
35
+ self.username = derive_username if username.blank?
36
+ end
37
+ authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
38
+ end
39
+
40
+ def derive_username
41
+ split_email = self.email.split(/@/)
42
+ username_taken = User.where(:username => split_email[0]).first
43
+ unless username_taken
44
+ split_email[0]
45
+ else
46
+ nil
47
+ end
48
+ end
49
+
50
+ def password_required?
51
+ (authentications.empty? || !password.blank?) && super
52
+ end
53
+
54
+ end
@@ -0,0 +1,13 @@
1
+ <h2>Sign In Using...</h2>
2
+
3
+ <%%= render 'shared/open_auth' %>
4
+
5
+ <%% unless user_signed_in? %>
6
+ <div class="left span-12 last">
7
+ <h2 class="alt">... or a Normal Account:</h2>
8
+ <%%= render 'shared/login_form' %>
9
+ <%%= link_to "Forgot your password?", new_password_path('user') %>
10
+ <br/>
11
+ <%%= link_to "Sign up", new_user_registration_path %>
12
+ </div>
13
+ <%% end %>
@@ -0,0 +1,11 @@
1
+ <h2>Sign In Using...</h2>
2
+
3
+ <%= render 'shared/open_auth' %>
4
+
5
+ <% unless user_signed_in? %>
6
+ <div class="left span-9 last">
7
+ <h2 class="alt">... or a Normal Account:</h2>
8
+ <%= render 'shared/login_form' %>
9
+ <%= render "devise/shared/links" %>
10
+ </div>
11
+ <% end %>
@@ -0,0 +1,47 @@
1
+ <div class="left span-9">
2
+ <h2>Edit <%%= resource_name.to_s.humanize %></h2>
3
+
4
+ <%%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:method => :put}) do |f| %>
5
+ <%%= render 'shared/error_messages', :object => f.object %>
6
+
7
+ <p><%%= f.label :username %></p>
8
+
9
+ <p><%%= f.text_field :username, :class => "text" %></p>
10
+
11
+ <p><%%= f.label :email %></p>
12
+
13
+ <p><%%= f.text_field :email, :class => "text" %></p>
14
+
15
+ <p><%%= f.label :password %> <span class="alt large">(leave blank if you don't want to change it)</span></p>
16
+
17
+ <p><%%= f.password_field :password, :class => "text" %></p>
18
+
19
+ <p><%%= f.label :password_confirmation %></p>
20
+
21
+ <p><%%= f.password_field :password_confirmation, :class => "text" %></p>
22
+
23
+ <p><%%= f.submit "Update" %></p>
24
+ <%% end %>
25
+ </div>
26
+
27
+ <div class="left span-9 last">
28
+ <%%= render 'shared/open_auth' %>
29
+ <p>To use another provider to logon, click the provider you want to use.</p>
30
+ <br />
31
+ <p>To tell your authentication provider to stop authenticating with our site, then visit:
32
+ <ul>
33
+ <li><a href="https://accounts.google.com/IssuedAuthSubTokens">Google</a></li>
34
+ <li><a href="https://www.facebook.com/appcenter/my">Facebook</a></li>
35
+ <li><a href="https://twitter.com/settings/applications">Twitter</a></li>
36
+ <li><a href="https://github.com/account/connections">GitHub</a></li>
37
+ </ul>
38
+ </p>
39
+ </div>
40
+
41
+ <h3 class="clear">Cancel my account</h3>
42
+
43
+ <p>Want to delete your user and all associated
44
+ information? <%%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>
45
+ .</p>
46
+
47
+ <%%= link_to "Back", :back %>
@@ -0,0 +1,25 @@
1
+ <%% title "Sign up" %>
2
+
3
+ <h2>Sign up</h2>
4
+
5
+ <%%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
6
+ <%%= render 'shared/error_messages', :object => f.object %>
7
+
8
+ <p><%%= f.label :username %></p>
9
+ <p><%%= f.text_field :username %></p>
10
+
11
+ <p><%%= f.label :email %></p>
12
+ <p><%%= f.text_field :email %></p>
13
+
14
+ <%% if @user.password_required? %>
15
+ <p><%%= f.label :password %></p>
16
+ <p><%%= f.password_field :password %></p>
17
+
18
+ <p><%%= f.label :password_confirmation %></p>
19
+ <p><%%= f.password_field :password_confirmation %></p>
20
+ <%% end %>
21
+
22
+ <p><%%= f.submit "Sign up" %></p>
23
+ <%% end %>
24
+
25
+ <%%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,14 @@
1
+ <%%= form_for("user", :url => user_session_path) do |f| %>
2
+ <%%= f.label :login, "Login / Email" %>
3
+ <br/>
4
+ <%%= f.text_field :login, :class => "text" %>
5
+ <br/>
6
+ <%%= f.label :password %>
7
+ <br/>
8
+ <%%= f.password_field :password, :class => "text" %>
9
+ <br/>
10
+ <%%= f.check_box :remember_me %>
11
+ <%%= f.label :remember_me %>
12
+ <br/>
13
+ <%%= f.submit 'Sign in' %>
14
+ <%% end %>
@@ -0,0 +1,39 @@
1
+ <div class="left span-9 last">
2
+ <h2 class="alt">Open Authentication:</h2>
3
+
4
+ <%% if @authentications %>
5
+ <%% unless @authentications.empty? %>
6
+ <p><strong>You can sign in to this account using:</strong></p>
7
+
8
+ <div class="authentications">
9
+ <%% for authentication in @authentications %>
10
+ <div class="authentication ui-corner-all left">
11
+ <%%= link_to "X", authentication, :confirm => 'Are you sure you want to remove this authentication option?', :method => :delete, :class => "right", :title => "Remove" %>
12
+ <%%= image_tag "#{authentication.provider_name.downcase}_32.png", :size => "32x32" %>
13
+ <div class="provider"><%%= authentication.provider_name %></div>
14
+ <!--div class="uid alt"><%%= authentication.uid %></div-->
15
+ </div>
16
+ <%% end %>
17
+ <div class="clear"></div>
18
+ </div>
19
+ <%% end %>
20
+ <p><strong>Link another account:</strong></p>
21
+ <%% end %>
22
+
23
+ <a href="/auth/google_oauth2" class="auth_provider">
24
+ <%%= image_tag "google_64.png", :size => "64x64", :alt => "Google" %>
25
+ Google
26
+ </a>
27
+ <a href="/auth/facebook" class="auth_provider">
28
+ <%%= image_tag "facebook_64.png", :size => "64x64", :alt => "Facebook" %>
29
+ Facebook
30
+ </a>
31
+ <a href="/auth/twitter" class="auth_provider">
32
+ <%%= image_tag "twitter_64.png", :size => "64x64", :alt => "Twitter" %>
33
+ Twitter
34
+ </a>
35
+ <a href="/auth/github" class="auth_provider">
36
+ <%%= image_tag "github_64.png", :size => "64x64", :alt => "github" %>
37
+ GitHub
38
+ </a>
39
+ </div>
@@ -0,0 +1,13 @@
1
+ #require 'openid/store/filesystem'
2
+ Rails.application.config.middleware.use OmniAuth::Builder do
3
+ #require 'omniauth-google-oauth2'
4
+ config.omniauth :google_oauth2, 'APP_ID', 'APP_SECRET', { :scope => 'https://www.googleapis.com/auth/userinfo.email', :redirect_uri => 'http://tester.econtriver.com/auth/google_oauth2/callback', :approval_prompt => 'auto' }
5
+
6
+ #require 'omniauth-twitter'
7
+ config.omniauth :twitter, 'APP_ID', 'APP_SECRET'
8
+
9
+ #require 'omniauth-github'
10
+ config.omniauth :github, 'APP_ID', 'APP_SECRET'
11
+
12
+ #provider :open_id, OpenID::Store::Filesystem.new('/tmp')
13
+ end
@@ -84,7 +84,7 @@ module Frame
84
84
  #run "bundle"
85
85
 
86
86
  string='
87
- validates_presence_of :name
87
+ validates_presence_of :name, :location
88
88
 
89
89
  scope :topbar, where(:location => "topbar")
90
90
  scope :sidebar, where(:location => "sidebar")
@@ -30,6 +30,11 @@ module Frame
30
30
  initializer("secret_token.rb", "#{Rails.application.class.parent_name}::Application.config.secret_token = '#{secret}'")
31
31
  end
32
32
 
33
+ def create_rake_file
34
+ #@title = Rails.application.class.parent_name.downcase
35
+ template('Rakefile')
36
+ end
37
+
33
38
  end
34
39
  end
35
40
  end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rake
2
+
3
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
4
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
5
+
6
+ require File.expand_path('../config/application', __FILE__)
7
+
8
+ Tester::Application.load_tasks
9
+
10
+ files = ['config/initializers/omniauth.rb','config/database.yml','config/initializers/secret_token.rb']
11
+
12
+ domain = "#{Rails.application.class.parent_name.downcase}.econtriver.com"
13
+ user = "root" # The server's user for deploys
14
+ deploy_to = "/srv/www/#{domain}"
15
+
16
+ task :setup_server_db do
17
+ system("ssh #{user}@#{domain} 'cd #{File.join(deploy_to,'current')};rake db:setup RAILS_ENV=production'")
18
+ end
19
+
20
+ task :put_secret do
21
+ files.each do |f|
22
+ system("scp #{f} #{user}@#{domain}:#{File.join(deploy_to,'private',f)}")
23
+ end
24
+ end
25
+
26
+ task :get_secret do
27
+ files.each do |f|
28
+ system("scp #{user}@#{domain}:#{File.join(deploy_to,'private',f)} #{f}")
29
+ end
30
+ end
31
+
32
+ task :backup, :roles => :db, :only => { :primary => true } do
33
+ filename = "#{Rails.application.class.parent_name.downcase}.db_backup.#{Time.now.to_f}.sql.bz2"
34
+ filepath = File.join(deploy_to,'current',filename)
35
+ config = YAML.load_file(File.join(deploy_to,'private', 'config', 'database.yml')
36
+ run "mysqldump -u #{config['production']['username']} -p #{config['production']['database']} | bzip2 -c > #{filepath}" do |ch, stream, out|
37
+ ch.send_data "#{config['production']['password']}\n" if out =~ /^Enter password:/
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frame
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-23 00:00:00.000000000 Z
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeadmin
@@ -187,6 +187,38 @@ dependencies:
187
187
  - - ! '>='
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: omniauth-github
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ - !ruby/object:Gem::Dependency
207
+ name: omniauth-facebook
208
+ requirement: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
190
222
  - !ruby/object:Gem::Dependency
191
223
  name: rails
192
224
  requirement: !ruby/object:Gem::Requirement
@@ -261,17 +293,28 @@ extensions: []
261
293
  extra_rdoc_files: []
262
294
  files:
263
295
  - lib/generators/frame.rb
264
- - lib/generators/frame/layout/templates/defaults.html.erb
265
- - lib/generators/frame/layout/templates/application.html.erb
266
- - lib/generators/frame/layout/templates/application_helper.rb
267
- - lib/generators/frame/layout/templates/frame.css
268
- - lib/generators/frame/layout/templates/favicon.ico
269
- - lib/generators/frame/layout/templates/econ64.gif
270
- - lib/generators/frame/layout/templates/default_layout.html.erb
296
+ - lib/generators/frame/layout/templates/app/stylesheets/frame.css
297
+ - lib/generators/frame/layout/templates/app/views/layouts/defaults.html.erb
298
+ - lib/generators/frame/layout/templates/app/views/layouts/application.html.erb
299
+ - lib/generators/frame/layout/templates/app/views/layouts/default_layout.html.erb
300
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_16.png
301
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_256.png
302
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_32.png
303
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_64.png
304
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_128.png
305
+ - lib/generators/frame/layout/templates/app/assets/images/favicon.ico
306
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_64.gif
307
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_32_loading.gif
308
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_128.gif
309
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_256.gif
310
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_32.gif
311
+ - lib/generators/frame/layout/templates/app/assets/images/econ_f_16.gif
312
+ - lib/generators/frame/layout/templates/app/helpers/application_helper.rb
271
313
  - lib/generators/frame/layout/layout_generator.rb
272
314
  - lib/generators/frame/layout/USAGE
273
315
  - lib/generators/frame/mysql/USAGE
274
316
  - lib/generators/frame/mysql/mysql_generator.rb
317
+ - lib/generators/frame/secret/templates/Rakefile
275
318
  - lib/generators/frame/secret/templates/database.yml
276
319
  - lib/generators/frame/secret/secret_generator.rb
277
320
  - lib/generators/frame/secret/USAGE
@@ -285,21 +328,36 @@ files:
285
328
  - lib/generators/frame/pages/templates/_error_messages.html.erb
286
329
  - lib/generators/frame/pages/pages_generator.rb
287
330
  - lib/generators/frame/pages/USAGE
288
- - lib/generators/frame/omniauth/templates/defaults.html.erb
289
- - lib/generators/frame/omniauth/templates/omniauth_callbacks_controller.rb
290
- - lib/generators/frame/omniauth/templates/omniauth.rb
331
+ - lib/generators/frame/omniauth/templates/app/views/authentications/index.html.erb
332
+ - lib/generators/frame/omniauth/templates/app/views/registrations/new.html.erb
333
+ - lib/generators/frame/omniauth/templates/app/views/registrations/edit.html.erb
334
+ - lib/generators/frame/omniauth/templates/app/views/devise/sessions/new.html.erb
335
+ - lib/generators/frame/omniauth/templates/app/views/shared/_open_auth.html.erb
336
+ - lib/generators/frame/omniauth/templates/app/views/shared/_login_form.html.erb
337
+ - lib/generators/frame/omniauth/templates/app/models/user.rb
338
+ - lib/generators/frame/omniauth/templates/app/assets/images/twitter_64.png
339
+ - lib/generators/frame/omniauth/templates/app/assets/images/github_32.png
340
+ - lib/generators/frame/omniauth/templates/app/assets/images/google_64.png
341
+ - lib/generators/frame/omniauth/templates/app/assets/images/facebook_64.png
342
+ - lib/generators/frame/omniauth/templates/app/assets/images/twitter_32.png
343
+ - lib/generators/frame/omniauth/templates/app/assets/images/facebook_32.png
344
+ - lib/generators/frame/omniauth/templates/app/assets/images/google_32.png
345
+ - lib/generators/frame/omniauth/templates/app/assets/images/github_64.png
346
+ - lib/generators/frame/omniauth/templates/app/controllers/authentications_controller.rb
347
+ - lib/generators/frame/omniauth/templates/app/controllers/registrations_controller.rb
348
+ - lib/generators/frame/omniauth/templates/config/initializers/omniauth.rb
291
349
  - lib/generators/frame/omniauth/USAGE
292
350
  - lib/generators/frame/omniauth/omniauth_generator.rb
293
351
  - lib/generators/frame/all/USAGE
294
352
  - lib/generators/frame/all/all_generator.rb
295
353
  - lib/generators/frame/blueprint/USAGE
296
354
  - lib/generators/frame/blueprint/blueprint_generator.rb
297
- - lib/generators/frame/devise/templates/defaults.html.erb
355
+ - lib/generators/frame/devise/templates/app/views/layouts/defaults.html.erb
298
356
  - lib/generators/frame/devise/USAGE
299
357
  - lib/generators/frame/devise/devise_generator.rb
300
- - lib/generators/frame/admin/templates/pages_controller.rb
301
- - lib/generators/frame/admin/templates/show.html.erb
302
- - lib/generators/frame/admin/templates/pages.rb
358
+ - lib/generators/frame/admin/templates/app/views/pages/show.html.erb
359
+ - lib/generators/frame/admin/templates/app/controllers/pages_controller.rb
360
+ - lib/generators/frame/admin/templates/app/admin/pages.rb
303
361
  - lib/generators/frame/admin/USAGE
304
362
  - lib/generators/frame/admin/admin_generator.rb
305
363
  - lib/generators/frame/gitignore/gitignore_generator.rb
@@ -1,47 +0,0 @@
1
- <%% content_for :head do %>
2
- <%%= favicon_link_tag('/assets/favicon.ico') %>
3
- <%%= stylesheet_link_tag "application" %>
4
- <%%= javascript_include_tag "application" %>
5
- <%%= csrf_meta_tag %>
6
- <%% end %>
7
-
8
- <%% content_for :header do %>
9
- <nav class="span-24 append-bottom">
10
- <ul>
11
- <%%= render :partial => "pages/links", :collection => @display_pages.topbar, :as => :page, :locals => {:classes => "left hover"} %>
12
- <%% if user_signed_in? %>
13
- <%%= link_to '<li class="left hover">Account</li>'.html_safe, edit_user_registration_path %>
14
- <%%= link_to '<li class="right hover">Sign out</li>'.html_safe, destroy_user_session_path, :method => :delete %>
15
- <li class="right last lighter"><%%= current_user.email %></li>
16
- <%% else %>
17
- <%%= link_to '<li class="right hover">Sign in</li>'.html_safe, user_session_path %>
18
- <%% end %>
19
- </ul>
20
- </nav>
21
- <banner>
22
- <%%= link_to logo, root_path, {:class => "right prepend-1"} %>
23
- <h1 class="left alt append-1"><%%= yield(:title) %></h1>
24
- <%% flash.each do |key, value| %>
25
- <div id="notice" class="left flash <%%= key %>"><%%= value %></div>
26
- <%% end %>
27
- </banner>
28
- <hr/>
29
- <%% end %>
30
-
31
- <%% content_for :sidebar do %>
32
- <%%= render 'shared/sidebar', :sidebar => @display_pages.sidebar %>
33
- <%% end %>
34
-
35
- <%% content_for :userbar do %>
36
- <%% if user_signed_in? %>
37
- <%%= render 'shared/sidebar', :sidebar => @display_pages.userbar %>
38
- <%% end %>
39
- <%% end %>
40
-
41
- <%% content_for :footer do %>
42
- <nav class="span-24 prepend-top last">
43
- <ul>
44
- <%%= render :partial => "pages/links", :collection => @display_pages.bottombar, :as => :page, :locals => {:classes => "left hover"} %>
45
- </ul>
46
- </nav>
47
- <%% end %>
@@ -1,6 +0,0 @@
1
- Devise.setup do |config|
2
- require 'omniauth-google-oauth2'
3
- config.omniauth :google_oauth2, 'APP_ID', 'APP_SECRET', { :scope => 'https://www.googleapis.com/auth/userinfo.email', :redirect_uri => 'http://tester.econtriver.com/auth/google_oauth2/callback', :approval_prompt => 'auto' }
4
- require 'omniauth-twitter'
5
- config.omniauth :twitter, 'APP_ID', 'APP_SECRET'
6
- end
@@ -1,38 +0,0 @@
1
- class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
- #def facebook
3
- # @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
4
- #
5
- # if @user.persisted?
6
- # flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
7
- # sign_in_and_redirect @user, :event => :authentication
8
- # else
9
- # session["devise.facebook_data"] = request.env["omniauth.auth"]
10
- # redirect_to new_user_registration_url
11
- # end
12
- #end
13
-
14
- def twitter
15
- @user = User.find_for_twitter_oauth(request.env["omniauth.auth"], current_user)
16
-
17
- if @user.persisted?
18
- flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Twitter"
19
- sign_in_and_redirect @user, :event => :authentication
20
- else
21
- session["devise.twitter_data"] = request.env["omniauth.auth"]
22
- redirect_to new_user_registration_url
23
- end
24
- end
25
-
26
- def google
27
- @user = User.find_for_google_oauth(request.env["omniauth.auth"], current_user)
28
-
29
- if @user.persisted?
30
- flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
31
- sign_in_and_redirect @user, :event => :authentication
32
- else
33
- session["devise.google_data"] = request.env["omniauth.auth"]
34
- redirect_to new_user_registration_url
35
- end
36
- end
37
-
38
- end