basic-initial-rails4 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/controllers/session_user.rb +1 -1
- data/app/controllers/sessions_controller.rb +23 -24
- data/app/controllers/users_controller.rb +2 -5
- data/app/models/user.rb +6 -6
- data/app/views/sessions/new.html.haml +5 -3
- data/app/views/users/index.html.haml +1 -3
- data/app/views/users/new.html.haml +28 -28
- data/lib/basic/initial/rails4/version.rb +1 -1
- data/lib/generators/binstall/binstall_generator.rb +15 -10
- metadata +2 -2
@@ -1,41 +1,23 @@
|
|
1
1
|
class SessionsController < ApplicationController
|
2
2
|
require 'session_user'
|
3
|
-
skip_before_action :is_login!, only: [:create, :new]
|
4
3
|
|
5
4
|
def new
|
6
|
-
|
7
|
-
|
8
|
-
else
|
9
|
-
@user = $user
|
10
|
-
end
|
5
|
+
redirect_to root_path unless session[:user_id].nil?
|
6
|
+
$user.nil? ? @user = User.new : @user = $user
|
11
7
|
$user = nil
|
12
8
|
end
|
13
9
|
|
14
10
|
def create
|
15
11
|
if params[:commit] === 'Sign up'
|
16
|
-
user = User.create(user_params)
|
17
|
-
if user.save
|
18
|
-
session[:user_id] = user.id
|
12
|
+
$user = User.create(user_params)
|
13
|
+
if $user.save
|
14
|
+
session[:user_id] = $user.id
|
19
15
|
redirect_to root_path
|
20
16
|
else
|
21
|
-
$user = user
|
22
17
|
redirect_to new_user_path
|
23
18
|
end
|
24
|
-
elsif request.env['omniauth.auth'].nil?
|
25
|
-
redirect_to new_user_path
|
26
19
|
else
|
27
|
-
|
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
|
20
|
+
request.env['omniauth.auth'].nil? ? (redirect_to new_user_path) : set_omniauth_user
|
39
21
|
end
|
40
22
|
end
|
41
23
|
|
@@ -47,6 +29,23 @@ class SessionsController < ApplicationController
|
|
47
29
|
|
48
30
|
def failure
|
49
31
|
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def set_omniauth_user
|
36
|
+
$current_user = SessionUser.new
|
37
|
+
$current_user.provider = params['provider']
|
38
|
+
session[:user_id] = request.env['omniauth.auth']['extra']['raw_info']['id']
|
39
|
+
$current_user.name = request.env['omniauth.auth']['extra']['raw_info']['name']
|
40
|
+
if $current_user.provider === 'twitter'
|
41
|
+
$current_user.screen_name = request.env['omniauth.auth']['extra']['raw_info']['screen_name']
|
42
|
+
$current_user.followers = request.env['omniauth.auth']['extra']['raw_info']['followers_count']
|
43
|
+
$current_user.friends = request.env['omniauth.auth']['extra']['raw_info']['friends_count']
|
44
|
+
elsif $current_user.provider === 'github'
|
45
|
+
$current_user.screen_name = request.env['omniauth.auth']['extra']['raw_info']['login']
|
46
|
+
end
|
47
|
+
redirect_to root_path
|
48
|
+
end
|
50
49
|
|
51
50
|
def user_params
|
52
51
|
params.permit(:name, :email, :password, :password_confirmation)
|
@@ -22,11 +22,8 @@ class UsersController < ApplicationController
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def new
|
25
|
-
|
26
|
-
|
27
|
-
else
|
28
|
-
@user = $user
|
29
|
-
end
|
25
|
+
redirect_to root_path unless session[:user_id].nil?
|
26
|
+
$user.nil? ? @user = User.new : @user = $user
|
30
27
|
$user = nil
|
31
28
|
end
|
32
29
|
end
|
data/app/models/user.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
class User < ActiveRecord::Base
|
2
2
|
has_secure_password
|
3
|
-
validates_presence_of
|
4
|
-
validates_presence_of
|
3
|
+
validates_presence_of :name
|
4
|
+
validates_presence_of :email
|
5
5
|
validates_uniqueness_of :name
|
6
6
|
validates_uniqueness_of :email
|
7
|
-
validates_length_of
|
8
|
-
validates_length_of
|
9
|
-
validates_format_of
|
10
|
-
validates_format_of
|
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
11
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
- if session[:user_id].nil?
|
2
|
-
= link_to 'Twitter', '/auth/twitter'
|
3
|
-
= link_to 'Github', '/auth/github'
|
2
|
+
= link_to 'Twitter', '/auth/twitter' unless @init_twitter.nil?
|
3
|
+
= link_to 'Github', '/auth/github' unless @init_github.nil?
|
4
|
+
= link_to 'Facebook', '/auth/facebook' unless @init_facebook.nil?
|
5
|
+
= link_to 'Linked_in', '/auth/linked_in' unless @init_linkedin.nil?
|
4
6
|
%h1 Sign in
|
5
7
|
%p Put you information to login
|
6
8
|
= form_for @user do |f|
|
7
|
-
%table{width: '
|
9
|
+
%table{width: '25%'}
|
8
10
|
%tr
|
9
11
|
%td
|
10
12
|
= f.label :email, 'You user email'
|
@@ -1,29 +1,29 @@
|
|
1
1
|
%h1 Sign up
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
2
|
+
%p put information to complete your register
|
3
|
+
= form_tag sessions_new_path, method: "POST" do |f|
|
4
|
+
%table{width: "25%"}
|
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"
|
@@ -29,19 +29,28 @@ class BinstallGenerator < Rails::Generators::Base
|
|
29
29
|
inject_into_file 'app/helpers/application_helper.rb', after: 'module ApplicationHelper' do
|
30
30
|
"\n def is_login!\n
|
31
31
|
if session[:user_id].nil?
|
32
|
-
|
33
|
-
|
34
|
-
else
|
35
|
-
if $current_user.nil?
|
32
|
+
redirect_to sessions_new_path, notice: 'You need login to load this section'
|
33
|
+
elsif $current_user.nil?
|
36
34
|
$current_user = User.find_by_id(session[:user_id])
|
37
|
-
end
|
38
35
|
end
|
39
36
|
end"
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
40
|
+
def load_initial_link_ban
|
41
|
+
inject_into_file 'app/controllers/application_controller.rb', after: 'protect_from_forgery with: :exception' do
|
42
|
+
"\n before_filter :load_initial
|
43
|
+
def load_initial
|
44
|
+
@init_twitter = nil
|
45
|
+
@init_github = nil
|
46
|
+
@init_facebook = nil
|
47
|
+
@init_linkedin = nil
|
48
|
+
end"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
43
52
|
def load_routes
|
44
|
-
inject_into_file 'config/routes.rb', after: 'do' do
|
53
|
+
inject_into_file 'config/routes.rb', after: 'Application.routes.draw do' do
|
45
54
|
"\n get 'sessions/new'
|
46
55
|
post 'sessions/new', to: 'sessions#create'
|
47
56
|
get 'sessions/destroy', to: 'sessions#logout'
|
@@ -51,8 +60,4 @@ class BinstallGenerator < Rails::Generators::Base
|
|
51
60
|
get '/auth/failure', to: 'sessions#failure'"
|
52
61
|
end
|
53
62
|
end
|
54
|
-
|
55
|
-
def copy_application_layout
|
56
|
-
copy_file 'layouts/application.html.haml', 'app/views/layouts/application.html.haml'
|
57
|
-
end
|
58
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic-initial-rails4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
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: 2013-
|
12
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|