Added badge system

This commit is contained in:
MrYummy
2017-05-28 17:39:06 -04:00
parent 992406a20b
commit 276949c0cd
11 changed files with 124 additions and 29 deletions

View File

@@ -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;
}
}

View File

@@ -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]

18
app/models/badge.rb Normal file
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

View File

@@ -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
end

View File

@@ -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>
<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>

View File

@@ -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>
<%= 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>

View File

@@ -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 %>
<% end %>

View File

@@ -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>
</div>

View File

@@ -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

View File

@@ -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

View File

@@ -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)
)
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
)