iceauth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +55 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/iceauth.gemspec +24 -0
- data/lib/generators/iceauth/.DS_Store +0 -0
- data/lib/generators/iceauth/USAGE +7 -0
- data/lib/generators/iceauth/iceauth_generator.rb +25 -0
- data/lib/generators/iceauth/templates/app/assets/images/rails.png +0 -0
- data/lib/generators/iceauth/templates/app/assets/stylesheets/application.css +9 -0
- data/lib/generators/iceauth/templates/app/assets/stylesheets/pages.css.scss +170 -0
- data/lib/generators/iceauth/templates/app/controllers/application_controller.rb +5 -0
- data/lib/generators/iceauth/templates/app/controllers/pages_controller.rb +22 -0
- data/lib/generators/iceauth/templates/app/controllers/sessions_controller.rb +24 -0
- data/lib/generators/iceauth/templates/app/controllers/users_controller.rb +52 -0
- data/lib/generators/iceauth/templates/app/helpers/.DS_Store +0 -0
- data/lib/generators/iceauth/templates/app/helpers/sessions_helper.rb +39 -0
- data/lib/generators/iceauth/templates/app/layouts/_footer.html.haml +7 -0
- data/lib/generators/iceauth/templates/app/layouts/_header.html.haml.tt +14 -0
- data/lib/generators/iceauth/templates/app/layouts/_javascripts.html.haml +2 -0
- data/lib/generators/iceauth/templates/app/layouts/_stylesheets.html.haml +4 -0
- data/lib/generators/iceauth/templates/app/layouts/application.html.haml.tt +16 -0
- data/lib/generators/iceauth/templates/app/models/.gitkeep +0 -0
- data/lib/generators/iceauth/templates/app/models/user.rb +53 -0
- data/lib/generators/iceauth/templates/app/views/layouts/_footer.html.haml +7 -0
- data/lib/generators/iceauth/templates/app/views/layouts/_header.html.haml.tt +14 -0
- data/lib/generators/iceauth/templates/app/views/layouts/_javascripts.html.haml +2 -0
- data/lib/generators/iceauth/templates/app/views/layouts/_stylesheets.html.haml +4 -0
- data/lib/generators/iceauth/templates/app/views/layouts/application.html.haml.tt +16 -0
- data/lib/generators/iceauth/templates/app/views/pages/about.html.haml.tt +3 -0
- data/lib/generators/iceauth/templates/app/views/pages/contact.html.haml.tt +3 -0
- data/lib/generators/iceauth/templates/app/views/pages/help.html.haml.tt +3 -0
- data/lib/generators/iceauth/templates/app/views/pages/home.html.haml.tt +7 -0
- data/lib/generators/iceauth/templates/app/views/sessions/new.html.haml +23 -0
- data/lib/generators/iceauth/templates/app/views/shared/_error_messages.html.haml +10 -0
- data/lib/generators/iceauth/templates/app/views/users/_fields.html.haml +27 -0
- data/lib/generators/iceauth/templates/app/views/users/edit.html.haml +7 -0
- data/lib/generators/iceauth/templates/app/views/users/new.html.haml +7 -0
- data/lib/generators/iceauth/templates/spec/controllers/pages_controller_spec.rb.tt +68 -0
- data/lib/generators/iceauth/templates/spec/controllers/sessions_controller_spec.rb +88 -0
- data/lib/generators/iceauth/templates/spec/controllers/users_controller_spec.rb +266 -0
- data/lib/generators/iceauth/templates/spec/factories.rb +16 -0
- data/lib/generators/iceauth/templates/spec/models/user_spec.rb +192 -0
- data/lib/generators/iceauth/templates/spec/spec_helper.rb +50 -0
- data/lib/generators/iceauth/templates/vendor/.DS_Store +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/.gitkeep +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/awesome-buttons.css +114 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/ie.css +36 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/lock.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/link-icons/screen.css +42 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/plugins/rtl/screen.css +110 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/print.css +29 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/screen.css +265 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/forms.css +82 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/grid.css +280 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/grid.png +0 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/ie.css +79 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/print.css +92 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/reset.css +65 -0
- data/lib/generators/iceauth/templates/vendor/assets/stylesheets/blueprint/src/typography.css +123 -0
- data/lib/iceauth/version.rb +3 -0
- data/lib/iceauth.rb +5 -0
- metadata +124 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.2-p290@iceauth"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
+
|
14
|
+
#
|
15
|
+
# First we attempt to load the desired environment directly from the environment
|
16
|
+
# file. This is very fast and efficient compared to running through the entire
|
17
|
+
# CLI and selector. If you want feedback on which environment was used then
|
18
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
+
#
|
20
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
+
then
|
23
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
+
|
25
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
+
then
|
27
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
+
fi
|
29
|
+
else
|
30
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
+
if ! rvm --create use "$environment_id"
|
32
|
+
then
|
33
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
+
exit 1
|
35
|
+
fi
|
36
|
+
fi
|
37
|
+
|
38
|
+
#
|
39
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
+
# necessary.
|
42
|
+
#
|
43
|
+
# filename=".gems"
|
44
|
+
# if [[ -s "$filename" ]]
|
45
|
+
# then
|
46
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
47
|
+
# fi
|
48
|
+
|
49
|
+
# If you use bundler, this might be useful to you:
|
50
|
+
# if command -v bundle && [[ -s Gemfile ]]
|
51
|
+
# then
|
52
|
+
# bundle install
|
53
|
+
# fi
|
54
|
+
|
55
|
+
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/iceauth.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "iceauth/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "iceauth"
|
7
|
+
s.version = Iceauth::VERSION
|
8
|
+
s.authors = ["Mark Dillon"]
|
9
|
+
s.email = ["mdillon@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Generate authentication for an icebreaker based rails application}
|
12
|
+
s.description = %q{Generate authentication for an icebreaker based rails application}
|
13
|
+
|
14
|
+
s.rubyforge_project = "iceauth"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class IceauthGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def copy_app
|
5
|
+
directory "app"
|
6
|
+
directory "spec"
|
7
|
+
directory "vendor"
|
8
|
+
end
|
9
|
+
|
10
|
+
def make_routes
|
11
|
+
route "root :to => 'pages#home'"
|
12
|
+
|
13
|
+
route "match '/signup', :to => 'users#new'"
|
14
|
+
route "match '/signin', :to => 'sessions#new'"
|
15
|
+
route "match '/signout', :to => 'sessions#destroy'"
|
16
|
+
|
17
|
+
route "match '/contact', :to => 'pages#contact'"
|
18
|
+
route "match '/about', :to => 'pages#about'"
|
19
|
+
route "match '/help', :to => 'pages#help'"
|
20
|
+
|
21
|
+
route "resources :sessions, :only => [:new, :create, :destroy]"
|
22
|
+
route "resources :users"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
Binary file
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require ../../../vendor/assets/stylesheets/blueprint/screen.css
|
6
|
+
*= require_self
|
7
|
+
*= require_tree .
|
8
|
+
*= require ../../../vendor/assets/stylesheets/awesome-buttons
|
9
|
+
*/
|
@@ -0,0 +1,170 @@
|
|
1
|
+
// Place all the styles related to the pages controller here.
|
2
|
+
// They will automatically be included in application.css.
|
3
|
+
// You can use Sass (SCSS) here: http://sass-lang.com/
|
4
|
+
.container {
|
5
|
+
width: 70%;
|
6
|
+
}
|
7
|
+
|
8
|
+
body {
|
9
|
+
background: #EDEFED;
|
10
|
+
}
|
11
|
+
|
12
|
+
header {
|
13
|
+
background: lightgray;
|
14
|
+
padding: 10px 0 10px 0;
|
15
|
+
}
|
16
|
+
|
17
|
+
header img {
|
18
|
+
padding: 1em;
|
19
|
+
}
|
20
|
+
|
21
|
+
section {
|
22
|
+
margin-top: 1em;
|
23
|
+
font-size: 120%;
|
24
|
+
padding: 20px;
|
25
|
+
background: #fff;
|
26
|
+
}
|
27
|
+
|
28
|
+
section h1 {
|
29
|
+
font-size: 200%;
|
30
|
+
}
|
31
|
+
|
32
|
+
/* Links */
|
33
|
+
|
34
|
+
a {
|
35
|
+
color: #09c;
|
36
|
+
text-decoration: none;
|
37
|
+
}
|
38
|
+
|
39
|
+
a:hover {
|
40
|
+
color: #069;
|
41
|
+
text-decoration: underline;
|
42
|
+
}
|
43
|
+
|
44
|
+
a:visited {
|
45
|
+
color: #069;
|
46
|
+
}
|
47
|
+
|
48
|
+
/* Navigation */
|
49
|
+
|
50
|
+
nav {
|
51
|
+
float: right;
|
52
|
+
}
|
53
|
+
|
54
|
+
nav {
|
55
|
+
padding: 0 0.7em;
|
56
|
+
white-space: nowrap;
|
57
|
+
}
|
58
|
+
|
59
|
+
nav ul {
|
60
|
+
margin: 0;
|
61
|
+
padding: 0;
|
62
|
+
}
|
63
|
+
|
64
|
+
nav ul li {
|
65
|
+
list-style-type: none;
|
66
|
+
display: inline-block;
|
67
|
+
padding: 0.2em 0;
|
68
|
+
}
|
69
|
+
|
70
|
+
nav ul li a {
|
71
|
+
padding: 0 5px;
|
72
|
+
font-weight: bold;
|
73
|
+
}
|
74
|
+
|
75
|
+
nav ul li a:visited {
|
76
|
+
color: #09c;
|
77
|
+
}
|
78
|
+
|
79
|
+
nav ul li a:hover {
|
80
|
+
text-decoration: underline;
|
81
|
+
}
|
82
|
+
|
83
|
+
/* Round corners */
|
84
|
+
|
85
|
+
.round {
|
86
|
+
-moz-border-radius: 10px;
|
87
|
+
-webkit-border-radius: 10px;
|
88
|
+
border-radius: 10px;
|
89
|
+
}
|
90
|
+
|
91
|
+
/* Footer */
|
92
|
+
|
93
|
+
footer {
|
94
|
+
background: lightgray;
|
95
|
+
text-align: center;
|
96
|
+
margin-top: 10px;
|
97
|
+
margin-left: auto;
|
98
|
+
margin-right: auto;
|
99
|
+
padding: 10px 0 10px 0;
|
100
|
+
}
|
101
|
+
|
102
|
+
footer nav {
|
103
|
+
float: none;
|
104
|
+
}
|
105
|
+
|
106
|
+
/* Error Messages */
|
107
|
+
|
108
|
+
.field_with_errors {
|
109
|
+
margin-top: 10px;
|
110
|
+
padding: 2px;
|
111
|
+
background-color: red;
|
112
|
+
display: table;
|
113
|
+
}
|
114
|
+
|
115
|
+
.field_with_errors label {
|
116
|
+
color: #fff;
|
117
|
+
}
|
118
|
+
|
119
|
+
#error_explanation {
|
120
|
+
width: 400px;
|
121
|
+
border: 2px solid red;
|
122
|
+
padding: 7px;
|
123
|
+
padding-bottom: 12px;
|
124
|
+
margin-bottom: 20px;
|
125
|
+
background-color: #f0f0f0;
|
126
|
+
}
|
127
|
+
|
128
|
+
#error_explanation h2 {
|
129
|
+
text-align: left;
|
130
|
+
font-weight: bold;
|
131
|
+
padding: 5px 5px 5px 15px;
|
132
|
+
font-size: 12px;
|
133
|
+
margin: -7px;
|
134
|
+
background-color: #c00;
|
135
|
+
color: #fff;
|
136
|
+
}
|
137
|
+
|
138
|
+
#error_explanation p {
|
139
|
+
color: #333;
|
140
|
+
margin-bottom: 0;
|
141
|
+
padding: 5px;
|
142
|
+
}
|
143
|
+
|
144
|
+
#error_explanation ul li {
|
145
|
+
font-size: 12px;
|
146
|
+
list-style: square;
|
147
|
+
}
|
148
|
+
|
149
|
+
/* Flash Messsages */
|
150
|
+
.flash {
|
151
|
+
text-align: center;
|
152
|
+
font-weight: bold;
|
153
|
+
font-size: 150%;
|
154
|
+
margin-top: 1em;
|
155
|
+
}
|
156
|
+
|
157
|
+
/* Sign up button */
|
158
|
+
|
159
|
+
a.signup_button {
|
160
|
+
margin-left: auto;
|
161
|
+
margin-right: auto;
|
162
|
+
display: block;
|
163
|
+
text-align: center;
|
164
|
+
width: 190px;
|
165
|
+
color: #fff;
|
166
|
+
background: #006400;
|
167
|
+
font-size: 150%;
|
168
|
+
font-weight: bold;
|
169
|
+
padding: 20px;
|
170
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class PagesController < ApplicationController
|
2
|
+
before_filter :set_title
|
3
|
+
|
4
|
+
def home
|
5
|
+
end
|
6
|
+
|
7
|
+
def contact
|
8
|
+
end
|
9
|
+
|
10
|
+
def about
|
11
|
+
end
|
12
|
+
|
13
|
+
def help
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_title
|
19
|
+
@title = params[:action].titleize
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
|
3
|
+
def new
|
4
|
+
@title = "Sign In"
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
user = (User.where(:username => params[:session][:login]) | User.where(:email => params[:session][:login])).first
|
9
|
+
if user && user.authenticate(params[:session][:password])
|
10
|
+
signin(user, params[:session][:remember_me])
|
11
|
+
redirect_to root_url, :flash => {:success => "Logged in!"}
|
12
|
+
else
|
13
|
+
flash.now[:error] = "Invalid login/password combination."
|
14
|
+
@title = "Sign in"
|
15
|
+
render 'new'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def destroy
|
20
|
+
signout
|
21
|
+
redirect_to root_url, :notice => "Logged out!"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
before_filter :authenticate, :only => [:edit, :update]
|
3
|
+
before_filter :new_user?, :only => [:new, :create]
|
4
|
+
before_filter :current_user?, :only => [:edit, :update]
|
5
|
+
|
6
|
+
def new
|
7
|
+
@user = User.new
|
8
|
+
@title = "Sign Up"
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@user = User.new(params[:user])
|
13
|
+
if @user.save
|
14
|
+
signin(@user)
|
15
|
+
redirect_to root_url, :flash => {:success => "Signed Up!" }
|
16
|
+
else
|
17
|
+
@title = "Sign Up"
|
18
|
+
render "new"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def edit
|
23
|
+
@title = "Profile Settings"
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
if @user.authenticate(params[:user].delete(:current_password))
|
28
|
+
if @user.update_attributes(params[:user])
|
29
|
+
redirect_to edit_user_path(@user), :flash => {:success => "Settings Updated!"}
|
30
|
+
else
|
31
|
+
@title = "Profile Settings"
|
32
|
+
render 'edit'
|
33
|
+
end
|
34
|
+
else
|
35
|
+
@title = "Profile Settings"
|
36
|
+
flash[:error] = "Please provide correct current password to update profile settings"
|
37
|
+
render 'edit'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def new_user?
|
44
|
+
redirect_to(root_path) if signed_in?
|
45
|
+
end
|
46
|
+
|
47
|
+
def current_user?
|
48
|
+
@user = User.find(params[:id])
|
49
|
+
redirect_to(root_path) unless @user == current_user
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SessionsHelper
|
2
|
+
|
3
|
+
def signin(user, remember = false)
|
4
|
+
if remember
|
5
|
+
cookies.permanent.signed[:remember_token] = [user.id, user.salt]
|
6
|
+
else
|
7
|
+
cookies.signed[:remember_token] = [user.id, user.salt]
|
8
|
+
end
|
9
|
+
@current_user = user
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_user
|
13
|
+
@current_user ||= user_from_remember_token
|
14
|
+
end
|
15
|
+
|
16
|
+
def signed_in?
|
17
|
+
current_user.present?
|
18
|
+
end
|
19
|
+
|
20
|
+
def signout
|
21
|
+
cookies.delete(:remember_token)
|
22
|
+
@current_user = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def authenticate
|
26
|
+
redirect_to signin_path, :notice => "Please sign in to access this page." unless signed_in?
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def user_from_remember_token
|
32
|
+
User.authenticate_with_salt(*remember_token)
|
33
|
+
end
|
34
|
+
|
35
|
+
def remember_token
|
36
|
+
cookies.signed[:remember_token] || [nil, nil]
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
%header.last
|
2
|
+
.container
|
3
|
+
- logo = image_tag('rails.png', :alt => '<%= name.camelcase %>') #, :size => "300x50")
|
4
|
+
= link_to logo, root_path, :class => "left"
|
5
|
+
|
6
|
+
%nav.round.right
|
7
|
+
%ul
|
8
|
+
- unless signed_in?
|
9
|
+
%li= link_to "Sign In", signin_path
|
10
|
+
%li= link_to "Home", root_path
|
11
|
+
%li= link_to "Help", help_path
|
12
|
+
- if signed_in?
|
13
|
+
%li= link_to "Settings", edit_user_path(current_user)
|
14
|
+
%li= link_to "Sign Out", signout_path
|
@@ -0,0 +1,16 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title= @title ? "<%= name.camelcase %> | #{@title}" : '<%= name.camelcase %>'
|
5
|
+
= csrf_meta_tags
|
6
|
+
= render 'layouts/stylesheets'
|
7
|
+
|
8
|
+
%body
|
9
|
+
= render 'layouts/header'
|
10
|
+
.container
|
11
|
+
- flash.each do |key, value|
|
12
|
+
%div{:class => "round flash #{key}"}= value
|
13
|
+
= yield
|
14
|
+
|
15
|
+
= render 'layouts/footer'
|
16
|
+
= render 'layouts/javascripts'
|
File without changes
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class User
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
include Mongoid::Paranoia
|
5
|
+
include ActiveModel::SecurePassword
|
6
|
+
|
7
|
+
has_secure_password
|
8
|
+
|
9
|
+
attr_accessible :provider, :uid, :username, :name, :email, :password, :password_confirmation, :deleted_at
|
10
|
+
|
11
|
+
# Defined fields
|
12
|
+
field :username, :type => String
|
13
|
+
field :email, :type => String
|
14
|
+
field :name, :type => String
|
15
|
+
field :password_digest, :type => String
|
16
|
+
field :admin, :type => Boolean, :default => false
|
17
|
+
|
18
|
+
# DB indexes (always use background to avoid locking)
|
19
|
+
index :username, :unique => true, :background => true
|
20
|
+
index :email, :unique => true, :background => true
|
21
|
+
|
22
|
+
# Validations
|
23
|
+
validates :name,
|
24
|
+
:presence => true,
|
25
|
+
:length => { :maximum => 30 }
|
26
|
+
validates :username,
|
27
|
+
:presence => true,
|
28
|
+
:length => { :maximum => 20 },
|
29
|
+
:format => { :with => /^[A-Za-z\d_]+$/ },
|
30
|
+
:uniqueness => { :case_sensitive => false }
|
31
|
+
validates :email,
|
32
|
+
:presence => true,
|
33
|
+
:format => { :with => /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i },
|
34
|
+
:uniqueness => { :case_sensitive => false }
|
35
|
+
validates :password,
|
36
|
+
:length => { :within => 6..40 },
|
37
|
+
:allow_blank => true
|
38
|
+
|
39
|
+
def salt
|
40
|
+
BCrypt::Password.new(password_digest).salt unless password_digest.blank?
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.authenticate_with_salt(id, cookie_salt)
|
44
|
+
user = User.where(:_id => id).first
|
45
|
+
(user && user.salt == cookie_salt) ? user : nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def toggle_admin!
|
49
|
+
self.admin = !admin
|
50
|
+
save :validate => false
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
%header.last
|
2
|
+
.container
|
3
|
+
- logo = image_tag('rails.png', :alt => '<%= name.camelcase %>') #, :size => "300x50")
|
4
|
+
= link_to logo, root_path, :class => "left"
|
5
|
+
|
6
|
+
%nav.round.right
|
7
|
+
%ul
|
8
|
+
- unless signed_in?
|
9
|
+
%li= link_to "Sign In", signin_path
|
10
|
+
%li= link_to "Home", root_path
|
11
|
+
%li= link_to "Help", help_path
|
12
|
+
- if signed_in?
|
13
|
+
%li= link_to "Settings", edit_user_path(current_user)
|
14
|
+
%li= link_to "Sign Out", signout_path
|
@@ -0,0 +1,16 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title= @title ? "<%= name.camelcase %> | #{@title}" : '<%= name.camelcase %>'
|
5
|
+
= csrf_meta_tags
|
6
|
+
= render 'layouts/stylesheets'
|
7
|
+
|
8
|
+
%body
|
9
|
+
= render 'layouts/header'
|
10
|
+
.container
|
11
|
+
- flash.each do |key, value|
|
12
|
+
%div{:class => "round flash #{key}"}= value
|
13
|
+
= yield
|
14
|
+
|
15
|
+
= render 'layouts/footer'
|
16
|
+
= render 'layouts/javascripts'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
%section.round
|
2
|
+
%h1 Sign In
|
3
|
+
|
4
|
+
= form_for(:session, :url => sessions_path) do |f|
|
5
|
+
.field
|
6
|
+
= f.label :login, "Email or Username"
|
7
|
+
%br
|
8
|
+
= f.text_field :login
|
9
|
+
%br
|
10
|
+
.field
|
11
|
+
= f.label :password
|
12
|
+
%br
|
13
|
+
= f.password_field :password
|
14
|
+
.field
|
15
|
+
= f.label :remember_me
|
16
|
+
= f.check_box :remember_me, :checked => true
|
17
|
+
%br
|
18
|
+
.actions
|
19
|
+
= f.submit "Sign In", :class => 'awesome'
|
20
|
+
%br
|
21
|
+
%p
|
22
|
+
New user?
|
23
|
+
= link_to "Sign Up Now!", signup_path
|