Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sample_app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tô Ngọc Ánh
sample_app
Commits
49d2b018
Commit
49d2b018
authored
Jul 03, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sign-in-out' into 'master'
Finish sign in See merge request
!7
parents
9c90e762
3325c153
Pipeline
#672
failed with stages
in 0 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
48 additions
and
3 deletions
+48
-3
app/assets/javascripts/application.js
+1
-0
app/controllers/sessions_controller.rb
+3
-1
app/controllers/users_controller.rb
+1
-0
app/helpers/sessions_helper.rb
+6
-0
app/views/layouts/_header.html.erb
+18
-1
config/database.yml
+5
-1
lib/tasks/.keep
+0
-0
spec/requests/authentication_pages_spec.rb
+5
-0
spec/requests/user_pages_spec.rb
+9
-0
No files found.
app/assets/javascripts/application.js
View file @
49d2b018
...
@@ -12,5 +12,6 @@
...
@@ -12,5 +12,6 @@
//
//
//= require jquery
//= require jquery
//= require jquery_ujs
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require turbolinks
//= require_tree .
//= require_tree .
app/controllers/sessions_controller.rb
View file @
49d2b018
...
@@ -7,7 +7,7 @@ class SessionsController < ApplicationController
...
@@ -7,7 +7,7 @@ class SessionsController < ApplicationController
user
=
User
.
find_by
(
email:
params
[
:session
][
:email
].
downcase
)
user
=
User
.
find_by
(
email:
params
[
:session
][
:email
].
downcase
)
if
user
&&
user
.
authenticate
(
params
[
:session
][
:password
])
if
user
&&
user
.
authenticate
(
params
[
:session
][
:password
])
# Sign the user in and redirect to the user's show page.
# Sign the user in and redirect to the user's show page.
sign_in
user
sign_in
(
user
)
redirect_to
user
redirect_to
user
else
else
flash
.
now
[
:error
]
=
'Invalid email/password combination'
# Not quite right!
flash
.
now
[
:error
]
=
'Invalid email/password combination'
# Not quite right!
...
@@ -16,5 +16,7 @@ class SessionsController < ApplicationController
...
@@ -16,5 +16,7 @@ class SessionsController < ApplicationController
end
end
def
destroy
def
destroy
sign_out
redirect_to
root_url
end
end
end
end
app/controllers/users_controller.rb
View file @
49d2b018
...
@@ -10,6 +10,7 @@ class UsersController < ApplicationController
...
@@ -10,6 +10,7 @@ class UsersController < ApplicationController
def
create
def
create
@user
=
User
.
new
(
user_params
)
@user
=
User
.
new
(
user_params
)
if
@user
.
save
if
@user
.
save
sign_in
(
@user
)
flash
[
:success
]
=
"Welcome to the Sample App"
flash
[
:success
]
=
"Welcome to the Sample App"
redirect_to
@user
redirect_to
@user
else
else
...
...
app/helpers/sessions_helper.rb
View file @
49d2b018
...
@@ -18,4 +18,10 @@ module SessionsHelper
...
@@ -18,4 +18,10 @@ module SessionsHelper
remember_token
=
User
.
digest
(
cookies
[
:remember_token
])
remember_token
=
User
.
digest
(
cookies
[
:remember_token
])
@current_user
||=
User
.
find_by
(
remember_token:
remember_token
)
@current_user
||=
User
.
find_by
(
remember_token:
remember_token
)
end
end
def
sign_out
current_user
.
update_attribute
(
:remember_token
,
User
.
digest
(
User
.
new_remember_token
))
cookies
.
delete
(
:remember_token
)
self
.
current_user
=
nil
end
end
end
app/views/layouts/_header.html.erb
View file @
49d2b018
...
@@ -6,7 +6,24 @@
...
@@ -6,7 +6,24 @@
<ul
class=
"nav pull-right"
>
<ul
class=
"nav pull-right"
>
<li>
<%=
link_to
"Home"
,
home_path
%>
</li>
<li>
<%=
link_to
"Home"
,
home_path
%>
</li>
<li>
<%=
link_to
"Help"
,
help_path
%>
</li>
<li>
<%=
link_to
"Help"
,
help_path
%>
</li>
<li>
<%=
link_to
"Sign in"
,
signin_path
%>
</li>
<%
if
signed_in?
%>
<li>
<%=
link_to
"Users"
,
'#'
%>
</li>
<li
id=
"fat-menu"
class=
"dropdown"
>
<a
href=
"#"
class=
"dropdown-toggle"
data-toggle=
"dropdown"
>
Account
<b
class=
"caret"
></b>
</a>
<ul
class=
"dropdown-menu"
>
<li>
<%=
link_to
"Profile"
,
current_user
%>
</li>
<li>
<%=
link_to
"Settings"
,
'#'
%>
</li>
<li
class=
"divider"
></li>
<li>
<%=
link_to
"Sign out"
,
signout_path
,
method: :delete
%>
</li>
</ul>
</li>
<%
else
%>
<li>
<%=
link_to
"Sign in"
,
signin_path
%>
</li>
<%
end
%>
</ul>
</ul>
</nav>
</nav>
</div>
</div>
...
...
config/database.yml
View file @
49d2b018
...
@@ -16,7 +16,7 @@ development:
...
@@ -16,7 +16,7 @@ development:
# Warning: The database defined as "test" will be erased and
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
# Do not set this db to the same as development or production.
test
:
test
:
&test
<<
:
*default
<<
:
*default
database
:
db/test.sqlite3
database
:
db/test.sqlite3
...
@@ -25,3 +25,6 @@ production:
...
@@ -25,3 +25,6 @@ production:
adapter
:
postgresql
adapter
:
postgresql
encoding
:
unicode
encoding
:
unicode
url
:
<%= ENV['DATABASE_URL'] %>
url
:
<%= ENV['DATABASE_URL'] %>
cucumber
:
<<
:
*test
\ No newline at end of file
lib/tasks/.keep
deleted
100644 → 0
View file @
9c90e762
spec/requests/authentication_pages_spec.rb
View file @
49d2b018
...
@@ -36,6 +36,11 @@ describe "AuthenticationPages" do
...
@@ -36,6 +36,11 @@ describe "AuthenticationPages" do
it
{
should
have_link
(
'Profile'
,
href:
user_path
(
user
))
}
it
{
should
have_link
(
'Profile'
,
href:
user_path
(
user
))
}
it
{
should
have_link
(
'Sign out'
,
href:
signout_path
)
}
it
{
should
have_link
(
'Sign out'
,
href:
signout_path
)
}
it
{
should_not
have_link
(
'Sign in'
,
href:
signin_path
)
}
it
{
should_not
have_link
(
'Sign in'
,
href:
signin_path
)
}
describe
"followed by signout"
do
before
{
click_link
"Sign out"
}
it
{
should
have_link
(
'Sign in'
)
}
end
end
end
end
end
end
end
spec/requests/user_pages_spec.rb
View file @
49d2b018
...
@@ -43,6 +43,15 @@ describe "User pages" do
...
@@ -43,6 +43,15 @@ describe "User pages" do
it
"should create a user"
do
it
"should create a user"
do
expect
{
click_button
submit
}.
to
change
(
User
,
:count
).
by
(
1
)
expect
{
click_button
submit
}.
to
change
(
User
,
:count
).
by
(
1
)
end
end
describe
"after saving the user"
do
before
{
click_button
submit
}
let
(
:user
)
{
User
.
find_by
(
email:
'user@example.com'
)
}
it
{
should
have_link
(
'Sign out'
)
}
it
{
should
have_title
(
user
.
name
)
}
it
{
should
have_selector
(
'div.alert.alert-success'
,
text:
'Welcome'
)
}
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment