Added badge system

This commit is contained in:
MrYummy
2017-06-18 13:11:36 -04:00
parent 992406a20b
commit 1b4a270038
11 changed files with 124 additions and 29 deletions
+4 -8
View File
@@ -437,18 +437,14 @@ blockquote p {
color: #ddd !important; color: #ddd !important;
} }
} }
.donor {
color: #fff;
background: #f60 !important;
margin-left: 2px !important;
}
.ign { .ign {
display: block; display: block;
color: #000; color: #000;
font-style: italic; font-style: italic;
} }
.badge {
margin-left: 2px !important;
}
} }
#online-users { #online-users {
@@ -1026,4 +1022,4 @@ nav.pagination {
padding: 0.1em 0.2em; padding: 0.1em 0.2em;
border-radius: 0.2em; border-radius: 0.2em;
text-shadow: none; text-shadow: none;
} }
+13 -4
View File
@@ -10,8 +10,6 @@ class UsersController < ApplicationController
if params[:role] if params[:role]
if params[:role].downcase == "staff" if params[:role].downcase == "staff"
@users = User.joins(:role).where("roles.value >= ?", Role.get(:mod).to_i) @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 else
if role = Role.get(params[:role]) if role = Role.get(params[:role])
@users = User.joins(:role).where(role: role) @users = User.joins(:role).where(role: role)
@@ -21,10 +19,18 @@ class UsersController < ApplicationController
return return
end end
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 else
@users = User.joins(:role).where.not(id: User.first.id) #Remove first user @users = User.joins(:role).where.not(id: User.first.id) #Remove first user
end 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 @count = @users.size
@users = @users.page(params[:page]).per(100) @users = @users.page(params[:page]).per(100)
end end
@@ -151,7 +157,7 @@ class UsersController < ApplicationController
def update def update
if (mod? && current_user.role >= @user.role ) || (@user.is?(current_user) && confirmed?) if (mod? && current_user.role >= @user.role ) || (@user.is?(current_user) && confirmed?)
if mod? 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 else
userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about]) userdata = user_params([:name, :skype, :skype_public, :youtube, :twitter, :about])
end end
@@ -164,6 +170,9 @@ class UsersController < ApplicationController
userdata.delete(:role) userdata.delete(:role)
end end
end end
if userdata[:badge]
userdata[:badge] = Badge.get(userdata[:badge])
end
if @user.youtube != userdata[:youtube] if @user.youtube != userdata[:youtube]
youtube = get_youtube(userdata[:youtube]) youtube = get_youtube(userdata[:youtube])
userdata[:youtube] = youtube[:channel] userdata[:youtube] = youtube[:channel]
+18
View File
@@ -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
+2 -1
View File
@@ -5,6 +5,7 @@ class User < ActiveRecord::Base
strip_attributes strip_attributes
belongs_to :role belongs_to :role
belongs_to :badge
has_secure_password has_secure_password
@@ -173,4 +174,4 @@ class User < ActiveRecord::Base
def set_email_token def set_email_token
self.email_token ||= SecureRandom.hex(16) self.email_token ||= SecureRandom.hex(16)
end end
end end
+2 -2
View File
@@ -11,7 +11,7 @@
<li>Donator+ ($20 or more) <li>Donator+ ($20 or more)
</ul> </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> <h3>Perks for you</h3>
<p>For <i>Donator</i> and <i>Donator+</i></p> <p>For <i>Donator</i> and <i>Donator+</i></p>
@@ -45,4 +45,4 @@
</div> </div>
<hr> <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> <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>
+2 -2
View File
@@ -1,4 +1,4 @@
<div class="user"> <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 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? %> <%= 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> </div>
+7 -5
View File
@@ -28,15 +28,17 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Confirmed email address</td> <td>Badge</td>
<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> </td>
</tr> </tr>
<tr> <tr>
<td>Donator</td> <td>Confirmed email address</td>
<td> <td>
<%= f.select :donor, [["No", false], ["Yes", true]], {}, { disabled: !can_edit? } %> <%= f.select :confirmed, [["No", false], ["Yes", true]], {}, { disabled: !can_edit? } %>
</td> </td>
</tr> </tr>
<% end %> <% end %>
@@ -87,4 +89,4 @@
<span class='red-alert'>This user has not confirmed his email!</span> <span class='red-alert'>This user has not confirmed his email!</span>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
+7 -3
View File
@@ -1,12 +1,16 @@
<h1> <h1>
<% if params[:role] %> <% if params[:role] && !params[:badge]%>
<%= title "All '#{params[:role]}' users" %> <%= 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 %> <% else %>
<%= title "All Users" %> <%= title "All Users" %>
<% end %> <% end %>
(<%= @count %>) (<%= @count %>)
</h1> </h1>
<%= link_to "show all", users_path if params[:role] %> <%= link_to "show all", users_path if params[:role] || params[:badge] %>
<div id="userlist"> <div id="userlist">
<% @users.each do |u| %> <% @users.each do |u| %>
@@ -19,4 +23,4 @@
</div> </div>
<% end %> <% end %>
<%= paginate @users %> <%= paginate @users %>
</div> </div>
@@ -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
+8 -2
View File
@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "blogposts", force: :cascade do |t|
t.string "title" t.string "title"
@@ -90,6 +90,12 @@ ActiveRecord::Schema.define(version: 20160926220738) do
t.string "color" t.string "color"
end 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| create_table "sessions", force: :cascade do |t|
t.string "session_id", null: false t.string "session_id", null: false
t.text "data", limit: 65535 t.text "data", limit: 65535
@@ -122,7 +128,6 @@ ActiveRecord::Schema.define(version: 20160926220738) do
t.string "youtube" t.string "youtube"
t.string "youtube_channelname" t.string "youtube_channelname"
t.string "twitter" t.string "twitter"
t.boolean "donor", default: false
t.string "email_token" t.string "email_token"
t.boolean "confirmed", default: false t.boolean "confirmed", default: false
t.datetime "last_seen" 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_own_blogpost_comment", default: true
t.boolean "mail_other_blogpost_comment", default: true t.boolean "mail_other_blogpost_comment", default: true
t.boolean "mail_mention", default: true t.boolean "mail_mention", default: true
t.integer "badge_id"
end end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
+53 -2
View File
@@ -10,6 +10,14 @@ Role.create!([
{name: "superadmin", value: 500, color: "#d22"} {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) userpw = SecureRandom.hex(36)
@@ -23,6 +31,7 @@ deleted_user = User.create!(
password: userpw, password: userpw,
password_confirmation: userpw, password_confirmation: userpw,
role: Role.get(:disabled), role: Role.get(:disabled),
badge: Badge.get(:none),
skype: "echo123", skype: "echo123",
skype_public: true, skype_public: true,
last_ip: "0.0.0.0", last_ip: "0.0.0.0",
@@ -37,5 +46,47 @@ User.create!(
email: "jomo@example.com", email: "jomo@example.com",
password: "123456789", # high seructity! password: "123456789", # high seructity!
password_confirmation: "123456789", password_confirmation: "123456789",
role: Role.get(:superadmin) 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
)