summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMrYummy <elemental428@gmail.com>2017-05-28 17:39:06 -0400
committerMrYummy <elemental428@gmail.com>2017-06-18 13:11:36 -0400
commit1b4a270038cb5055be79269fff07fab92a6c5d92 (patch)
tree09f496b117f3eaa896be6fac90bdb2fb19522307
parent992406a20b90d47d1ef8a9b4f8d0c599590a1171 (diff)
Added badge system
-rw-r--r--app/assets/stylesheets/style.css.scss12
-rw-r--r--app/controllers/users_controller.rb17
-rw-r--r--app/models/badge.rb18
-rw-r--r--app/models/user.rb3
-rw-r--r--app/views/statics/donate.html.erb4
-rw-r--r--app/views/users/_username.html.erb4
-rw-r--r--app/views/users/edit.html.erb12
-rw-r--r--app/views/users/index.html.erb10
-rw-r--r--db/migrate/20170319193517_add_badge_id_to_users.rb8
-rw-r--r--db/schema.rb10
-rw-r--r--db/seeds.rb55
11 files changed, 124 insertions, 29 deletions
diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss
index 6de5aa2..da15801 100644
--- a/app/assets/stylesheets/style.css.scss
+++ b/app/assets/stylesheets/style.css.scss
@@ -437,18 +437,14 @@ blockquote p {
color: #ddd !important;
}
}
-
- .donor {
- color: #fff;
- background: #f60 !important;
- margin-left: 2px !important;
- }
-
.ign {
display: block;
color: #000;
font-style: italic;
}
+ .badge {
+ margin-left: 2px !important;
+ }
}
#online-users {
@@ -1026,4 +1022,4 @@ nav.pagination {
padding: 0.1em 0.2em;
border-radius: 0.2em;
text-shadow: none;
-} \ No newline at end of file
+}
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 5dc0e80..27e89af 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -10,8 +10,6 @@ class UsersController < ApplicationController
if params[:role]
if params[:role].downcase == "staff"
@users = User.joins(:role).where("roles.value >= ?", Role.get(:mod).to_i)
- elsif params[:role].downcase == "donor"
- @users = User.joins(:role).where(donor: true)
else
if role = Role.get(params[:role])
@users = User.joins(:role).where(role: role)
@@ -21,10 +19,18 @@ class UsersController < ApplicationController
return
end
end
+ elsif params[:badge]
+ if badge = Badge.get(params[:badge])
+ @users = User.joins(:badge).where(badge: badge)
+ else
+ flash[:alert] = "badge '#{params[:badge]}' does not exist!"
+ redirect_to users_path
+ return
+ end
else
@users = User.joins(:role).where.not(id: User.first.id) #Remove first user
end
- @users = @users.order("roles.value desc", "confirmed desc", :name)
+ @users = @users.order("roles.value desc", "confirmed desc", :name) unless params[:badge]
@count = @users.size
@users = @users.page(params[:page]).per(100)
end
@@ -151,7 +157,7 @@ class UsersController < ApplicationController
def update
if (mod? && current_user.role >= @user.role ) || (@user.is?(current_user) && confirmed?)
if mod?
- userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about, :role, :confirmed, :donor])
+ userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about, :role, :badge, :confirmed])
else
userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about])
end
@@ -164,6 +170,9 @@ class UsersController < ApplicationController
userdata.delete(:role)
end
end
+ if userdata[:badge]
+ userdata[:badge] = Badge.get(userdata[:badge])
+ end
if @user.youtube != userdata[:youtube]
youtube = get_youtube(userdata[:youtube])
userdata[:youtube] = youtube[:channel]
diff --git a/app/models/badge.rb b/app/models/badge.rb
new file mode 100644
index 0000000..a7ff831
--- /dev/null
+++ b/app/models/badge.rb
@@ -0,0 +1,18 @@
+class Badge < ActiveRecord::Base
+ include Comparable
+ has_many :users
+
+ def self.get (input)
+ if input.is_a?(String) || input.is_a?(Symbol)
+ Badge.find_by_name(input)
+ elsif input.is_a?(Fixnum)
+ Badge.find_by_id(input)
+ elsif input.is_a?(Badge)
+ return input
+ end
+ end
+
+ def to_s
+ self.name
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index c422e28..ab7471e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -5,6 +5,7 @@ class User < ActiveRecord::Base
strip_attributes
belongs_to :role
+ belongs_to :badge
has_secure_password
@@ -173,4 +174,4 @@ class User < ActiveRecord::Base
def set_email_token
self.email_token ||= SecureRandom.hex(16)
end
-end \ No newline at end of file
+end
diff --git a/app/views/statics/donate.html.erb b/app/views/statics/donate.html.erb
index 2831807..774d917 100644
--- a/app/views/statics/donate.html.erb
+++ b/app/views/statics/donate.html.erb
@@ -11,7 +11,7 @@
<li>Donator+ ($20 or more)
</ul>
-<p>We also have <%= link_to "list of users who donated", users_path(role: "donor") %> already!</p>
+<p>We also have <%= link_to "list of users who donated", users_path(badge: "donor") %> already!</p>
<h3>Perks for you</h3>
<p>For <i>Donator</i> and <i>Donator+</i></p>
@@ -45,4 +45,4 @@
</div>
<hr>
-<p class="small">Please note that you are not buying anything. We do not guarantee for these perks, however, we will try hard to make sure you'll get them! Donations are processed manually, it can take a few hours.</p> \ No newline at end of file
+<p class="small">Please note that you are not buying anything. We do not guarantee for these perks, however, we will try hard to make sure you'll get them! Donations are processed manually, it can take a few hours.</p>
diff --git a/app/views/users/_username.html.erb b/app/views/users/_username.html.erb
index 10adb36..4e78673 100644
--- a/app/views/users/_username.html.erb
+++ b/app/views/users/_username.html.erb
@@ -1,4 +1,4 @@
<div class="user">
<%= link_to user.name, user, class: "role #{user.role.name} #{"banned" if user.banned?} #{"disabled" if user.disabled?} #{"unconfirmed" unless user.confirmed?}", title: "#{user.ign} – #{user.role}", style: "color: #{fcolor(user.role.color)}; background-color: #{user.role.color}" %>
- <%= link_to "$", donate_statics_path, class: "role donor", title: "Donator" if user.donor? %>
-</div> \ No newline at end of file
+ <%= link_to user.badge.symbol, users_path(badge: user.badge.name), class: "role badge", title: user.badge.name, style: "color: #{fcolor(user.badge.color)}; background-color: #{user.badge.color}" unless user.badge.value == 0 %>
+</div>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb
index 6a6fe4d..5e63c00 100644
--- a/app/views/users/edit.html.erb
+++ b/app/views/users/edit.html.erb
@@ -28,15 +28,17 @@
</td>
</tr>
<tr>
- <td>Confirmed email address</td>
+ <td>Badge</td>
<td>
- <%= f.select :confirmed, [["No", false], ["Yes", true]], {}, { disabled: !can_edit? } %>
+ <% if current_user.role >= Role.get(:mod) %>
+ <%= f.select :badge, Badge.all %>
+ <% end %>
</td>
</tr>
<tr>
- <td>Donator</td>
+ <td>Confirmed email address</td>
<td>
- <%= f.select :donor, [["No", false], ["Yes", true]], {}, { disabled: !can_edit? } %>
+ <%= f.select :confirmed, [["No", false], ["Yes", true]], {}, { disabled: !can_edit? } %>
</td>
</tr>
<% end %>
@@ -87,4 +89,4 @@
<span class='red-alert'>This user has not confirmed his email!</span>
<% end %>
<% end %>
-<% end %> \ No newline at end of file
+<% end %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
index 883ffb0..95ab480 100644
--- a/app/views/users/index.html.erb
+++ b/app/views/users/index.html.erb
@@ -1,12 +1,16 @@
<h1>
- <% if params[:role] %>
+ <% if params[:role] && !params[:badge]%>
<%= title "All '#{params[:role]}' users" %>
+ <% elsif params[:badge] && !params[:role] %>
+ <%= title "All '#{params[:badge]}' users" %>
+ <% elsif params[:role] && params[:badge] %>
+ <%= title "All '#{params[:role]}' and '#{params[:badge]}' users" %>
<% else %>
<%= title "All Users" %>
<% end %>
(<%= @count %>)
</h1>
-<%= link_to "show all", users_path if params[:role] %>
+<%= link_to "show all", users_path if params[:role] || params[:badge] %>
<div id="userlist">
<% @users.each do |u| %>
@@ -19,4 +23,4 @@
</div>
<% end %>
<%= paginate @users %>
-</div> \ No newline at end of file
+</div>
diff --git a/db/migrate/20170319193517_add_badge_id_to_users.rb b/db/migrate/20170319193517_add_badge_id_to_users.rb
new file mode 100644
index 0000000..08328cf
--- /dev/null
+++ b/db/migrate/20170319193517_add_badge_id_to_users.rb
@@ -0,0 +1,8 @@
+class AddBadgeIdToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :badge_id, :integer
+ add_column :users, :badge_id, :integer, default: 0
+ User.where(donor: true).update_all(badge_id: 1)
+ remove_column :users, :donor
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2c68029..b38ae38 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160926220738) do
+ActiveRecord::Schema.define(version: 20170319193517) do
create_table "blogposts", force: :cascade do |t|
t.string "title"
@@ -90,6 +90,12 @@ ActiveRecord::Schema.define(version: 20160926220738) do
t.string "color"
end
+ create_table "badges", force: :cascade do |t|
+ t.string "name"
+ t.string "symbol"
+ t.string "color"
+ end
+
create_table "sessions", force: :cascade do |t|
t.string "session_id", null: false
t.text "data", limit: 65535
@@ -122,7 +128,6 @@ ActiveRecord::Schema.define(version: 20160926220738) do
t.string "youtube"
t.string "youtube_channelname"
t.string "twitter"
- t.boolean "donor", default: false
t.string "email_token"
t.boolean "confirmed", default: false
t.datetime "last_seen"
@@ -134,6 +139,7 @@ ActiveRecord::Schema.define(version: 20160926220738) do
t.boolean "mail_own_blogpost_comment", default: true
t.boolean "mail_other_blogpost_comment", default: true
t.boolean "mail_mention", default: true
+ t.integer "badge_id"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
diff --git a/db/seeds.rb b/db/seeds.rb
index 780ddb5..06c8d10 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -10,6 +10,14 @@ Role.create!([
{name: "superadmin", value: 500, color: "#d22"}
])
+Badge.create!([
+ {name: "none", symbol: "", color: "#000"},
+ {name: "donor", symbol: "$", color: "#f60"},
+ {name: "developer", symbol: "D", color: "#a0a"},
+ {name: "retired", symbol: "R", color: "#0aa"},
+ {name: "lead", symbol: "L", color: "#a00"}
+])
+
userpw = SecureRandom.hex(36)
@@ -23,6 +31,7 @@ deleted_user = User.create!(
password: userpw,
password_confirmation: userpw,
role: Role.get(:disabled),
+ badge: Badge.get(:none),
skype: "echo123",
skype_public: true,
last_ip: "0.0.0.0",
@@ -37,5 +46,47 @@ User.create!(
email: "jomo@example.com",
password: "123456789", # high seructity!
password_confirmation: "123456789",
- role: Role.get(:superadmin)
-) \ No newline at end of file
+ role: Role.get(:superadmin),
+ badge: Badge.get(:donor),
+ confirmed: true
+)
+User.create!(
+ uuid: "7f52491ab5d64c11b4a43806db47a101",
+ ign: "YummyRedstone",
+ email: "yummy@example.com",
+ password: "123456789", # high seructity!
+ password_confirmation: "123456789",
+ role: Role.get(:admin),
+ badge: Badge.get(:lead),
+ confirmed: true
+)
+User.create!(
+ uuid: "d2693e9193e14e3f929ff38e1ce8df03",
+ ign: "Pepich1851",
+ email: "pepe@example.com",
+ password: "123456789", # high seructity!
+ password_confirmation: "123456789",
+ role: Role.get(:superadmin),
+ badge: Badge.get(:retired),
+ confirmed: true
+)
+User.create!(
+ uuid: "c69f8316c60a4f8ca922bda933e01acd",
+ ign: "Doomblah",
+ email: "doom@example.com",
+ password: "123456789", # high seructity!
+ password_confirmation: "123456789",
+ role: Role.get(:normal),
+ badge: Badge.get(:developer),
+ confirmed: true
+)
+User.create!(
+ uuid: "b85a91b558b0474da2a42d5dd025f9e5",
+ ign: "Futsy",
+ email: "futsy@example.com",
+ password: "123456789", # high seructity!
+ password_confirmation: "123456789",
+ role: Role.get(:mod),
+ badge: Badge.get(:none),
+ confirmed: true
+)