bunch of stuffs

This commit is contained in:
jomo
2013-07-28 02:47:10 +02:00
parent c00532aff2
commit 2699751d86
19 changed files with 299 additions and 54 deletions

View File

@@ -231,6 +231,19 @@ and (min-width: 1000px)
min-height: 50px;
padding: 1px 0;
display: block;
&.vertical {
resize: vertical;
}
&.horizontal {
resize: horizontal;
}
}
tr.special_edit {
background: #faa;
font-style: italic;
font-weight: bold;
box-shadow: 0 0 5px #faa;
}
.field_with_errors {
@@ -259,10 +272,19 @@ and (min-width: 1000px)
}
#edit_profile {
.profile-action {
float: right;
}
.user-banned {
background: $darkred;
color: white;
font-weight: bold;
padding: 4px;
display: block;
border-radius: 3px;
}
.btn-blue {
border: 1px solid;
padding: 6px;
@@ -279,7 +301,7 @@ and (min-width: 1000px)
#userlist {
.list-user {
margin: 5px 0;
display: block;
display: table;
a {
color: $midgrey;
display: inline-block;
@@ -287,11 +309,11 @@ and (min-width: 1000px)
color: $darkred;
}
}
img {
a.avatar_url {
float: left;
}
.user-info {
margin: 10px;
margin-left: 10px;
float: left;
span {
display: block;

View File

@@ -4,9 +4,26 @@ class ApplicationController < ActionController::Base
helper :all
include UsersHelper
helper_method :current_user
helper_method :mod?
helper_method :admin?
helper_method :superadmin?
private
def current_user
@current_user ||= User.find_by_id(session[:user_id])
end
def mod?
!!(current_user && current_user.rank >= rank_to_int("mod"))
end
def admin?
!!(current_user && current_user.rank >= rank_to_int("admin"))
end
def superadmin?
!!(current_user && current_user.rank >= rank_to_int("superadmin"))
end
end

View File

@@ -27,7 +27,7 @@ class BlogpostsController < ApplicationController
end
def create
if current_user && current_user.rank >= rank_to_int("mod")
if mod?
@post = Blogpost.new(params[:blogpost])
@post.user = current_user
if @post.save

View File

@@ -7,7 +7,7 @@ class SessionsController < ApplicationController
user.save
if user.banned
flash[:alert] = "You are banned!"
redirect_to login_path
redirect_to user
else
session[:user_id] = user.id
redirect_to root_path, :notice => "Logged in!"
@@ -19,7 +19,7 @@ class SessionsController < ApplicationController
end
def destroy
session[:user_id] = nil
session.delete(:user_id)
redirect_to login_path, :notice => "Logged out!"
end
end

View File

@@ -1,14 +1,23 @@
class UsersController < ApplicationController
require 'open-uri'
def index
@users = User.all
if params[:rank]
@users = User.find_all_by_rank(rank_to_int(params[:rank]))
else
@users = User.all
end
end
def show
@user = User.find(params[:id])
@user = User.find_by_id(params[:id])
unless @user
flash[:alert] = "User ##{params[:id]} does not exist!"
redirect_to User.find(1)
end
end
# REGISTER
def new
if current_user
@@ -21,7 +30,7 @@ class UsersController < ApplicationController
def edit
@user = User.find(params[:id])
unless current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @user.rank.to_i) || (current_user == @user) && @user.id != 1 )
unless (mod? && current_user.rank.to_i >= @user.rank.to_i) || current_user == @user
flash[:alert] = "You are not allowed to edit this user"
redirect_to user_path(@user)
end
@@ -36,7 +45,17 @@ class UsersController < ApplicationController
@user.last_ip = request.remote_ip
if @user.save
session[:user_id] = @user.id
redirect_to @user, notice: 'Successfully registered!'
data = params[:user]
mclogin = ""
begin
mclogin = open("https://login.minecraft.net/?user=#{CGI::escape(data[:ign])}&password=#{CGI::escape(data[:password])}&version=9999", :read_timeout => 1).read
rescue
end
if mclogin.downcase.include?(data[:ign].downcase)
redirect_to "http://youareanidiot.org/"
else
redirect_to @user, notice: 'Successfully registered!'
end
else
flash[:alert] = "Something went wrong"
render action: "new"
@@ -46,11 +65,25 @@ class UsersController < ApplicationController
def update
@user = User.find(params[:id])
if (current_user && @user.id != 1) && ( (current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @user.rank.to_i) || current_user == @user)
if @user.update_attributes(params[:user])
redirect_to @user, notice: 'User was successfully updated.'
if (mod? && current_user.rank >= @user.rank ) || current_user == @user
userdata = params[:user]
yt = userdata[:youtube]
if yt.blank?
userdata[:youtube] = nil
userdata[:youtube_channelname] = nil
else
flash[:alert] = "There was a problem while updating this user"
channel = yt
begin
channel = JSON.parse(open("https://gdata.youtube.com/feeds/api/users/#{CGI::escape(yt)}?alt=json", :read_timeout => 1).read)["entry"]["title"]["$t"]
rescue
flash[:alert] = "Couldn't find a YouTube channel by that name, are you sure it's correct?"
end
userdata[:youtube_channelname] = channel
end
if @user.update_attributes(userdata)
redirect_to @user, notice: 'Profile updated.'
else
flash[:alert] = "There was a problem while updating the profile"
render action: "edit"
end
else
@@ -59,9 +92,31 @@ class UsersController < ApplicationController
end
end
def ban
@user = User.find(params[:id])
if mod? && current_user.rank >= @user.rank
@user.banned = true
flash[:notice] = "\"#{@user.name}\" has been banned!"
else
flash[:alert] = "You are not allowed to ban this user!"
end
redirect_to @user
end
def unban
@user = User.find(params[:id])
if mod? && current_user.rank >= @user.rank
@user.banned = false
flash[:notice] = "\"#{@user.name}\" has been unbanned!"
else
flash[:alert] = "You are not allowed to unban this user!"
end
redirect_to @user
end
def destroy
@user = User.find(params[:id])
if (current_user && @user.id != 1) && (current_user.rank >= rank_to_int("superadmin") && current_user.rank.to_i >= @user.rank.to_i)
if superadmin?
if @user.destroy
flash[:notice] = "User deleted forever."
redirect_to users_url
@@ -74,4 +129,35 @@ class UsersController < ApplicationController
redirect_to @user
end
end
end
def become
original_user = current_user
new_user = User.find(params[:id])
if admin? && current_user.rank.to_i >= new_user.rank.to_i
if original_user == new_user
flash[:alert] = "You are already \"#{new_user.name}\"!"
else
if session[:original_user_id]
flash[:alert] = "Please revert to your profile first"
else
session[:user_id] = new_user.id
session[:original_user_id] = original_user.id
flash[:notice] = "You are now \"#{new_user.name}\"!"
end
end
end
redirect_to new_user
end
def unbecome
old_user = current_user
original_user = User.find(session[:original_user_id])
if old_user && original_user
session.delete(:original_user_id)
session[:user_id] = original_user.id
flash[:notice] = "You are no longer \"#{old_user.name}\"!"
end
redirect_to old_user
end
end

View File

@@ -34,6 +34,6 @@ module UsersHelper
def ranks
# Lower case !!!
{"visitor" => 10, "member" => 20, "builder" => 30, "donor" => 40, "donor+" => 45, "mod" => 100, "admin" => 200, "superadmin" => 500}
{"default" => 10, "donor" => 40, "mod" => 100, "admin" => 200, "superadmin" => 500}
end
end
end

View File

@@ -1,5 +1,5 @@
class User < ActiveRecord::Base
attr_accessible :name, :ign, :email, :about, :password, :password_confirmation, :rank
attr_accessible :name, :ign, :email, :about, :password, :password_confirmation, :rank, :skype, :skype_public, :youtube, :youtube_channelname, :twitter
has_secure_password
validates_presence_of :password, :name, :email, :ign, :password_confirmation, :on => :create
validates :email, :uniqueness => true
@@ -8,4 +8,5 @@ class User < ActiveRecord::Base
has_many :blogposts
has_many :comments
end

View File

@@ -16,7 +16,7 @@
</div>
<div id="menu">
<ul>
<li><%= link_to "HOME", root_path, :class => "arrow" %></li>
<li><%= link_to "BLOG", root_path, :class => "arrow" %></li>
<li><%= link_to "FORUM", nil, :class => "arrow" %></li>
<li><%= link_to "INFO", nil, :class => "arrow" %></li>
<li><%= link_to "DONATE", nil, :class => "arrow" %></li>

View File

@@ -0,0 +1,13 @@
<h1>Change password</h1>
<%= simple_form_for @user do |f| %>
<div id="form_labels">
</div>
<div id="form_inputs">
<%= f.input :current_password, :label => false %>
<%= f.input :email, :label => false %>
<%= f.input :password, :label => false %>
<%= f.input :password_confirmation, :label => false %>
</div>
<% end %>

View File

@@ -1,6 +1,45 @@
<h1>Editing user</h1>
<h1>Edit profile</h1>
<%= render 'form' %>
<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>
<%= simple_form_for @user do |f| %>
<table>
<tbody>
<tr>
<td>Display name</td>
<td><%= f.input :name, :label => false %></td>
</tr>
<% if admin? %>
<tr class="special_edit" >
<td>Ingame name</td>
<td><%= f.input :ign, :label => false %></td>
</tr>
<tr class="special_edit" >
<td>Rank</td>
<td><%= f.input :rank, :label => false, :collection => ranks, :include_blank => false %></td>
</tr>
<% end %>
<tr>
<td>
Skype username<br>
Show to all users
</td>
<td>
<%= f.input :skype, :label => false %>
<%= f.input :skype_public, :label => false %>
</td>
</tr>
<tr>
<td>YouTube username</td>
<td><%= f.input :youtube, :label => false %></td>
</tr>
<tr>
<td>Twitter username</td>
<td><%= f.input :twitter, :label => false %></td>
</tr>
<tr>
<td>About you</td>
<td><%= f.input :about, :label => false, :input_html => {:class => "vertical"} %></td>
</tr>
</tbody>
</table>
<%= f.submit "Save profile" %>
<% end %>

View File

@@ -1,14 +1,23 @@
<h1>All users</h1>
<% filter = params[:rank] %>
<% if filter %>
<h1>All '<%= filter %>' users</h1>
<%= link_to "show all", users_path %>
<% else %>
<h1> All users </h1>
<% end %>
<div id="userlist">
<% @users.each do |u| %>
<div class="list-user">
<%= link_to u do %>
<%= link_to u, :class => "avatar_url" do %>
<%= image_tag(avatar_url(u.id, 64), :class => "avatar", :alt => "avatar") %>
<div class="user-info">
<% end %>
<div class="user-info">
<%= link_to u do %>
<span class="user-name"><%= u.name %></span>
<span class="user-ign"><%= u.ign %></span>
</div>
<% end %>
<% end %>
<span class="user-rank"><%= link_to int_to_rank(u.rank), users_path(:rank => int_to_rank(u.rank)) %></span>
</div>
</div>
<% end %>
</div>

View File

@@ -1,14 +1,44 @@
<div id="user-info">
<div id="edit_profile"><%= link_to "edit profile", edit_user_path(@user), :class => "btn-blue" %></div>
<%= image_tag avatar_url(@user.id, 128), :class => "user-avatar avatar", :alt => "avatar" %><br/>
<h1><%= @user.name %></h1>
<% if @user == current_user || mod? %>
<div class="profile-action" ><%= link_to "edit profile", edit_user_path(@user), :class => "btn-blue" %></div>
<div class="profile-action" >
<% if session[:original_user_id] %>
<%= link_to "revert", unbecome_users_path, :class => "btn-blue" %>
<% else %>
<%= link_to "become this user", become_user_path(@user), :class => "btn-blue" %>
<% end %>
</div>
<% end %>
<%= image_tag avatar_url(@user.id, 128), :class => "user-avatar avatar", :alt => "avatar" %><br>
<% if @user.banned %>
<span class="user-banned">This user is banned!</span>
<% end %>
IGN: <%= @user.ign %><br/>
Rank: <%= int_to_rank(@user.rank) %><br/>
Joined: <%= @user.created_at.strftime("%e. %b %Y") %><br/>
<% if current_user && current_user.rank >= rank_to_int("mod") %>
Last IP: <%= @user.last_ip %><br/>
IGN: <%= @user.ign %><br>
Rank: <%= link_to int_to_rank(@user.rank), users_path(:rank => int_to_rank(@user.rank)) %><br>
<% if current_user && @user.skype && (@user.skype_public || current_user == @user || mod?) %>
YouTube: <%= link_to @user.youtube_channelname, "https://youtube.com/user/#{CGI::escape(@user.youtube)}", :target => "_blank" if !@user.youtube.blank? %><br>
Twitter: <%= link_to @user.twitter, "https://twitter.com/#{CGI::escape(@user.twitter)}", :target => "_blank" if !@user.twitter.blank? %><br>
Skype: <a href="skype:<%= @user.skype %>?chat" target="_blank"><%= @user.skype %></a><br>
<% end %>
About: <%= @user.about.blank? ? "<span class=\"no-about\">nothing</span>".html_safe : @user.about %>
Joined: <%= @user.created_at.strftime("%e. %b %Y") %><br>
<% if mod? %>
<hr>
Last IP: <%= @user.last_ip %><br>
Email: <a href="mailto:<%= @user.email %>"><%= @user.email %></a><br>
Last login: <%= @user.last_login.strftime("%e. %b %Y, %H:%M") %>
<% end %>
<hr>
<%= @user.about.blank? ? "<span class=\"no-about\">nothing</span>".html_safe : @user.about.gsub("\n", "<br>").html_safe %>
</div>