first release

This commit is contained in:
jomo
2013-05-31 22:26:22 +02:00
parent 149232ec0c
commit 8921d108e2
70 changed files with 1080 additions and 85 deletions

View File

@@ -1,3 +1,10 @@
class ApplicationController < ActionController::Base
protect_from_forgery
force_ssl
require "Tools"
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user
end

View File

@@ -0,0 +1,58 @@
class BlogpostsController < ApplicationController
# GET /blogposts
# GET /blogposts.json
def index
@posts = Blogpost.all.reverse
end
# GET /blogposts/1
# GET /blogposts/1.json
def show
@post = Blogpost.find(params[:id])
@comment = Comment.new(:blogpost_id => @post.id)
end
# GET /blogposts/new
# GET /blogposts/new.json
def new
@post = Blogpost.new
end
# GET /blogposts/1/edit
def edit
@post = Blogpost.find(params[:id])
end
# POST /blogposts
# POST /blogposts.json
def create
@post = Blogpost.new(params[:blogpost])
@post.user_id = current_user.id unless current_user.nil?
if @post.save
redirect_to @post, notice: 'Post has been created.'
else
render action: "new"
end
end
# PUT /blogposts/1
# PUT /blogposts/1.json
def update
@post = Blogpost.find(params[:id])
if @post.update_attributes(params[:blogpost])
redirect_to @post, notice: 'Post has been updated.'
else
render action: "edit"
end
end
# DELETE /blogposts/1
# DELETE /blogposts/1.json
def destroy
@post = Blogpost.find(params[:id])
@post.destroy
redirect_to blogposts_url
end
end

View File

@@ -0,0 +1,83 @@
class CommentsController < ApplicationController
# GET /comments
# GET /comments.json
def index
@comments = Comment.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @comments }
end
end
# GET /comments/1
# GET /comments/1.json
def show
@comment = Comment.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @comment }
end
end
# GET /comments/new
# GET /comments/new.json
def new
@comment = Comment.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @comment }
end
end
# GET /comments/1/edit
def edit
@comment = Comment.find(params[:id])
end
# POST /comments
# POST /comments.json
def create
@comment = Comment.new(params[:comment])
@comment.user_id = current_user.id
respond_to do |format|
if @comment.save
format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
format.json { render json: @comment, status: :created, location: @comment }
else
format.html { render action: "new" }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end
# PUT /comments/1
# PUT /comments/1.json
def update
@comment = Comment.find(params[:id])
respond_to do |format|
if @comment.update_attributes(params[:comment])
format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end
# DELETE /comments/1
# DELETE /comments/1.json
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.html { redirect_to comments_url }
format.json { head :no_content }
end
end
end

View File

@@ -0,0 +1,35 @@
class PaypalController < ApplicationController
protect_from_forgery :except => [:create] #Otherwise the request from PayPal wouldn't make it to the controller
def create
puts request.raw_post
response = validate_IPN_notification(request.raw_post)
case response
when "VERIFIED"
# check that paymentStatus=Completed
# check that txnId has not been previously processed
# check that receiverEmail is your Primary PayPal email
# check that paymentAmount/paymentCurrency are correct
# process payment
when "INVALID"
# log for investigation
else
# error
end
render :nothing => true
end
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)
http.open_timeout = 60
http.read_timeout = 60
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
response = http.post(uri.request_uri, raw,
'Content-Length' => "#{raw.size}",
'User-Agent' => "Redstoner.com"
).body
end
end

View File

@@ -0,0 +1,10 @@
class ServercheckerController < ApplicationController
def show
require "Tools"
if Tools.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

@@ -0,0 +1,29 @@
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
user.last_ip = request.remote_ip
user.save
if user.banned
flash[:alert] = "You are banned!"
redirect_to login_path
else
session[:user_id] = user.id
redirect_to root_path, :notice => "Logged in!"
end
else
flash[:alert] = "You're doing it wrong!"
redirect_to login_path
end
end
def destroy
session[:user_id] = nil
redirect_to root_path, :notice => "Logged out!"
end
end

View File

@@ -0,0 +1,54 @@
class UsersController < ApplicationController
# GET /users
# GET /users.json
def index
@users = User.all
end
# GET /users/1
# GET /users/1.json
def show
@user = User.find(params[:id])
end
# GET /users/new
# GET /users/new.json
def new
@user = User.new
end
# GET /users/1/edit
def edit
@user = User.find(params[:id])
end
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
if @user.save
redirect_to @user, notice: 'User was successfully created.'
else
render action: "new"
end
end
# PUT /users/1
# PUT /users/1.json
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
redirect_to @user, notice: 'User was successfully updated.'
else
render action: "edit"
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user = User.find(params[:id])
@user.destroy
redirect_to users_url
end
end