Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
final_project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
evilla_gomez_guian_principe
final_project
Commits
16417474
Commit
16417474
authored
Jul 20, 2016
by
Jasmine Principe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated authorization
parent
1e447e08
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
34 deletions
+67
-34
users_controller.rb
Halalan/app/controllers/users_controller.rb
+1
-1
user.rb
Halalan/app/models/user.rb
+9
-9
edit.html.erb
Halalan/app/views/devise/registrations/edit.html.erb
+25
-23
new.html.erb
Halalan/app/views/devise/registrations/new.html.erb
+1
-1
_user.html.erb
Halalan/app/views/users/_user.html.erb
+12
-0
index.html.erb
Halalan/app/views/users/index.html.erb
+16
-0
show.html.erb
Halalan/app/views/users/show.html.erb
+3
-0
No files found.
Halalan/app/controllers/users_controller.rb
View file @
16417474
...
@@ -34,7 +34,7 @@ class UsersController < ApplicationController
...
@@ -34,7 +34,7 @@ class UsersController < ApplicationController
def
admin_only
def
admin_only
unless
current_user
.
admin?
unless
current_user
.
admin?
redirect_to
:back
,
:alert
=>
"Access denied."
redirect_to
root_path
,
:alert
=>
"Access denied."
end
end
end
end
...
...
Halalan/app/models/user.rb
View file @
16417474
class
User
<
ApplicationRecord
class
User
<
ApplicationRecord
enum
role:
{
voter:
0
,
admin:
1
}
after_initialize
:set_default_role
,
:if
=>
:new_record?
def
set_default_role
self
.
role
||=
:voter
end
has_many
:votes
,
dependent: :destroy
has_many
:votes
,
dependent: :destroy
devise
:database_authenticatable
,
:registerable
,
devise
:database_authenticatable
,
:registerable
,
...
@@ -12,12 +20,4 @@ class User < ApplicationRecord
...
@@ -12,12 +20,4 @@ class User < ApplicationRecord
def
full_name
def
full_name
"
#{
self
.
first_name
}
#{
self
.
last_name
}
"
"
#{
self
.
first_name
}
#{
self
.
last_name
}
"
end
end
enum
role:
{
voter:
0
,
admin:
1
}
after_initialize
:set_default_role
,
:if
=>
:new_record?
def
set_default_role
self
.
role
=
:voter
end
end
end
Halalan/app/views/devise/registrations/edit.html.erb
View file @
16417474
<h2>
Edit
<%=
resource_name
.
to_s
.
humanize
%>
</h2>
<div
class=
"authform"
>
<h2>
Edit
<%=
resource_name
.
to_s
.
humanize
%>
</h2>
<%=
simple_form_for
(
resource
,
as:
resource_name
,
url:
registration_path
(
resource_name
),
html:
{
method: :put
})
do
|
f
|
%>
<%=
simple_form_for
(
resource
,
as:
resource_name
,
url:
registration_path
(
resource_name
),
html:
{
method: :put
,
:role
=>
'form'
})
do
|
f
|
%>
<%=
f
.
error_notification
%>
<%=
f
.
error_notification
%>
<div
class=
"form-inputs"
>
<div
class=
"form-inputs"
>
...
@@ -22,10 +23,11 @@
...
@@ -22,10 +23,11 @@
<div
class=
"form-actions"
>
<div
class=
"form-actions"
>
<%=
f
.
button
:submit
,
"Update"
%>
<%=
f
.
button
:submit
,
"Update"
%>
</div>
</div>
<%
end
%>
<%
end
%>
<h3>
Cancel my account
</h3>
<h3>
Cancel my account
</h3>
<p>
Unhappy?
<%=
link_to
"Cancel my account"
,
registration_path
(
resource_name
),
data:
{
confirm:
"Are you sure?"
},
method: :delete
%>
</p>
<p>
Unhappy?
<%=
link_to
"Cancel my account"
,
registration_path
(
resource_name
),
data:
{
confirm:
"Are you sure?"
},
method: :delete
%>
</p>
<%=
link_to
"Back"
,
:back
%>
<%=
link_to
"Back"
,
:back
%>
</div>
\ No newline at end of file
Halalan/app/views/devise/registrations/new.html.erb
View file @
16417474
<h2>
Sign up
</h2>
<h2>
Sign up
</h2>
<%=
simple_form_for
(
resource
,
as:
resource_name
,
url:
registration_path
(
resource_name
))
do
|
f
|
%>
<%=
simple_form_for
(
resource
,
as:
resource_name
,
url:
registration_path
(
resource_name
)
,
:html
=>
{
:role
=>
'form'
}
)
do
|
f
|
%>
<%=
f
.
error_notification
%>
<%=
f
.
error_notification
%>
<div
class=
"form-inputs"
>
<div
class=
"form-inputs"
>
...
...
Halalan/app/views/users/_user.html.erb
0 → 100644
View file @
16417474
<td>
<%=
link_to
user
.
email
,
user
%>
</td>
<td>
<%=
form_for
(
user
)
do
|
f
|
%>
<%=
f
.
select
(
:role
,
User
.
roles
.
keys
.
map
{
|
role
|
[
role
.
titleize
,
role
]})
%>
<%=
f
.
submit
'Change Role'
,
:class
=>
'button-xs'
%>
<%
end
%>
</td>
<td>
<%=
link_to
(
"Delete user"
,
user_path
(
user
),
:data
=>
{
:confirm
=>
"Are you sure?"
},
:method
=>
:delete
,
:class
=>
'button-xs'
)
unless
user
==
current_user
%>
</td>
\ No newline at end of file
Halalan/app/views/users/index.html.erb
0 → 100644
View file @
16417474
<div
class=
"container"
>
<div
class=
"row"
>
<h3>
Users
</h3>
<div
class=
"column"
>
<table
class=
"table"
>
<tbody>
<%
@users
.
each
do
|
user
|
%>
<tr>
<%=
render
user
%>
</tr>
<%
end
%>
</tbody>
</table>
</div>
</div>
</div>
\ No newline at end of file
Halalan/app/views/users/show.html.erb
0 → 100644
View file @
16417474
<h3>
User
</h3>
<p>
Name:
<%=
@user
.
name
if
@user
.
name
%>
</p>
<p>
Email:
<%=
@user
.
email
if
@user
.
email
%>
</p>
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