Archived
LOTS of stuff
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
|
||||
before_filter :update_ip, :update_seen
|
||||
# force_ssl
|
||||
|
||||
helper :all
|
||||
@@ -10,16 +10,22 @@ class ApplicationController < ActionController::Base
|
||||
helper_method :current_user
|
||||
helper_method :disabled?
|
||||
helper_method :banned?
|
||||
helper_method :confirmed?
|
||||
helper_method :unconfirmed?
|
||||
helper_method :default?
|
||||
helper_method :donor?
|
||||
helper_method :normal?
|
||||
helper_method :mod?
|
||||
helper_method :admin?
|
||||
helper_method :superadmin?
|
||||
|
||||
helper_method :donor?
|
||||
helper_method :confirmed?
|
||||
private
|
||||
|
||||
def update_ip
|
||||
current_user && current_user.update_attribute(:last_ip, request.remote_ip)
|
||||
end
|
||||
|
||||
def update_seen
|
||||
current_user && current_user.update_attribute(:last_seen, Time.now)
|
||||
end
|
||||
|
||||
def current_user
|
||||
@current_user ||= User.find_by_id(session[:user_id])
|
||||
end
|
||||
@@ -33,21 +39,8 @@ class ApplicationController < ActionController::Base
|
||||
!!(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?)
|
||||
def normal?
|
||||
!!(current_user && current_user.normal?)
|
||||
end
|
||||
|
||||
def mod?
|
||||
@@ -62,4 +55,12 @@ class ApplicationController < ActionController::Base
|
||||
!!(current_user && current_user.superadmin?)
|
||||
end
|
||||
|
||||
def donor?
|
||||
!!(current_user && current_user.donor?)
|
||||
end
|
||||
|
||||
def confirmed?
|
||||
!!(current_user && current_user.confirmed?)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -34,7 +34,7 @@ class BlogpostsController < ApplicationController
|
||||
if @post.save
|
||||
redirect_to @post, notice: 'Post has been created.'
|
||||
else
|
||||
flash[:alert] = @post.errors.first
|
||||
flash[:alert] = "Error creating blogpost"
|
||||
render action: "new"
|
||||
end
|
||||
else
|
||||
@@ -47,7 +47,7 @@ class BlogpostsController < ApplicationController
|
||||
@post = Blogpost.find(params[:id])
|
||||
if mod? || @comment.author.is?(current_user)
|
||||
@post.user_editor = current_user
|
||||
if @post.update_attributes(params[:blogpost] ? params[:blogpost].slice(:title, :content, :user_editor) : {})
|
||||
if @post.update_attributes(params[:blogpost].slice(:title, :content, :user_editor))
|
||||
redirect_to @post, notice: 'Post has been updated.'
|
||||
else
|
||||
flash[:alert] = "There was a problem while updating the post"
|
||||
|
||||
@@ -9,17 +9,33 @@ class ForumgroupsController < ApplicationController
|
||||
end
|
||||
|
||||
def edit
|
||||
if admin?
|
||||
@group = Forumgroup.find(params[:id])
|
||||
else
|
||||
flash[:alert] = "You are not allowed to edit forum groups."
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
if admin?
|
||||
@group = Forumgroup.find(params[:id])
|
||||
if @group.update_attributes(params[:forumgroup])
|
||||
flash[:notice] = "Forum group updated"
|
||||
redirect_to @group
|
||||
else
|
||||
flash[:alert] = "Something went wrong"
|
||||
render :edit
|
||||
end
|
||||
else
|
||||
flash[:alert] = "You are not allowed to change forum groups"
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
if admin?
|
||||
@group = Forumgroup.new
|
||||
else
|
||||
flash[:alert] = "You are not allowed to create forums."
|
||||
flash[:alert] = "You are not allowed to create forum groups."
|
||||
redirect_to forums_path
|
||||
end
|
||||
end
|
||||
@@ -28,14 +44,14 @@ class ForumgroupsController < ApplicationController
|
||||
if admin?
|
||||
@group = Forumgroup.new(params[:forumgroup])
|
||||
if @group.save
|
||||
flash[:notice] = "Forums created."
|
||||
flash[:notice] = "Forum group created."
|
||||
redirect_to @group
|
||||
else
|
||||
flash[:alert] = "Something went wrong"
|
||||
render :new
|
||||
end
|
||||
else
|
||||
flash[:alert] = "You are not allowed to create forums."
|
||||
flash[:alert] = "You are not allowed to create forum groups."
|
||||
redirect_to forums_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,28 +1,19 @@
|
||||
class ForumsController < ApplicationController
|
||||
before_filter :check_permission, only: [:show]
|
||||
|
||||
def index
|
||||
@groups = Forumgroup.all
|
||||
if current_user
|
||||
@groups.select! do |g|
|
||||
g.role_read.nil? || g.role_read <= current_user.role
|
||||
end
|
||||
else
|
||||
@groups.select!{|g| g.role_read == nil}
|
||||
end
|
||||
@groups.sort_by{|g| g[:position]}
|
||||
@groups.select!{|g| g.can_read?(current_user) }
|
||||
@groups.sort_by!{|g| g[:position]}
|
||||
end
|
||||
|
||||
def show
|
||||
@forum = Forum.find(params[:id])
|
||||
if @forum.role_read.nil? || current_user && @forum.role_read <= current_user.role
|
||||
@threads = @forum.forumthreads.order("sticky desc, updated_at desc")
|
||||
else
|
||||
redirect_to forums_path
|
||||
end
|
||||
@threads = @forum.forumthreads.order("sticky desc, updated_at desc")
|
||||
end
|
||||
|
||||
def new
|
||||
if admin?
|
||||
@group = Forumgroup.find(params[:forumgroup_id])
|
||||
@group = Forumgroup.find(params[:forumgroup])
|
||||
@forum = Forum.new(forumgroup: @group)
|
||||
else
|
||||
flash[:alert] = "You are not allowed to create a forum."
|
||||
@@ -33,7 +24,7 @@ class ForumsController < ApplicationController
|
||||
def create
|
||||
if admin?
|
||||
@forum = Forum.new(params[:forum])
|
||||
@forum.forumgroup = Forumgroup.find(params[:forumgroup_id])
|
||||
@forum.forumgroup = Forumgroup.find(params[:forum][:forumgroup_id])
|
||||
if @forum.save
|
||||
flash[:notice] = "Forum created."
|
||||
redirect_to @forum
|
||||
@@ -47,4 +38,16 @@ class ForumsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def check_permission
|
||||
@forum = Forum.find(params[:id])
|
||||
unless @forum.can_read?(current_user)
|
||||
flash[:alert] = "You are not allowed to view this forum"
|
||||
redirect_to forums_path
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -1,52 +1,49 @@
|
||||
class ForumthreadsController < ApplicationController
|
||||
|
||||
before_filter :check_permission
|
||||
|
||||
def index
|
||||
f = Forum.find(params[:forum_id])
|
||||
redirect_to forum_path(f.forumgroup, f)
|
||||
redirect_to forum_path(@thread.forum.forumgroup, f)
|
||||
end
|
||||
|
||||
def show
|
||||
@thread = Forumthread.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@thread = Forumthread.find(params[:id])
|
||||
if mod? || @thread.author.is?(current_user)
|
||||
@thread.user_editor = current_user
|
||||
if @thread.update_attributes(params[:forumthread] ? params[:forumthread].slice(:title, :content, :user_editor) : {})
|
||||
redirect_to [@thread.forum, @thread], notice: 'Post has been updated.'
|
||||
if @thread.update_attributes(params[:forumthread].slice(:title, :content, :user_editor))
|
||||
redirect_to @thread, notice: 'Post has been updated.'
|
||||
else
|
||||
flash[:alert] = "There was a problem while updating the post"
|
||||
render action: "edit"
|
||||
end
|
||||
else
|
||||
flash[:alert] = "You are not allowed to edit this thread!"
|
||||
redirect_to [@thread.forum, @thread]
|
||||
redirect_to @thread
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@thread = Forumthread.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@forum = Forum.find(params[:forum_id])
|
||||
if @forum && current_user && (@forum.group.role_read.nil? || @forum.group.role_read <= current_user.role) && (@forum.role_read.nil? || @forum.role_read <= current_user.role)
|
||||
@thread = Forumthread.new(forum: @forum)
|
||||
else
|
||||
flash[:alert] = "You are not allowed to create a new thread here!"
|
||||
redirect_to @forum
|
||||
unless @forum.can_write?(current_user)
|
||||
flash[:alert] = "You are not allowed to view this forum"
|
||||
redirect_to forums_path
|
||||
end
|
||||
@thread = Forumthread.new(forum: @forum)
|
||||
end
|
||||
|
||||
def create
|
||||
@forum = Forum.find(params[:forum_id])
|
||||
if (confirmed? && (@forum.group.role_read || Role.get(:default))<= current_user.role && (@forum.group.role_write || Role.get(:default))<= current_user.role && (@forum.role_read || Role.get(:default))<= current_user.role && (@forum.group.role_write || Role.get(:default))<= current_user.role)
|
||||
@thread = Forumthread.new(mod? ? params[:forumthread] : params[:forumthread].slice(:title, :content))
|
||||
@thread = Forumthread.new(mod? ? params[:forumthread] : params[:forumthread].slice(:title, :content))
|
||||
if @thread.can_write?(current_user)
|
||||
@thread.user_author = current_user
|
||||
@thread.forum = @forum
|
||||
@thread.forum = @thread.forum
|
||||
if @thread.save
|
||||
flash[:notice] = "Thread created!"
|
||||
redirect_to forum_forumthread_path(@forum, @thread)
|
||||
redirect_to forumthread_path( @thread)
|
||||
return
|
||||
else
|
||||
flash[:alert] = "Seomthing went wrong while creating your thread."
|
||||
@@ -55,7 +52,20 @@ class ForumthreadsController < ApplicationController
|
||||
end
|
||||
else
|
||||
flash[:alert] = "You are not allowed to create a thread here!"
|
||||
redirect_to @forum
|
||||
redirect_to @thread.forum
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def check_permission
|
||||
if params[:id]
|
||||
@thread = Forumthread.find(params[:id])
|
||||
unless @thread.can_read?(current_user)
|
||||
flash[:alert] = "You are not allowed to view this thread"
|
||||
redirect_to forums_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class SessionsController < ApplicationController
|
||||
require 'resolv'
|
||||
|
||||
def new
|
||||
if current_user
|
||||
@@ -14,22 +13,13 @@ class SessionsController < ApplicationController
|
||||
unless current_user
|
||||
user = User.find_by_email(params[:email])
|
||||
if user && user.authenticate(params[:password])
|
||||
hostname = ""
|
||||
begin
|
||||
hostname = Resolv.getname(request.remote_ip)
|
||||
rescue
|
||||
hostname = ""
|
||||
end
|
||||
user.last_ip = "#{request.remote_ip} | #{hostname}"
|
||||
user.last_login = Time.now
|
||||
user.save
|
||||
if user.disabled?
|
||||
flash[:alert] = "Your account has been disabled!"
|
||||
elsif user.banned?
|
||||
flash[:alert] = "You are banned!"
|
||||
else
|
||||
session[:user_id] = user.id
|
||||
flash[:alert] = "Remember to validate your email! Your account may be deleted soon!" if user.unconfirmed?
|
||||
flash[:alert] = "Remember to validate your email! Your account may be deleted soon!" if !user.confirmed?
|
||||
flash[:notice] = "Logged in!"
|
||||
end
|
||||
else
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class ThreadrepliesController < ApplicationController
|
||||
|
||||
end
|
||||
@@ -13,6 +13,7 @@ require 'open-uri'
|
||||
@users = User.all
|
||||
@users.shift() #Remove first user
|
||||
end
|
||||
@users = @users.sort_by{|u| u.role}.reverse!
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -29,7 +30,7 @@ require 'open-uri'
|
||||
flash[:notice] = "You are already signed up!"
|
||||
redirect_to current_user
|
||||
else
|
||||
@user = User.new(role: Role.get(:unconfirmed))
|
||||
@user = User.new
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,9 +38,9 @@ require 'open-uri'
|
||||
if current_user
|
||||
@user = User.find(params[:id])
|
||||
code = params[:code]
|
||||
if @user && @user.is?(current_user) && code && @user.confirm_code == code
|
||||
if @user.role == Role.get(:unconfirmed)
|
||||
@user.role = Role.get :default
|
||||
if @user && @user.is?(current_user) && code && @user.email_token == code
|
||||
if !confirmed?
|
||||
@user.confirmed = true
|
||||
if @user.save
|
||||
flash[:notice] = "Registration mail confirmed."
|
||||
redirect_to edit_user_path(@user)
|
||||
@@ -49,7 +50,7 @@ require 'open-uri'
|
||||
redirect_to @user
|
||||
return
|
||||
end
|
||||
elsif @user.role < Role.get(:unconfirmed)
|
||||
elsif @user.role < Role.get(:normal)
|
||||
flash[:alert] = "Your account has been banned or removed"
|
||||
else
|
||||
flash[:alert] = "Your account has already been confirmed!"
|
||||
@@ -60,7 +61,8 @@ require 'open-uri'
|
||||
redirect_to root_path
|
||||
end
|
||||
else
|
||||
flash[:alert] = "Please login"
|
||||
flash[:alert] = "Please login first"
|
||||
cookies[:return_path] = request.fullpath
|
||||
redirect_to login_path
|
||||
end
|
||||
end
|
||||
@@ -78,32 +80,44 @@ require 'open-uri'
|
||||
flash[:notice] = "You are already signed up!"
|
||||
redirect_to current_user
|
||||
else
|
||||
@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
|
||||
if uses_mc_password?(@user.ign, params[:user][:password])
|
||||
minecraftpw = true
|
||||
flash[:alert] = "Really? That's your Minecraft password!"
|
||||
@user = User.new(params[:user] ? params[:user].slice(:ign, :email, :password, :password_confirmation) : {} )
|
||||
user_profile = @user.get_profile
|
||||
if user_profile
|
||||
@user.uuid = user_profile["id"]
|
||||
@user.ign = user_profile["name"] # correct case
|
||||
if validate_token(@user.uuid, @user.email, params[:registration_token])
|
||||
@user.last_ip = request.remote_ip # showing in mail
|
||||
if @user.save
|
||||
session[:user_id] = @user.id
|
||||
if @user.uses_mc_password?(params[:user][:password])
|
||||
is_idiot = true
|
||||
flash[:alert] = "Really? That's your Minecraft password!"
|
||||
end
|
||||
begin
|
||||
RedstonerMailer.register_mail(@user, is_idiot).deliver
|
||||
RedstonerMailer.register_info_mail(@user, is_idiot).deliver
|
||||
rescue => e
|
||||
puts "---"
|
||||
puts "WARNING: registration mail failed for user #{@user.name}, #{@user.email}"
|
||||
puts e.message
|
||||
puts "---"
|
||||
flash[:alert] = "Registration mail failed. Please contact us in-game."
|
||||
end
|
||||
flash[:notice] = "Successfully signed up! Check your email!"
|
||||
redirect_to edit_user_path(@user)
|
||||
else
|
||||
flash[:alert] = "Something went wrong"
|
||||
render action: "new"
|
||||
end
|
||||
@user.email_token = SecureRandom.hex(16)
|
||||
else
|
||||
flash[:alert] = "Token invalid for this username"
|
||||
render action: "new"
|
||||
end
|
||||
begin
|
||||
RedstonerMailer.register_mail(@user, minecraftpw).deliver
|
||||
RedstonerMailer.register_info_mail(@user, minecraftpw).deliver
|
||||
rescue => e
|
||||
puts "---"
|
||||
puts "WARNING: registration mail failed for user #{@user.name}, #{@user.email}"
|
||||
puts e.message
|
||||
puts "---"
|
||||
flash[:alert] = "Registration mail failed. Please contact us in-game."
|
||||
end
|
||||
flash[:notice] = "Successfully signed up! Check your email!"
|
||||
redirect_to edit_user_path(@user)
|
||||
else
|
||||
flash[:alert] = "Something went wrong"
|
||||
render action: "new"
|
||||
flash[:alert] = "Error. Your username is not correct or Mojang's servers are down."
|
||||
render action: new
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -129,10 +143,10 @@ require 'open-uri'
|
||||
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?]
|
||||
flash[:alert] = "Couldn't find a YouTube channel with that name, are you sure it's correct?" unless youtube[:is_correct?]
|
||||
end
|
||||
if @user.update_attributes(userdata)
|
||||
flash[:notice] = 'Profile updated.'
|
||||
flash[:notice] = 'Profile updated.'
|
||||
else
|
||||
flash[:alert] = "There was a problem while updating the profile"
|
||||
render action: "edit"
|
||||
@@ -158,7 +172,7 @@ require 'open-uri'
|
||||
def unban
|
||||
@user = User.find(params[:id])
|
||||
if mod? && current_user.role >= @user.role
|
||||
@user.role = Role.get :default
|
||||
@user.role = Role.get :normal
|
||||
flash[:notice] = "\"#{@user.name}\" has been unbanned!"
|
||||
else
|
||||
flash[:alert] = "You are not allowed to unban this user!"
|
||||
@@ -212,4 +226,13 @@ require 'open-uri'
|
||||
redirect_to old_user
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
|
||||
def validate_token(uuid, email, token)
|
||||
user_token = RegisterToken.where(uuid: uuid, email: email).first
|
||||
user_token && user_token.token == token
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user