another big commit :D

This commit is contained in:
jomo
2013-10-07 04:59:21 +02:00
parent 2761387703
commit 5fac505a31
74 changed files with 1003 additions and 357 deletions

View File

@@ -10,7 +10,10 @@ gem 'jquery-rails'
gem 'therubyracer'
gem 'bcrypt-ruby', '~> 3.0.0' # To use ActiveModel has_secure_password
gem 'simple_form'
gem 'rbbcode'
gem 'sanitize'
gem 'github-markdown'
gem 'hirb' #pretty console output
gem 'rb-readline'
# Gems used only for assets and not required
# in production environments by default.
@@ -25,6 +28,7 @@ group :assets do
end
group :development do
gem 'webrick'
gem 'better_errors'
gem 'binding_of_caller'
end

View File

@@ -48,7 +48,9 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
github-markdown (0.5.5)
hike (1.2.2)
hirb (0.7.1)
i18n (0.6.4)
journey (1.0.4)
jquery-rails (2.2.1)
@@ -87,15 +89,12 @@ GEM
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.4)
rbbcode (1.0.3)
sanitize
treetop
rb-readline (0.5.0)
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.4)
sanitize (2.0.3)
nokogiri (>= 1.4.4, < 1.6)
nokogiri (>= 1.4.4, < 1.6)
sass (3.2.9)
sass-rails (3.2.6)
railties (~> 3.2.0)
@@ -122,6 +121,7 @@ GEM
uglifier (2.1.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
webrick (1.3.1)
PLATFORMS
ruby
@@ -131,11 +131,15 @@ DEPENDENCIES
better_errors
binding_of_caller
coffee-rails (~> 3.2.1)
github-markdown
hirb
jquery-rails
rails (= 3.2.12)
rbbcode
rb-readline
sanitize
sass-rails (~> 3.2.3)
simple_form
sqlite3
therubyracer
uglifier (>= 1.0.3)
webrick

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -1,9 +1,24 @@
$(function(){
$('[data-confirm]').click(function(){
var c = confirm($(this).attr('data-confirm'));
if (!c) return false;
})
$('#flash').delay(3000).fadeOut('slow');
$('.flash').click(function(){
$('.flash').animate({
opacity: 0
}, 'fast', function(){
$(this).animate({
height: 0
}, 'slow', function(){
$(this).hide();
})
});
});
setTimeout(function(){
$('.flash').animate({
opacity: 0
}, 3000, function(){
$(this).animate({
height: 0
}, 'slow', function(){
$(this).hide();
})
});
}, 4000);
})

View File

@@ -9,6 +9,6 @@
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require app
//= require jquery_ujs
//= require app

View File

@@ -2,5 +2,12 @@
@media only screen
and (max-width: 999px)
{
#mobile-info {
background: none repeat scroll 0 0 #AB0000;
color: #FFFFFF;
font-weight: bold;
padding: 1em;
text-align: center;
display: block;
}
}

View File

@@ -1,14 +1,5 @@
/* CSS for PCs only */
$lightgrey: #D1D1D1;
$lightergrey: #959595;
$midgrey: #787878;
$darkgrey: #434343;
$darkred: #AB0000;
@media only screen
and (min-width: 1000px)
{
@@ -19,29 +10,32 @@ and (min-width: 1000px)
body {
background-image: url('/assets/bg.png');
background-color: #252525;
background-attachment: fixed;
}
#mobile-info {
display: none;
}
a {
transition: color 0.25s;
color: $darkred;
color: #AB0000;
text-decoration: none;
&:hover {
color: #F00;
}
}
#flash {
.flash {
text-align: center;
padding: 10px;
font-weight: bold;
position: fixed;
top: 0;
left: 0;
right: 0;
&.notice {
cursor: pointer;
&#notice {
background: #8e8;
border-bottom: 3px dashed #8d8;
}
&.alert {
&#alert {
background: #ebb;
border-bottom: 3px dashed #fdd;
}
@@ -61,7 +55,6 @@ and (min-width: 1000px)
#userinfo {
float: right;
padding: 0 10px;
margin-top: 14px;
img.avatar {
border: 1px solid #000;
border-radius: 16px;
@@ -80,9 +73,9 @@ and (min-width: 1000px)
}
}
a {
color: $midgrey;
color: #787878;
&:hover {
color: $darkred;
color: #AB0000;
}
}
#menu {
@@ -93,7 +86,7 @@ and (min-width: 1000px)
}
ul {
float: left;
margin-top: 0;
margin: 0;
li {
float: left;
height: 100%;
@@ -140,6 +133,10 @@ and (min-width: 1000px)
}
}
.user-avatar {
display: block;
}
.post {
margin-bottom: 50px;
.post-title {
@@ -203,33 +200,37 @@ and (min-width: 1000px)
}
}
input {
&[type=text], &[type=email], &[type=password] {
input , select, textarea {
margin: 4px;
vertical-align: middle;
&[type=submit] {
margin: 0;
}
}
input[type=text], input[type=email], input[type=password], textarea {
border: 1px solid #aaa;
border-radius: 3px;
background: #eee;
margin: 4px;
box-shadow: 0 0 5px $lightgrey inset;
box-shadow: 0 0 5px #959595 inset;
height: 17px;
width: 300px;
padding: 1px 0;
padding: 1px 3px;
display: block;
}
input, select, textarea {
&.disabled, &[disabled] {
box-shadow: none;
background: #ddd;
}
}
textarea {
border: 1px solid #aaa;
border-radius: 3px;
background: #eee;
margin: 4px;
box-shadow: 0 0 5px $lightgrey inset;
height: 300px;
width: 300px;
max-width: 100%;
min-width: 300px;
min-height: 50px;
padding: 1px 0;
display: block;
max-width: 100% !important;
height: 200px;
padding: 5px 3px;
&.vertical {
resize: vertical;
}
@@ -276,7 +277,7 @@ and (min-width: 1000px)
}
.user-banned {
background: $darkred;
background: #AB0000;
color: white;
font-weight: bold;
padding: 4px;
@@ -284,6 +285,17 @@ and (min-width: 1000px)
border-radius: 3px;
}
.user-unconfirmed {
background: #AB0000;
color: white;
font-weight: bold;
padding: 4px 10px;
display: inline-block;
border-radius: 3px;
margin: 10px 0;
box-shadow: 0 0 10px #000;
}
.btn-blue {
border: 1px solid;
padding: 6px;
@@ -302,14 +314,17 @@ and (min-width: 1000px)
margin: 5px 0;
display: table;
a {
color: $midgrey;
color: #787878;
display: inline-block;
&:hover {
color: $darkred;
color: #AB0000;
}
}
a.avatar_url {
float: left;
height: 64px;
width: 64px;
background-color: #fff;
}
.user-info {
margin-left: 10px;
@@ -335,11 +350,11 @@ and (min-width: 1000px)
transition: opacity 0.3s, margin 0.3s;
}
#edit_create_post {
#edit_create_post, #edit_create_comment {
float: left;
}
#delete_post {
#delete_post, #delete_comment {
float: right;
}
@@ -376,5 +391,9 @@ and (min-width: 1000px)
}
}
.red {
color: #AB0000;
font-weight: bold;
}
}

View File

@@ -4,6 +4,3 @@ body {
padding: 0;
font: 14px/1.6 'Oswald','Calibri','Arial','DejaVu Sans', 'Open Sans','Lucida Sans','Lucida Grande','Lucida Sans Unicode',sans-serif;
}
// use screen.css
// and mobi.css

View File

@@ -1,9 +1,19 @@
class ApplicationController < ActionController::Base
protect_from_forgery
# force_ssl
helper :all
include UsersHelper
include ApplicationHelper
helper_method :current_user
helper_method :disabled?
helper_method :banned?
helper_method :confirmed?
helper_method :unconfirmed?
helper_method :default?
helper_method :donor?
helper_method :mod?
helper_method :admin?
helper_method :superadmin?
@@ -14,16 +24,42 @@ class ApplicationController < ActionController::Base
@current_user ||= User.find_by_id(session[:user_id])
end
#roles
def disabled?
!!(current_user && current_user.disabled?)
end
def banned?
!!(current_user && current_user.banned?)
end
def unconfirmed?
!!(current_user && current_user.unconfirmed?)
end
#special one
def confirmed?
!!(current_user && current_user.confirmed?)
end
def default?
!!(current_user && current_user.default?)
end
def donor?
!!(current_user && current_user.donor?)
end
def mod?
!!(current_user && current_user.rank >= rank_to_int("mod"))
!!(current_user && current_user.mod?)
end
def admin?
!!(current_user && current_user.rank >= rank_to_int("admin"))
!!(current_user && current_user.admin?)
end
def superadmin?
!!(current_user && current_user.rank >= rank_to_int("superadmin"))
!!(current_user && current_user.superadmin?)
end
end

View File

@@ -10,7 +10,7 @@ class BlogpostsController < ApplicationController
end
def new
if current_user && current_user.rank >= rank_to_int("mod")
if mod?
@post = Blogpost.new
else
flash[:alert] = "You are not allowed to create a new post!"
@@ -20,19 +20,21 @@ class BlogpostsController < ApplicationController
def edit
@post = Blogpost.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @post.user.rank.to_i) || (current_user == @edit.user))
if mod?
else
flash[:alert] = "You are not allowed to update this post!"
flash[:alert] = "You are not allowed to edit this post!"
redirect_to @post
end
end
def create
if mod?
@post = Blogpost.new(params[:blogpost])
@post.user = current_user
@post.user_author = current_user
if @post.save
redirect_to @post, notice: 'Post has been created.'
else
flash[:alert] = @post.errors.first
render action: "new"
end
else
@@ -43,11 +45,12 @@ class BlogpostsController < ApplicationController
def update
@post = Blogpost.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @post.user.rank.to_i) || (current_user == @post.user))
if mod?
if @post.update_attributes(params[:blogpost])
redirect_to @post, notice: 'Post has been updated.'
else
flash[:alert] = "There was a problem while updating the post"
raise @post.errors
render action: "edit"
end
end
@@ -55,7 +58,7 @@ class BlogpostsController < ApplicationController
def destroy
@post = Blogpost.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @post.user.rank.to_i) || (current_user == @post.user))
if mod?
if @post.destroy
flash[:notice] = "Post deleted!"
else

View File

@@ -2,8 +2,7 @@ class CommentsController < ApplicationController
def edit
@comment = Comment.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @comment.user.rank.to_i) || (current_user == @comment.user))
session[:return_to] = blogpost_path(@comment.blogpost)
if mod? || @comment.author.is?(current_user)
else
flash[:alert] = "You are not allowed to edit this comment"
redirect_to @comment.blogpost
@@ -11,39 +10,43 @@ class CommentsController < ApplicationController
end
def create
if current_user
if confirmed?
params[:comment].slice!("content") if params[:comment]
@comment = Comment.new(params[:comment])
@comment.user_id = current_user.id
@comment.user_author = current_user
@comment.blogpost = Blogpost.find(params[:blogpost_id])
if @comment.save
redirect_to @comment.blogpost, notice: 'Comment created!'
else
flash[:alert] = @comment.errors.full_messages.first
redirect_to blogpost_path(params[:blogpost_id])
flash[:alert] = "Could not create comment."
redirect_to Blogpost.find(params[:blogpost_id])
end
else
flash[:alert] = "You are not allowed to create comments."
redirect_to Blogpost.find(params[:blogpost_id])
end
end
def update
@comment = Comment.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @comment.user.rank.to_i) || (current_user == @comment.user))
if mod? || @comment.author.is?(current_user)
params[:comment].slice!("content") if params[:comment]
if @comment.update_attributes(params[:comment])
flash[:notice] = "Comment updated!"
redirect_to @comment.blogpost
else
flash[:alert] = "There was a problem while updating your comment"
redirect_to session[:return_to]
session.delete(:redirect_to)
render action: "edit"
end
else
flash[:alert] = "You are not allowed to edit this comment"
redirect_to blogpost_path(params[:blogpost_id])
redirect_to @comment.blogpost
end
end
def destroy
@comment = Comment.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @comment.user.rank.to_i) || (current_user == @comment.user))
if mod? || @comment.author.is?(current_user)
if @comment.destroy
flash[:notice] = "Comment deleted!"
else

View File

@@ -1,6 +1,9 @@
class ForumgroupsController < ApplicationController
def index
@groups = Forumgroup.all.sort_by{|s| s[:position]}
end
def show
redirect_to forumgroups_path + "#forum-#{params[:id]}"
end
end

View File

@@ -1,2 +1,11 @@
class ForumsController < ApplicationController
end
def index
redirect_to :forumgroups
end
def show
@forum = Forum.find(params[:id])
@threads = @forum.forumthreads
end
end

View File

@@ -0,0 +1,6 @@
class ForumthreadsController < ApplicationController
def index
f = Forum.find(params[:id])
redirect_to forum_path(f.forumgroup, f)
end
end

View File

@@ -19,7 +19,7 @@ class PaypalController < ApplicationController
end
protected
protected
def validate_IPN_notification(raw)
uri = URI.parse('https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate')
http = Net::HTTP.new(uri.host, uri.port)
@@ -29,7 +29,7 @@ class PaypalController < ApplicationController
http.use_ssl = true
response = http.post(uri.request_uri, raw,
'Content-Length' => "#{raw.size}",
'User-Agent' => "Redstoner.com"
'User-Agent' => "RedstonerServer, redstoner.com"
).body
end
end

View File

@@ -1,10 +0,0 @@
class ServercheckerController < ApplicationController
def show
if mc_running?
send_file "app/assets/images/on.png", :type => "image/png", :disposition => "inline"
else
send_file "app/assets/images/off.png", :type => "image/png", :disposition => "inline"
end
end
end

View File

@@ -1,21 +1,37 @@
class SessionsController < ApplicationController
require 'resolv'
def new
if current_user
redirect_to current_user
flash[:alert] = "You are already logged in!"
end
end
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
user.last_ip = "#{request.remote_ip} | #{Resolv.getname(request.remote_ip)}"
user.last_login = Time.now
user.save
if user.banned
flash[:alert] = "You are banned!"
redirect_to user
unless current_user
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
user.last_ip = "#{request.remote_ip} | #{Resolv.getname(request.remote_ip)}"
user.last_login = Time.now
user.save
if user.disabled?
flash[:alert] = "This user has been disabled!"
redirect_to login_path
elsif user.banned?
flash[:alert] = "You are banned!"
redirect_to user
else
session[:user_id] = user.id
redirect_to root_path, :notice => "Logged in!"
end
else
session[:user_id] = user.id
redirect_to root_path, :notice => "Logged in!"
flash[:alert] = "You're doing it wrong!"
redirect_to login_path
end
else
flash[:alert] = "You're doing it wrong!"
redirect_to login_path
redirect_to current_user
flash[:alert] = "You are already logged in!"
end
end

View File

@@ -0,0 +1,21 @@
class StatusController < ApplicationController
def show
if params[:check]
if params[:check].downcase == "minecraft"
if port_open?("redstoner.com", 25565)
send_file "app/assets/images/on.png", :type => "image/png", :disposition => "inline"
else
send_file "app/assets/images/off.png", :type => "image/png", :disposition => "inline"
end
elsif params[:check].downcase == "teamspeak"
if port_open?("redstoner.com", 9987)
send_file "app/assets/images/on.png", :type => "image/png", :disposition => "inline"
else
send_file "app/assets/images/off.png", :type => "image/png", :disposition => "inline"
end
else
render :text => "invalid params"
end
end
end
end

View File

@@ -3,18 +3,23 @@ class UsersController < ApplicationController
require 'open-uri'
def index
if params[:rank]
@users = User.find_all_by_rank(rank_to_int(params[:rank]))
if params[:role]
if params[:role].downcase == "staff"
@users = User.all.select {|u| u.role >= Role.get(:mod) }
else
@users = User.find_all_by_role_id(Role.get(params[:role]))
end
else
@users = User.all
@users.shift() #Remove first user
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)
flash[:alert] = "User does not exist!"
redirect_to users_path
end
end
@@ -22,15 +27,40 @@ require 'open-uri'
def new
if current_user
flash[:notice] = "You are already signed up!"
redirect_to user_path(current_user.id)
redirect_to current_user
else
@user = User.new
@user = User.new(role: Role.get(:unconfirmed))
end
end
def confirm
if current_user
@user = User.find(params[:id])
code = params[:code]
if @user && @user == current_user && code && @user.confirm_code == code
if @user.role == Role.get(:unconfirmed)
@user.role = Role.get :default
@user.save
flash[:notice] = "Registration confirmed."
elsif @user.role < Role.get(:unconfirmed)
flash[:alert] = "Your account has been banned or removed"
else
flash[:alert] = "Your account has already been confirmed!"
end
redirect_to @user
else
flash[:alert] = "Something is wrong with your confirmation code"
redirect_to root_path
end
else
flash[:alert] = "Please login"
redirect_to login_path
end
end
def edit
@user = User.find(params[:id])
unless (mod? && current_user.rank.to_i >= @user.rank.to_i) || current_user == @user
unless (mod? && current_user.role >= @user.role) || current_user == @user
flash[:alert] = "You are not allowed to edit this user"
redirect_to user_path(@user)
end
@@ -41,23 +71,29 @@ require 'open-uri'
flash[:notice] = "You are already signed up!"
redirect_to current_user
else
@user = User.new(params[:user])
@user = User.new(params[:user] ? params[:user].slice(:name, :ign, :email, :password, :password_confirmation) : {} )
@user.role = Role.get :unconfirmed
@user.confirm_code = SecureRandom.hex(16)
@user.last_ip = request.remote_ip
@user.last_login = Time.now
if @user.save
session[:user_id] = @user.id
data = params[:user]
mclogin = ""
if uses_mc_password?(@user.ign, params[:user][:password])
minecraftpw = true
flash[:alert] = "Really? That's your Minecraft password!"
end
begin
#check if this user is an idiot and uses his mc password.
mclogin = open("https://login.minecraft.net/?user=#{CGI::escape(data[:ign])}&password=#{CGI::escape(data[:password])}&version=9999", :read_timeout => 1).read
RedstonerMailer.register_mail(@user, minecraftpw).deliver
RedstonerMailer.register_info_mail(@user, minecraftpw).deliver
puts
rescue
puts "---"
puts "WARNING: registration mail failed for user #{@user.name}, #{@user.email}"
puts "---"
flash[:alert] = "Registration mail failed. Please contact us in-game."
end
if mclogin.downcase.include?(data[:ign].downcase)
redirect_to "http://youareanidiot.org/"
else
redirect_to edit_user_path(@user), notice: 'Successfully signed up!'
end
flash[:notice] = "Successfully signed up! Check your email!"
redirect_to edit_user_path(@user)
else
flash[:alert] = "Something went wrong"
render action: "new"
@@ -67,38 +103,46 @@ require 'open-uri'
def update
@user = User.find(params[:id])
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
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?"
if (mod? && current_user.role >= @user.role ) || (@user.is?(current_user) && confirmed?)
userdata = params[:user] ? params[:user].slice(:name, :ign, :role, :skype, :skype_public, :youtube, :twitter, :about, :password, :password_confirmation) : {}
if userdata[:role]
role = Role.find(userdata[:role])
if (mod? && role <= current_user.role)
userdata[:role] = role
else
#reset role
userdata[:role] = @user.role
end
userdata[:youtube_channelname] = channel
end
unless userdata[:ign] && (mod? && current_user.role >= @user.role)
#reset ign
userdata[:ign] = @user.ign
end
if @user.youtube != userdata[:youtube]
youtube = get_youtube(userdata[:youtube])
userdata[:youtube] = youtube[:channel]
userdata[:youtube_channelname] = youtube[:channel_name]
flash[:alert] = "Couldn't find a YouTube channel by that name, are you sure it's correct?" unless youtube[:is_correct?]
end
if @user.update_attributes(userdata)
redirect_to @user, notice: 'Profile updated.'
flash[:notice] = 'Profile updated.'
else
raise @user.errors.inspect
flash[:alert] = "There was a problem while updating the profile"
render action: "edit"
return
end
else
flash[:alert] = "You are not allowed to edit this user"
redirect_to @user
end
redirect_to @user
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!"
if mod? && current_user.role >= @user.role
@user.role = Role.get :banned
flash[:notice] = "'#{@user.name}' has been banned!"
else
flash[:alert] = "You are not allowed to ban this user!"
end
@@ -107,8 +151,8 @@ require 'open-uri'
def unban
@user = User.find(params[:id])
if mod? && current_user.rank >= @user.rank
@user.banned = false
if mod? && current_user.role >= @user.role
@user.role = Role.get :default
flash[:notice] = "\"#{@user.name}\" has been unbanned!"
else
flash[:alert] = "You are not allowed to unban this user!"
@@ -135,7 +179,7 @@ require 'open-uri'
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 admin? && current_user.role >= new_user.role
if original_user == new_user
flash[:alert] = "You are already \"#{new_user.name}\"!"
else
@@ -154,10 +198,10 @@ require 'open-uri'
def unbecome
old_user = current_user
original_user = User.find(session[:original_user_id])
if old_user && original_user
if old_user && original_user && original_user.admin?
session.delete(:original_user_id)
session[:user_id] = original_user.id
flash[:notice] = "You are no longer \"#{old_user.name}\"!"
flash[:notice] = "You are no longer '#{old_user.name}'!"
end
redirect_to old_user
end

View File

@@ -1,2 +1,17 @@
module ApplicationHelper
def port_open?(host, port)
wait = 300/1000.0 #milliseconds, the .0 is required!!
require 'timeout'
require 'socket'
isopen = false
begin
Timeout::timeout(wait) {
TCPSocket.new host, port
isopen = true
}
rescue Exception
# could not connect to the server
end
return isopen
end
end

View File

@@ -1,39 +1,71 @@
module UsersHelper
require "open-uri"
def avatar_url(user_id, size)
u = User.find_by_id(user_id)
u.nil? ? ign = :char : ign = u.ign
return "https://minotar.net/helm/#{ign}/#{size}"
return "https://minotar.net/helm/#{CGI.escape(ign)}/#{CGI.escape(size.to_s)}"
end
def mc_running?
host = "play.redstoner.com"
port = 25565
wait = 300/1000.0 #milliseconds, the .0 is required!!
require 'timeout'
require 'socket'
r = false
def uses_mc_password?(ign, password)
query = {
user: ign,
password: password,
version: 9999 #just something high so it won't fail with "Old version"
}.to_query
begin
Timeout::timeout(wait) {
TCPSocket.new host, port
r = true
}
rescue Exception
# could not connect to the server
#check if this user is an idiot and uses their mc password.
mclogin = open("https://login.minecraft.net/?#{query}", :read_timeout => 1).read
rescue
puts "---"
puts "ERROR: failed to check mc password for '#{ign}'. Login servers down?"
puts "---"
end
return r
!!mclogin.downcase.include?(ign.downcase)
end
def rank_to_int(rank)
r = ranks[rank]
def haspaid?(ign)
query = {user: ign}.to_query
begin
response = open("https://minecraft.net/haspaid.jsp?#{query}", :read_timeout => 1).read
rescue
puts "---"
puts "ERROR: failed to check for premium account for '#{ign}'. Minecraft servers down?"
puts "---"
response = "true"
end
!(response.casecmp("false") == 0)
end
def int_to_rank(int)
r = ranks.rassoc(int)
r.nil? ? "unknown" : r[0].to_s
def correct_case?(ign)
begin
http = Net::HTTP.start("skins.minecraft.net")
skin = http.get("/MinecraftSkins/#{CGI.escape(ign)}.png")
http.finish
rescue
puts "---"
puts "ERROR: failed to get skin status code for '#{ign}'. Skin servers down?"
puts "---"
end
skin.code != "404"
end
def ranks
# Lower case !!!
{"banned" => 1, "unconfirmed" => 5, "default" => 10, "donor" => 40, "mod" => 100, "admin" => 200, "superadmin" => 500}
def get_youtube(yt_name)
yt = {channel: yt_name}
if yt_name.blank?
yt[:channel] = nil
yt[:channel_name] = nil
yt[:is_correct?] = true
else
begin
yt[:channel_name] = JSON.parse(open("https://gdata.youtube.com/feeds/api/users/#{CGI.escape(yt_name)}?alt=json", :read_timeout => 1).read)["entry"]["title"]["$t"]
yt[:is_correct?] = true
rescue
yt[:is_correct?] = false
end
end
yt
end
end

View File

@@ -0,0 +1,17 @@
class RedstonerMailer < ActionMailer::Base
default from: "info@redstoner.com"
default reply_to: "redstonerserver@gmail.com"
def register_mail(user, uses_mc_pass)
@user = user
@mcpw = uses_mc_pass
mail(to: @user.email, subject: "Registration on Redstoner.com", from: "info@redstoner.com", reply_to: "redstonerserver@gmail.com")
end
def register_info_mail(user, uses_mc_pass)
@user = user
@mcpw = uses_mc_pass
mail(to: "redstonerserver@gmail.com", subject: "#{@user.name} registered on Redstoner.com", from: "info@redstoner.com", reply_to: "redstonerserver@gmail.com")
end
end

View File

@@ -1,15 +1,16 @@
class Blogpost < ActiveRecord::Base
attr_accessible :title, :text
validates_presence_of :title, :text, :user
belongs_to :user
has_many :comments
attr_accessible :title, :content, :author, :editor
validates_presence_of :title, :content, :author
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
has_many :comments, :dependent => :destroy
accepts_nested_attributes_for :comments
def author
@author ||= if user.present?
user
@author ||= if self.user_author.present?
user_author
else
User.find_by_name("Deleted user")
User.first
end
end
end

View File

@@ -1,10 +1,17 @@
class Comment < ActiveRecord::Base
attr_accessible :text, :user, :blogpost, :post
validates_presence_of :text, :user, :blogpost
validates_length_of :text, :in => 4..1000
attr_accessible :content, :author, :blogpost, :post
validates_presence_of :content, :author, :blogpost
validates_length_of :content, in: 4..1000
belongs_to :blogpost
belongs_to :user
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
def author
@author ||= if self.user_author.present?
user_author
else
User.first
end
end
end

View File

@@ -1,3 +1,12 @@
class Forum < ActiveRecord::Base
belongs_to :forumgroup
has_many :forumthreads
def to_s
name
end
def group
forumgroup
end
end

View File

@@ -1,3 +1,7 @@
class Forumgroup < ActiveRecord::Base
has_many :forums
def to_s
name
end
end

View File

@@ -0,0 +1,9 @@
class Forumthread < ActiveRecord::Base
belongs_to :forum
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
def to_s
name
end
end

38
app/models/role.rb Normal file
View File

@@ -0,0 +1,38 @@
class Role < ActiveRecord::Base
include Comparable
has_many :users
attr_accessible :name, :value
def to_s
self.name
end
def to_i
self.value
end
def is? (name)
!!(Role.find_by_name(name) == self)
end
def self.get (name)
Role.find_by_name(name)
end
def <=> (role)
if role.is_a?(Role)
self.value - role.value
elsif role.is_a?(Symbol)
self <=> Role.find_by_name(role)
else
raise "Cannot compare Role with #{role.class}"
end
end
def self.all_until (role)
Role.all.select do |r|
r <= role
end
end
end

View File

@@ -1,12 +1,95 @@
class User < ActiveRecord::Base
attr_accessible :name, :ign, :email, :about, :password, :password_confirmation, :rank, :skype, :skype_public, :youtube, :youtube_channelname, :twitter
include UsersHelper
belongs_to :role
attr_accessible :name, :password, :password_confirmation, :ign, :email, :confirm_code, :about, :last_ip, :skype, :skype_public, :youtube, :youtube_channelname, :twitter, :last_login, :role
has_secure_password
validates_presence_of :password, :name, :email, :ign, :password_confirmation, :on => :create
validates :email, uniqueness: {case_sensitive: false}
validates :name, :uniqueness => true
validates :ign, :uniqueness => true
before_validation :strip_whitespaces
validates_presence_of :password, :password_confirmation, :confirm_code, :on => :create
validates_presence_of :name, :email, :ign
validates_length_of :password, in: 8..256, :on => :create
validates_length_of :name, in: 3..20
validates_length_of :about, maximum: 5000
validates_length_of :ign, minimum: 2
validates :email, uniqueness: {case_sensitive: false}, format: {with: /^\S+@\S+\.[a-z]{2,}$/i, message: "That doesn't look like an email adress."}
validates :name, uniqueness: {case_sensitive: false}, format: {with: /^[a-z\d\-_ ]+$/i, message: "Allowed characters: a-z0-9, dashes, underscores and spaces"}
validates :ign, uniqueness: {case_sensitive: false}, format: {with: /^[a-z\d_]+$/i, message: "That is probably not your username."}
validate :ign_is_not_skull, :ign_is_not_mojang, :ign_has_paid, :ign_has_correct_case
has_many :blogposts
has_many :comments
def is? (user)
self == user
end
#roles
def disabled?
!!(self.role == :disabled)
end
def banned?
!!(self.role == :banned)
end
def unconfirmed?
!!(self.role == :unconfirmed)
end
def confirmed?
!!(self.role > :unconfirmed)
end
def default?
!!(self.role >= :default)
end
def donor?
!!(self.role >= :donor)
end
def mod?
!!(self.role >= :mod)
end
def admin?
!!(self.role >= :admin)
end
def superadmin?
!!(self.role >= :superadmin)
end
private
def ign_is_not_skull
errors.add(:ign, "Good one...") if ["MHF_Blaze", "MHF_CaveSpider", "MHF_Chicken", "MHF_Cow", "MHF_Enderman", "MHF_Ghast", "MHF_Golem", "MHF_Herobrine", "MHF_LavaSlime", "MHF_MushroomCow", "MHF_Ocelot", "MHF_Pig", "MHF_PigZombie", "MHF_Sheep", "MHF_Slime", "MHF_Spider", "MHF_Squid", "MHF_Villager", "MHF_Cactus", "MHF_Cake", "MHF_Chest", "MHF_Melon", "MHF_OakLog", "MHF_Pumpkin", "MHF_TNT", "MHF_TNT2", "MHF_ArrowUp", "MHF_ArrowDown", "MHF_ArrowLeft", "MHF_ArrowRight", "MHF_Exclamation", "MHF_Question"].include?(self.ign)
end
def ign_is_not_mojang
errors.add(:ign, "If that's really you, contact <a href='/users?role=staff'>us</a> in-game.") if ["mollstam", "carlmanneh", "MinecraftChick", "Notch", "jeb_", "xlson", "jonkagstrom", "KrisJelbring", "marc", "Marc_IRL", "MidnightEnforcer", "YoloSwag4Lyfe", "EvilSeph", "Grumm", "Dinnerbone", "geuder", "eldrone", "JahKob", "BomBoy", "MansOlson", "pgeuder", "91maan90", "vubui", "PoiPoiChen", "mamirm", "eldrone", "_tomcc"].include?(self.ign)
end
def ign_has_paid
errors.add(:ign, "'#{self.ign}' is not a valid account!") unless haspaid?(self.ign)
end
def ign_has_correct_case
errors.add(:ign, "The IGN is case-sensitive. Please correct '#{self.ign}'.") unless correct_case?(self.ign)
end
def strip_whitespaces
self.name.strip! if self.name
self.ign.strip! if self.ign
self.email.strip! if self.email
self.about.strip! if self.about
self.skype.strip! if self.skype
self.youtube.strip! if self.youtube
self.twitter.strip! if self.twitter
end
end

View File

@@ -2,9 +2,9 @@
<%= simple_form_for @post do |f|%>
<%= f.input :title, :label => false %>
<%= f.input :text, :label => false %>
<%= f.input :content, :label => false %>
<%= f.submit "Update Post", :id => "edit_create_post" %>
<% end %>
<div id="delete_post">
<%= button_to "Delete post", @post, :method => "delete", :confirm => "Delete post forever?" %>
<%= button_to "Delete post", @post, :method => "delete", :confirm => "Delete post + comments forever?" %>
</div>

View File

@@ -8,12 +8,12 @@
</span>
</div>
<span class="post-info">
by <%= link_to p.user.name, p.user %> on <%= p.created_at.strftime("%e. %b %Y") %>
by <%= link_to p.author.name, p.author %> on <%= p.created_at.strftime("%e. %b %Y") %>
</span>
<div class="post-content">
<%= RbbCode.new.convert(p.text).html_safe %>
<%= GitHub::Markdown.render_gfm(Sanitize.clean(p.content, Sanitize::Config::RESTRICTED)).html_safe %>
</div>
</div>
<% end %>
<%= link_to 'Make new Post', new_blogpost_path if current_user && current_user.rank >= rank_to_int("mod") %>
<%= link_to 'Make new Post', new_blogpost_path if mod? %>
</div>

View File

@@ -1,6 +1,6 @@
<h1>New Post</h1>
<%= simple_form_for @post do |f|%>
<%= f.input :title, :label => false %>
<%= f.input :text, :label => false %>
<%= f.input :content, :label => false %>
<%= f.submit "Update Post", :id => "edit_create_post" %>
<% end %>

View File

@@ -3,12 +3,12 @@
<h1><%= @post.title %></h1>
</div>
<span class="post-info"><%= link_to @post.author.name, @post.author %> on <%= @post.created_at.strftime("%e. %b %Y") %>
<% if current_user && current_user.rank >= rank_to_int("mod") %>
<% if mod? %>
- <%= link_to "edit", edit_blogpost_path(@post.id) %>
<% end %>
</span>
<div class="post-content">
<%= RbbCode.new.convert(@post.text).html_safe %>
<%= GitHub::Markdown.render_gfm(Sanitize.clean(@post.content, Sanitize::Config::RESTRICTED)).html_safe %>
</div>
<div id="comments">
<% @post.comments.each do |c| %>

View File

@@ -1,8 +1,8 @@
<div class="comment <%= "author" if c.user == @post.user %>">
<span class="comment-info"><%= link_to c.user.name, c.user %> <%= c.created_at.strftime("%e. %b %Y, %H:%m") %>
<% if mod? || current_user == c.user %>
<div class="comment <%= "author" if c.author == @post.author %>">
<span class="comment-info"><%= link_to c.author.name, c.author %> <%= c.created_at.strftime("%e. %b %Y, %H:%m") %>
<% if mod? || c.author.is?(current_user) %>
<div class="editlink"><%= link_to "edit", edit_blogpost_comment_path(c.blogpost, c) %></div>
<% end %>
</span>
<div class="comment-content"><%= h(c.text).gsub(/(\w*[\r\n]){3,}/, "\n\n").gsub("\n", "<br>").html_safe %></div>
<div class="comment-content"><%= h(c.content).gsub(/(\w*[\r\n]){3,}/, "\n\n").gsub("\n", "<br>").html_safe %></div>
</div>

View File

@@ -1,7 +1,7 @@
<% if current_user %>
<h3>New comment</h3>
<%= simple_form_for [@post, @comment] do |f| %>
<%= f.input :text, :label => false, :as => "text", :placeholder => "Comment" %>
<%= f.input :content, :label => false, :as => "text", :placeholder => "Comment" %>
<%= f.submit %>
<% end %>
<% end %>

View File

@@ -1,6 +1,9 @@
<h1>Edit comment</h1>
<%= simple_form_for [@comment.blogpost, @comment] do |f| %>
<%= f.input :text, :label => false, :as => "text", :placeholder => "Comment" %>
<%= f.submit %>
<% end %>
<%= f.input :content, :label => false, :as => "text", :placeholder => "Comment" %>
<%= f.submit "Update Comment", :id => "edit_create_comment" %>
<% end %>
<div id="delete_comment">
<%= button_to "Delete comment", [@comment.blogpost, @comment] , :method => "delete", :confirm => "Delete comment forever?" %>
</div>

View File

@@ -1,14 +1,14 @@
<div id="forum_groups">
<% @groups.each do |g| %>
<div class="group">
<% @groups.each do |group| %>
<div class="group" id="forum-<%= group.id %>">
<div class="header">
<%= g.name %>
<%= group.name %>
</div>
<div class="forums">
<% g.forums.sort_by{|s| s[:position]}.each do |f| %>
<% group.forums.sort_by{|s| s[:position]}.each do |f| %>
<div class="forum">
<%= f.name %>
<%= link_to f.name, f %>
</div>
<% end %>
</div>

View File

@@ -0,0 +1,20 @@
<div class='forum-path'><%= link_to @forum.group, forumgroup_path(@forum.group) %> → <%= link_to @forum %></div>
<h1><%= @forum.name %></h1>
<div id="forum_threads">
<% @threads.each do |thread| %>
<div class="group" id="thread-<%= thread.id %>">
<div class="header">
<%= thread.name %>
</div>
<div class="forums">
<% thread.forums.sort_by{|s| s[:position]}.each do |f| %>
<div class="forum">
<%= link_to f.name, f %>
</div>
<% end %>
</div>
</div>
<% end %>
</div>

View File

@@ -1,7 +1,9 @@
<div id="head">
<div id="logo"><%= image_tag "logo.png" %></div>
<div id="userinfo" <%= "class=\"logged-out\"".html_safe if !current_user %>>
<% if !current_user.nil? %>
<div id="logo"><%= link_to root_path do %>
<%= image_tag "logo.png" %>
<% end %></div>
<div id="userinfo" <%= "class=\"logged-out\"".html_safe unless current_user %>>
<% if current_user %>
<span id="userinfo-box">
<%= link_to current_user.name.truncate(14), current_user %><br/>
<%= link_to "Logout", logout_path %>
@@ -14,17 +16,14 @@
<div class="clear"></div>
<div id="menu">
<ul>
<li><%= link_to image_tag('icons/home.png'), root_path %></li>
<%= link_to root_path do %>
<li>Home</li>
<% end %>
<li>Info</li>
<%= link_to forums_path do %>
<%= link_to forumgroups_path do %>
<li>Forums</li>
<% end %>
<li>Donate</li>
<li>
<%= simple_form_for "asdf", method: "get", action: users_path do |f| %>
<%= f.input :rank %>
<% end %>
</li>
</ul>
<div class="clear"></div>
</div>

View File

@@ -8,12 +8,12 @@
<%= javascript_include_tag "application" %>
</head>
<body>
<%= render "/layouts/head" %>
<%= "<div id='flash' class='alert'>#{alert}</div>".html_safe if alert %>
<%= "<div id='flash' class='notice'>#{notice}</div>".html_safe if notice %>
<div id="main-content">
<%= yield %>
</div>
<div id="mobile-info">Sorry, we don't have a mobile style yet. It's all ugly for now.</div>
<%= render "/layouts/head" %>
<div id="main-content">
<%= "<div id='alert' class='flash'>#{alert}</div>".html_safe if alert %>
<%= "<div id='notice' class='flash'>#{notice}</div>".html_safe if notice %>
<%= yield %>
</div>
</body>
</html>

View File

@@ -0,0 +1,29 @@
<p><%= @user.name %> has registered on redstoner.</p>
<p>
<table style="border: 1px solid black; border-collapse:collapse;">
<tr>
<td style="border:1px solid black;">IGN</td>
<td style="border:1px solid black;"><%= @user.ign %></td>
</tr>
<tr>
<td style="border:1px solid black;">email</td>
<td style="border:1px solid black;"><%= @user.email %></td>
</tr>
<tr>
<td style="border:1px solid black;">Time</td>
<td style="border:1px solid black;"><%= @user.created_at %></td>
</tr>
<tr>
<td style="border:1px solid black;">IP</td>
<td style="border:1px solid black;"><%= @user.last_ip %></td>
</tr>
</table>
</p>
<% if @mcpw %>
<p>
<font color="red">
<b>USER IS AN IDIOT!</b>
</font>
</p>
<% end %>

View File

@@ -0,0 +1,29 @@
Hi <%= @user.name %>!
<p>Thank you for registering on Redstoner.com!</p>
<p>To use your account, you need to <%= link_to "confirm", confirm_user_path(@user, code: @user.confirm_code, only_path: false) %> your email address.
<% if @mcpw %>
<div>
<p>
<font color="red">
<b>NEVER USE THE SAME PASSWORD TWICE!</b>
</font>
</p>
<p>
<font color="red">
You used your minecraft password on our website. We could have stolen it easily!<br>
</font>
<i>(But we didn't)</i>
</p>
<% end %>
<p>Please click this link to confirm your registration:
<div style="background-color: #eeeeee; padding: 1em; margin: 0; text-align: center;" width="100%">
<%= link_to "confirm my email", confirm_user_path(@user, code: @user.confirm_code, only_path: false), style: "text-decoration: none; color: #f2f2f2; padding: 0.5em 2em; background-color: #4096EE; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; display: inline-block; text-transform: uppercase;" %>
</div>
</p>
<p>If you have any questions or problems, just ask one of our <%= link_to "Staff", users_path(role: "staff", only_path: false) %> in-game.</p>
<p>Your Redstoner team</p>

View File

@@ -1,4 +1,5 @@
<h1>Log in</h1>
<p>Not a member? <%= link_to "Join us here", signup_path %>!</p>
<%= form_tag login_path do |f| %>
<div id="form_labels">
<%= label_tag :email %>

View File

@@ -1,3 +1,4 @@
<%= link_to "Your profile", current_user %> → Edit
<h1>Edit profile</h1>
<%= simple_form_for @user do |f| %>
@@ -9,41 +10,59 @@
</tr>
<tr>
<td>Display name</td>
<td><%= f.input :name, :label => false %></td>
<td>
<%= f.input :name, :label => false, disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) %>
</td>
</tr>
<% if admin? %>
<tr class="special_edit" >
<td>Ingame name</td>
<td><%= f.input :ign, :label => false %></td>
<td>In-game name</td>
<td>
<%= f.input :ign, :label => false, disabled: !(mod? && current_user.role >= @user.role) %>
</td>
</tr>
<tr class="special_edit" >
<td>Rank</td>
<td><%= f.input :rank, :label => false, :collection => ranks, :include_blank => false %></td>
<tr>
<td>Role</td>
<td>
<% if mod? && current_user.role >= @user.role %>
<%= f.association :role, :label => false, :collection => Role.all_until(current_user.role), :include_blank => false %>
<% else %>
<%= f.input :role, label: false, disabled: true %>
<% end %>
</td>
</td>
</tr>
<% end %>
<tr>
<td>
Skype username<br>
Show to all users
Show to...
</td>
<td>
<%= f.input :skype, :label => false %>
<%= f.input :skype_public, :label => false %>
<%= f.input :skype, label: false, placeholder: "Skype username", disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) %>
<%= f.input :skype_public, label: false, as: :radio_buttons, collection: [['all users', false], ['only staff', true]], input_html: { disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) } %>
</td>
</td>
</tr>
<tr>
<td>YouTube username</td>
<td><%= f.input :youtube, :label => false %></td>
<td>
<%= f.input :youtube, :label => false, placeholder: "YouTube username", disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) %>
</td>
</tr>
<tr>
<td>Twitter username</td>
<td><%= f.input :twitter, :label => false %></td>
<td>
<%= f.input :twitter, :label => false, placeholder: "Twitter username", disabled: !(confirmed? || (mod? && current_user.role >= @user.role)) %>
</td>
</tr>
<tr>
<td>About you</td>
<td><%= f.input :about, :label => false, :input_html => {:class => "vertical"} %></td>
<td>
<%= f.input :about, :label => false, :input_html => {:class => "vertical"}, placeholder: "Tell us something about you...", disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) %>
</td>
</tr>
</tbody>
</table>
<%= f.submit "Save profile" %>
<%= f.submit "Save profile", disabled: @user.unconfirmed? %>
<% if @user.unconfirmed? %>
<span class='red'>Please confirm your email adress first.</span>
<% end %>
<% end %>

View File

@@ -1,4 +1,4 @@
<% filter = params[:rank] %>
<% filter = params[:role] %>
<% if filter %>
<h1>All '<%= filter %>' users</h1>
<%= link_to "show all", users_path %>
@@ -16,7 +16,7 @@
<span class="user-name"><%= u.name %></span>
<span class="user-ign"><%= u.ign %></span>
<% end %>
<span class="user-rank"><%= link_to int_to_rank(u.rank), users_path(:rank => int_to_rank(u.rank)) %></span>
<span class="user-role"><%= link_to u.role, users_path(:role => u.role.name) %></span>
</div>
</div>
<% end %>

View File

@@ -1,8 +1,8 @@
<h1>Register</h1>
<%= simple_form_for @user do |f| %>
<%= f.input :name %>
<%= f.input :ign, label: "Exact ingame name" %>
<%= f.input :name, label: "Display Name" %>
<%= f.input :ign, label: "Case sensitive Minecraft name" %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>

View File

@@ -1,22 +1,32 @@
<div id="user-info">
<h1><%= @user.name %></h1>
<% if @user == current_user || mod? %>
<% if @user.is?(current_user) || (mod? && current_user.role >= @user.role) %>
<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 %>
<div class="profile-action" >
<% if !session[:original_user_id] && admin? %>
<%= link_to "become this user", become_user_path(@user), :class => "btn-blue" %>
<% elsif session[:original_user_id] %>
<%= link_to "revert", unbecome_users_path, :class => "btn-blue" %>
<% end %>
</div>
<% if @user.rank.to_i == rank_to_int("banned") %>
<% if @user.banned? %>
<span class="user-banned">This user is banned!</span>
<% end %>
<% if @user.rank.to_i == rank_to_int("unconfirmed") %>
<span class="user-unconfirmed">This user hasn't confirmed his email yet!</span>
<% if @user.unconfirmed? %>
<% if @user.is?(current_user) %>
<span class="user-unconfirmed">Please confirm your email <u><%= @user.email %></u> !</span>
<% else %>
<span class="user-unconfirmed">This user hasn't confirmed their email yet!</span>
<% end %>
<% elsif @user.disabled? %>
<% if @user.is?(current_user) %>
<span class="user-unconfirmed">Your account has been disabled.</span>
<% else %>
<span class="user-unconfirmed">This user is disabled or does no longer exist.</span>
<% end %>
<% end %>
@@ -28,25 +38,25 @@
<td><%= @user.ign %></td>
</tr>
<tr>
<td>Rank</td>
<td><%= link_to int_to_rank(@user.rank), users_path(:rank => int_to_rank(@user.rank)) %></td>
<td>Role</td>
<td><%= link_to @user.role, users_path(:role => @user.role.name) %></td>
</tr>
<% if current_user && !@user.skype.blank? && (@user.skype_public || current_user == @user || mod?) %>
<tr>
<td>Skype</td>
<td><a href="skype:<%= @user.skype %>?chat" target="_blank"><%= @user.skype %></a></td>
<td><%= link_to @user.skype, "skype:#{@user.skype}?chat", target: "_blank" %></a></td>
</tr>
<% end %>
<% if !@user.youtube.blank? && @user.youtube_channelname.blank? %>
<% if !@user.youtube.blank? && !@user.youtube_channelname.blank? %>
<tr>
<td>YouTube</td>
<td><%= link_to @user.youtube_channelname, "https://youtube.com/user/#{CGI::escape(@user.youtube)}", :target => "_blank" %></td>
<td><%= link_to @user.youtube_channelname, "https://youtube.com/user/#{CGI.escape(@user.youtube)}", :target => "_blank" %></td>
</tr>
<% end %>
<% if !@user.twitter.blank? %>
<tr>
<td>Twitter</td>
<td><%= link_to @user.twitter, "https://twitter.com/#{CGI::escape(@user.twitter)}", :target => "_blank" %></td>
<td><%= link_to @user.twitter, "https://twitter.com/#{CGI.escape(@user.twitter)}", :target => "_blank" %></td>
</tr>
<% end %>
<tr>
@@ -54,10 +64,12 @@
<td><%= @user.created_at.strftime("%e. %b %Y") %></td>
</tr>
<% if mod? || current_user == @user %>
<% if mod? %>
<tr>
<td>Last IP</td>
<td><%= @user.last_ip %></td>
</tr>
<% end %>
<tr>
<td>Email</td>
<td><%= mail_to @user.email, @user.email, :subject => "Redstoner" %></td>

View File

@@ -1,8 +1,8 @@
# Be sure to restart your server when you modify this file.
Site::Application.config.session_store :cookie_store, key: '_site_session'
# Site::Application.config.session_store :cookie_store, key: '_redstoner_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# Site::Application.config.session_store :active_record_store
Site::Application.config.session_store :active_record_store

View File

@@ -3,20 +3,30 @@ Site::Application.routes.draw do
resources :blogposts, :path => '/blog' do
resources :comments
end
resources :roles
resources :users do
member do
get 'become'
get 'confirm'
end
collection do
get 'unbecome'
end
end
resources :forumgroups, :as => 'forums', :path => '/forums' do
resources :forumgroups, :path => '/forums' do
member do
resources :forums, :path => 'f' do
member do
resources :forumthreads, :path => 't', :as => 'threads' do
end
end
end
end
end
match '/serverstatus.png' => 'serverchecker#show'
match '/status' => 'status#show'
get "logout" => 'sessions#destroy'
get 'login' => 'sessions#new'

View File

@@ -0,0 +1,11 @@
class CreateRoles < ActiveRecord::Migration
def up
create_table :roles do |t|
t.string :name
t.integer :value
end
end
def down
end
end

View File

@@ -0,0 +1,23 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name, :unique => true, :null => false
t.string :password_digest, :null => false
t.string :ign, :unique => true, :null => false
t.string :email, :unique => true, :null => false
t.string :confirm_code, :null => false
t.text :about
t.string :last_ip
t.string :skype, :unique => true
t.boolean :skype_public, :default => false
t.string :youtube, :unique => true
t.string :youtube_channelname
t.string :twitter, :unique => true
t.datetime :last_login
t.references :role, :null => false
t.timestamps
end
end
end

View File

@@ -2,10 +2,12 @@ class CreateBlogposts < ActiveRecord::Migration
def change
create_table :blogposts do |t|
t.string :title
t.text :text
t.references :user
t.text :content
t.references :user_author
t.references :user_editor
t.timestamps
end
end
end
end

View File

@@ -1,8 +1,10 @@
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.text :text
t.integer :user_id
t.text :content
t.references :user_author
t.references :user_editor
t.references :blogpost
t.timestamps

View File

@@ -0,0 +1,10 @@
class CreateForumgroups < ActiveRecord::Migration
def change
create_table :forumgroups do |t|
t.string :name
t.integer :position
t.integer :read_permission
t.integer :write_permission
end
end
end

View File

@@ -1,11 +1,12 @@
class CreateForums < ActiveRecord::Migration
def change
create_table :forums do |t|
t.string "name"
t.integer "position"
t.references :forumgroup
t.string :name
t.integer :position
t.integer :read_permission
t.integer :write_permission
t.timestamps
t.references :forumgroup
end
end
end

View File

@@ -0,0 +1,17 @@
class CreateForumthreads < ActiveRecord::Migration
def change
create_table :forumthreads do |t|
t.string :title
t.text :content
t.boolean :sticky, :default => false
t.boolean :locked, :default => false
t.references :user_author
t.references :user_editor
t.references :forum
t.timestamps
end
end
end

View File

@@ -1,20 +0,0 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name, :unique => true, :null => false
t.string :ign, :unique => true, :null => false
t.integer :rank, :default => 10, :null => false
t.boolean :banned, :default => false
t.string :email, :unique => true, :null => false
t.text :about
t.string :password_digest, :null => false
t.string :last_ip
t.string :skype
t.boolean :skype_public, :default => false
t.datetime :last_login
t.datetime :last_active
t.timestamps
end
end
end

View File

@@ -1,5 +0,0 @@
class AddYoutubeToUsers < ActiveRecord::Migration
def change
add_column :users, :youtube, :string
end
end

View File

@@ -1,8 +0,0 @@
class AddYoutubeChannelname < ActiveRecord::Migration
def up
add_column :users, :youtube_channelname, :string
end
def down
end
end

View File

@@ -1,5 +0,0 @@
class AddTwitterToUsers < ActiveRecord::Migration
def change
add_column :users, :twitter, :string
end
end

View File

@@ -1,9 +0,0 @@
class AddForumgroups < ActiveRecord::Migration
def change
create_table :forumgroups do |t|
t.string :name
t.integer :position
t.timestamps
end
end
end

View File

@@ -0,0 +1,12 @@
class AddSessionsTable < ActiveRecord::Migration
def change
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
add_index :sessions, :session_id
add_index :sessions, :updated_at
end
end

View File

@@ -11,57 +11,85 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130802051521) do
ActiveRecord::Schema.define(:version => 20130922181339) do
create_table "blogposts", :force => true do |t|
t.string "title"
t.text "text"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "content"
t.integer "user_author_id"
t.integer "user_editor_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "comments", :force => true do |t|
t.text "text"
t.integer "user_id"
t.text "content"
t.integer "user_author_id"
t.integer "user_editor_id"
t.integer "blogpost_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "forumgroups", :force => true do |t|
t.string "name"
t.integer "position"
t.string "name"
t.integer "position"
t.integer "read_permission"
t.integer "write_permission"
end
create_table "forums", :force => true do |t|
t.string "name"
t.integer "position"
t.integer "read_permission"
t.integer "write_permission"
t.integer "forumgroup_id"
end
create_table "forumthreads", :force => true do |t|
t.string "title"
t.text "content"
t.boolean "sticky", :default => false
t.boolean "locked", :default => false
t.integer "user_author_id"
t.integer "user_editor_id"
t.integer "forum_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "roles", :force => true do |t|
t.string "name"
t.integer "value"
end
create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
t.text "data"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "forums", :force => true do |t|
t.string "name"
t.integer "position"
t.integer "forumgroup_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
create_table "users", :force => true do |t|
t.string "name", :null => false
t.string "ign", :null => false
t.integer "rank", :default => 10, :null => false
t.boolean "banned", :default => false
t.string "email", :null => false
t.text "about"
t.string "password_digest", :null => false
t.string "ign", :null => false
t.string "email", :null => false
t.string "confirm_code", :null => false
t.text "about"
t.string "last_ip"
t.string "skype"
t.boolean "skype_public", :default => false
t.datetime "last_login"
t.datetime "last_active"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "youtube"
t.string "youtube_channelname"
t.string "twitter"
t.datetime "last_login"
t.integer "role_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end

View File

@@ -1,12 +1,42 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
User.create(
Role.create!([
{name: "disabled", value: 1},
{name: "banned", value: 2},
{name: "unconfirmed", value: 5},
{name: "default", value: 10},
{name: "donor", value: 40},
{name: "mod", value: 100},
{name: "admin", value: 200},
{name: "superadmin", value: 500}
])
userpw = SecureRandom.hex(64)
deleted_user = User.create!(
name: "Deleted user",
email: "redstonerserver@gmail.com",
ign: "Mojang",
about: "Hey, apparently, I do no longer exist. This is just a placeholder profile",
password: userpw,
password_confirmation: userpw,
role: Role.get(:disabled),
confirm_code: SecureRandom.hex(16),
skype: "echo123",
skype_public: true,
last_ip: "0.0.0.0",
last_login: Time.utc(0).to_datetime
)
deleted_user.update_attribute(:ign, "Steve")
User.create!(
name: "Redstone Sheep",
ign: "noobkackboon",
email: "theredstonesheep@gmail.com",
about: "Hi, I am the admin :)",
password: "123",
password_confirmation: "123",
rank: 500
password: "123456789",
password_confirmation: "123456789",
role: Role.get(:superadmin),
confirm_code: SecureRandom.hex(16)
)

BIN
rcon_test Normal file

Binary file not shown.

11
test/fixtures/forumthreads.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

11
test/fixtures/permissions.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class RedstonerMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class ForumthreadTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class PermissionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end