basic-initial-rails4 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in basic-initial-rails4.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Oscar Hugo Cardenas Lopez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Basic::Initial::Rails4
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'basic-initial-rails4'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install basic-initial-rails4
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ class Sessionuser
2
+ attr_accessor :provider, :name, :screen_name, :followers, :friends
3
+ end
@@ -0,0 +1,54 @@
1
+ class SessionsController < ApplicationController
2
+ require 'session_user'
3
+ skip_before_action :is_login!, only: [:create, :new]
4
+
5
+ def new
6
+ if $user.nil?
7
+ @user = User.new
8
+ else
9
+ @user = $user
10
+ end
11
+ $user = nil
12
+ end
13
+
14
+ def create
15
+ if params[:commit] === 'Sign up'
16
+ user = User.create(user_params)
17
+ if user.save
18
+ session[:user_id] = user.id
19
+ redirect_to root_path
20
+ else
21
+ $user = user
22
+ redirect_to new_user_path
23
+ end
24
+ elsif request.env['omniauth.auth'].nil?
25
+ redirect_to new_user_path
26
+ else
27
+ $current_user = Sessionuser.new
28
+ $current_user.provider = params['provider']
29
+ session[:user_id] = request.env['omniauth.auth']['extra']['raw_info']['id']
30
+ $current_user.name = request.env['omniauth.auth']['extra']['raw_info']['name']
31
+ if $current_user.provider === 'twitter'
32
+ $current_user.screen_name = request.env['omniauth.auth']['extra']['raw_info']['screen_name']
33
+ $current_user.followers = request.env['omniauth.auth']['extra']['raw_info']['followers_count']
34
+ $current_user.friends = request.env['omniauth.auth']['extra']['raw_info']['friends_count']
35
+ elsif $current_user.provider === 'github'
36
+ $current_user.screen_name = request.env['omniauth.auth']['extra']['raw_info']['login']
37
+ end
38
+ redirect_to root_path
39
+ end
40
+ end
41
+
42
+ def logout
43
+ $current_user = nil
44
+ session[:user_id] = nil
45
+ redirect_to root_path
46
+ end
47
+
48
+ def failure
49
+ end
50
+
51
+ def user_params
52
+ params.permit(:name, :email, :password, :password_confirmation)
53
+ end
54
+ end
@@ -0,0 +1,32 @@
1
+ class UsersController < ApplicationController
2
+ skip_before_action :is_login!, only: [:create, :new]
3
+
4
+ def index
5
+
6
+ end
7
+
8
+ def create
9
+ if params[:commit] === 'Sign in'
10
+ user = User.find_by_email(params[:user][:email])
11
+ if user and user.authenticate(params[:user][:password])
12
+ session[:user_id] = user.id
13
+ flash[:notice] = 'Signed in successfully'
14
+ redirect_to root_path
15
+ else
16
+ $user = user
17
+ redirect_to new_user_path
18
+ end
19
+ else
20
+ redirect_to sessions_new_path
21
+ end
22
+ end
23
+
24
+ def new
25
+ if $user.nil?
26
+ @user = User.new
27
+ else
28
+ @user = $user
29
+ end
30
+ $user = nil
31
+ end
32
+ end
data/app/models/.keep ADDED
File without changes
@@ -0,0 +1,11 @@
1
+ class User < ActiveRecord::Base
2
+ has_secure_password
3
+ validates_presence_of :name
4
+ validates_presence_of :email
5
+ validates_uniqueness_of :name
6
+ validates_uniqueness_of :email
7
+ validates_length_of :name, minimum: 5, maximum: 18
8
+ validates_length_of :password, minimum: 8, maximum: 24
9
+ validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,on: :create
10
+ validates_format_of :name, with: /[a-zA-Z]/
11
+ end
@@ -0,0 +1,27 @@
1
+ - if session[:user_id].nil?
2
+ = link_to 'Twitter', '/auth/twitter'
3
+ = link_to 'Github', '/auth/github'
4
+ %h1 Sign in
5
+ %p Put you information to login
6
+ = form_for @user do |f|
7
+ %table{width: '100%'}
8
+ %tr
9
+ %td
10
+ = f.label :email, 'You user email'
11
+ %td
12
+ = f.text_field :email
13
+ %tr
14
+ %td
15
+ = f.label :password
16
+ %td
17
+ = f.password_field :password
18
+ %tr
19
+ %td
20
+ = f.label :password_confirmation
21
+ %td
22
+ = f.password_field :password_confirmation
23
+ %tr
24
+ %td
25
+ = f.submit 'Sign in'
26
+ %td
27
+ = f.submit 'Cancel'
@@ -0,0 +1,3 @@
1
+ %h1
2
+ - unless $current_user.nil?
3
+ = "Welcome #{$current_user.name}"
@@ -0,0 +1,29 @@
1
+ %h1 Sign up
2
+ %p put information to complete your register
3
+ = form_tag sessions_new_path, method: "POST" do |f|
4
+ %table{width: "100%"}
5
+ %tr
6
+ %td
7
+ = label_tag :name, "You user name"
8
+ %td
9
+ = text_field_tag :name
10
+ %tr
11
+ %td
12
+ = label_tag :email, "You user email"
13
+ %td
14
+ = text_field_tag :email
15
+ %tr
16
+ %td
17
+ = label_tag :password
18
+ %td
19
+ = password_field_tag :password
20
+ %tr
21
+ %td
22
+ = label_tag :password_confirmation
23
+ %td
24
+ = password_field_tag :password_confirmation
25
+ %tr
26
+ %td
27
+ = submit_tag "Sign up"
28
+ %td
29
+ = submit_tag "Cancel"
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'basic/initial/rails4/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "basic-initial-rails4"
8
+ gem.version = Basic::Initial::Rails4::VERSION
9
+ gem.authors = ["Oscar Hugo Cardenas Lopez"]
10
+ gem.email = ["ohcl87@hotmail.com"]
11
+ gem.description = %q{this gem is to create a main files into de new rails applications using a rails g binstall to save time into by creating equals files using basic gem pg compass using haml bcrypt and omniauth-twitter be added in the future new utils}
12
+ gem.summary = %q{gem to load another gems and basic files'}
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ #gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.post_install_message = "Important install the omniauth-twitter gem pitting in Gemfile gem 'omniauth-twitter'"
21
+
22
+ gem.add_runtime_dependency "rails", ">= 3.2"
23
+ gem.add_runtime_dependency "pg", ">= 0.15.0"
24
+ gem.add_runtime_dependency "bundler", "~> 1.3"
25
+ gem.add_runtime_dependency "bundler", "~> 1.3"
26
+ gem.add_development_dependency "compass", ">= 0.12.0"
27
+ gem.add_development_dependency "haml-rails", ">= 0.3"
28
+ gem.add_development_dependency "omniauth-twitter", ">= 1.0.0"
29
+ gem.add_development_dependency 'bcrypt-ruby', '~> 3.0.0'
30
+ gem.add_development_dependency "bootstrap-rails4"
31
+ gem.add_development_dependency "rake"
32
+ end
@@ -0,0 +1,11 @@
1
+ require "basic/initial/rails4/version"
2
+
3
+ module Basic
4
+ module Initial
5
+ module Rails4
6
+ class Engine < ::Rails::Engine
7
+ engine_name :binstall
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Basic
2
+ module Initial
3
+ module Rails4
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ require 'rails/generators'
2
+
3
+ class BinstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ desc 'This generator copy an initializer file at config/initializers/omniauth.rb'
6
+ def copy_initializers_files
7
+ initial_route = 'config/initializers/'
8
+ copy_file "#{initial_route}mail.rb", "#{initial_route}mail.rb"
9
+ copy_file "#{initial_route}omniauth.rb", "#{initial_route}omniauth.rb"
10
+ end
11
+
12
+ def copy_mailers_file
13
+ copy_file 'mailers/notifier.rb', 'app/mailers/notifier.rb'
14
+ end
15
+
16
+ def load_config_to_send_mail
17
+ inject_into_file 'config/environments/development.rb', after: 'config.action_mailer.raise_delivery_errors = false' do
18
+ "\n #change raise_delivery_errors false with true
19
+ config.action_mailer.delivery_method = :smtp
20
+ config.action_mailer.perform_deliveries = true"
21
+ end
22
+ end
23
+
24
+ def create_notifier_folder
25
+ create_file 'app/notifier/mail_method.html.rb'
26
+ end
27
+
28
+ def load_login_method
29
+ inject_into_file 'app/helpers/application_helper.rb', after: 'module ApplicationHelper' do
30
+ "\n def is_login!\n
31
+ if session[:user_id].nil?
32
+ flash[:notice] = 'You need login to load this section'
33
+ redirect_to sessions_new_path
34
+ else
35
+ if $current_user.nil?
36
+ $current_user = User.find_by_id(session[:user_id])
37
+ end
38
+ end
39
+ end"
40
+ end
41
+ end
42
+
43
+ def load_routes
44
+ inject_into_file 'config/routes.rb', after: 'do' do
45
+ "\n get 'sessions/new'
46
+ post 'sessions/new', to: 'sessions#create'
47
+ get 'sessions/destroy', to: 'sessions#logout'
48
+ root to: 'users#index'
49
+ resources :users, only: [:index, :create, :new]
50
+ get '/auth/:provider/callback', to: 'sessions#create'
51
+ get '/auth/failure', to: 'sessions#failure'"
52
+ end
53
+ end
54
+
55
+ def copy_application_layout
56
+ copy_file 'layouts/application.html.haml', 'app/views/layouts/application.html.haml'
57
+ end
58
+ end
@@ -0,0 +1,7 @@
1
+ ActionMailer::Base.smtp_settings = {
2
+ user_name: 'example@example.com',
3
+ password: 'example',
4
+ address: 'smtp_settings',
5
+ port: 587,
6
+ enable_starttls: true
7
+ }
@@ -0,0 +1,34 @@
1
+ Rails.application.config.middleware.use OmniAuth::Builder do
2
+ #provider :twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
3
+ #provider :github, 'Client ID', 'Client Secret'
4
+ #provider :facebook, 'APP_ID', 'APP_SECRET'
5
+ #provider :linked_in, 'CONSUMER_KEY', 'CONSUMER_SECRET'
6
+ end
7
+
8
+ class NonExplodingFailureEndpoint
9
+ attr_reader :env
10
+
11
+ def self.call(env)
12
+ new(env).call
13
+ end
14
+
15
+ def initialize(env)
16
+ @env = env
17
+ end
18
+
19
+ def call
20
+ redirect_to_failure
21
+ end
22
+
23
+ def raise_out!
24
+ raise env['omniauth.error'] || OmniAuth::Error.new(env['omniauth.error.type'])
25
+ end
26
+
27
+ def redirect_to_failure
28
+ message_key = env['omniauth.error.type']
29
+ new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
30
+ Rack::Response.new(["302 Moved"], 302, 'Location' => new_path).finish
31
+ end
32
+ end
33
+
34
+ OmniAuth.config.on_failure = NonExplodingFailureEndpoint
@@ -0,0 +1,16 @@
1
+ %html!
2
+ %head
3
+ %title Tickets
4
+ = stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
5
+ = javascript_include_tag "application", "data-turbolinks-track" => true
6
+ = csrf_meta_tags
7
+ %body
8
+ .row
9
+ .span4
10
+ - unless @user.nil?
11
+ - @user.errors.full_messages.each do |message|
12
+ = message
13
+ .span4
14
+ - unless session[:user_id].nil?
15
+ = link_to 'Logout', 'sessions/destroy'
16
+ = yield
@@ -0,0 +1,9 @@
1
+ class Notifier < ActionMailer::Base
2
+ from_address = ActionMailer::Base.smtp_settings[:user_name]
3
+ default from: "App Name <#{from_address}"
4
+
5
+ def mail_method(mail)
6
+ subject = "#{mail.subject} from App name"
7
+ mail(to: mail.email, subject: subject)
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basic-initial-rails4
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Oscar Hugo Cardenas Lopez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: pg
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.15.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.15.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: compass
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.12.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.12.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: haml-rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0.3'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0.3'
110
+ - !ruby/object:Gem::Dependency
111
+ name: omniauth-twitter
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 1.0.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: bcrypt-ruby
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 3.0.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 3.0.0
142
+ - !ruby/object:Gem::Dependency
143
+ name: bootstrap-rails4
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: rake
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: this gem is to create a main files into de new rails applications using
175
+ a rails g binstall to save time into by creating equals files using basic gem pg
176
+ compass using haml bcrypt and omniauth-twitter be added in the future new utils
177
+ email:
178
+ - ohcl87@hotmail.com
179
+ executables: []
180
+ extensions: []
181
+ extra_rdoc_files: []
182
+ files:
183
+ - .gitignore
184
+ - Gemfile
185
+ - LICENSE.txt
186
+ - README.md
187
+ - Rakefile
188
+ - app/controllers/session_user.rb
189
+ - app/controllers/sessions_controller.rb
190
+ - app/controllers/users_controller.rb
191
+ - app/models/.keep
192
+ - app/models/user.rb
193
+ - app/views/sessions/new.html.haml
194
+ - app/views/users/index.html.haml
195
+ - app/views/users/new.html.haml
196
+ - basic-initial-rails4.gemspec
197
+ - lib/basic/initial/rails4.rb
198
+ - lib/basic/initial/rails4/version.rb
199
+ - lib/generators/binstall/binstall_generator.rb
200
+ - lib/generators/binstall/templates/config/initializers/mail.rb
201
+ - lib/generators/binstall/templates/config/initializers/omniauth.rb
202
+ - lib/generators/binstall/templates/layouts/application.html.haml
203
+ - lib/generators/binstall/templates/mailers/notifier.rb
204
+ homepage: ''
205
+ licenses:
206
+ - MIT
207
+ post_install_message: Important install the omniauth-twitter gem pitting in Gemfile
208
+ gem 'omniauth-twitter'
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ! '>='
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ required_rubygems_version: !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ! '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 1.8.25
227
+ signing_key:
228
+ specification_version: 3
229
+ summary: gem to load another gems and basic files'
230
+ test_files: []