diff --git a/Gemfile b/Gemfile index e4e9806..18434a7 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,11 @@ gem 'rails', '3.2.12' # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' - +gem 'jquery-rails' +gem 'therubyracer' +gem 'bcrypt-ruby', '~> 3.0.0' # To use ActiveModel has_secure_password +gem 'simple_form' +gem 'rbbcode' # Gems used only for assets and not required # in production environments by default. @@ -20,11 +24,10 @@ group :assets do gem 'uglifier', '>= 1.0.3' end -gem 'jquery-rails' -gem 'therubyracer' - -# To use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' +group :development do + gem 'better_errors' + gem 'binding_of_caller' +end # To use Jbuilder templates for JSON # gem 'jbuilder' diff --git a/Gemfile.lock b/Gemfile.lock index eecfb76..30f44e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,7 +29,14 @@ GEM i18n (~> 0.6) multi_json (~> 1.0) arel (3.0.2) + bcrypt-ruby (3.0.1) + better_errors (0.7.2) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + binding_of_caller (0.7.1) + debug_inspector (>= 0.0.1) builder (3.0.4) + coderay (1.0.9) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -37,6 +44,7 @@ GEM coffee-script-source execjs coffee-script-source (1.6.2) + debug_inspector (0.0.2) erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) @@ -54,6 +62,7 @@ GEM treetop (~> 1.4.8) mime-types (1.23) multi_json (1.7.3) + nokogiri (1.5.9) polyglot (0.3.3) rack (1.4.5) rack-cache (1.2) @@ -78,14 +87,23 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.4) + rbbcode (1.0.3) + sanitize + treetop 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) sass (>= 3.1.10) tilt (~> 1.3) + simple_form (2.1.0) + actionpack (~> 3.0) + activemodel (~> 3.0) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -109,10 +127,15 @@ PLATFORMS ruby DEPENDENCIES + bcrypt-ruby (~> 3.0.0) + better_errors + binding_of_caller coffee-rails (~> 3.2.1) jquery-rails rails (= 3.2.12) + rbbcode sass-rails (~> 3.2.3) + simple_form sqlite3 therubyracer uglifier (>= 1.0.3) diff --git a/app/assets/images/favicon.ico b/app/assets/images/favicon.ico new file mode 100644 index 0000000..501f61a Binary files /dev/null and b/app/assets/images/favicon.ico differ diff --git a/app/assets/images/logo.png b/app/assets/images/logo.png new file mode 100644 index 0000000..ce58fb1 Binary files /dev/null and b/app/assets/images/logo.png differ diff --git a/app/assets/images/off.png b/app/assets/images/off.png new file mode 100644 index 0000000..2720164 Binary files /dev/null and b/app/assets/images/off.png differ diff --git a/app/assets/images/on.png b/app/assets/images/on.png new file mode 100644 index 0000000..12a001a Binary files /dev/null and b/app/assets/images/on.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9097d83..a6df101 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,6 +10,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 jquery_ujs -//= require_tree . +//= #require jquery +//= #require jquery_ujs +//= #require_tree . diff --git a/app/assets/javascripts/blogposts.js.coffee b/app/assets/javascripts/blogposts.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/blogposts.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/comments.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/users.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 3192ec8..e93ffaf 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -1,13 +1,6 @@ /* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the top of the - * compiled file, but it's generally better to create a new file per style scope. - * *= require_self - *= require_tree . - */ + *= require style.css + *= require screen.css + *= require mobi.css + */ \ No newline at end of file diff --git a/app/assets/stylesheets/blogposts.css.scss b/app/assets/stylesheets/blogposts.css.scss new file mode 100644 index 0000000..916c0b2 --- /dev/null +++ b/app/assets/stylesheets/blogposts.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Blogposts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/comments.css.scss b/app/assets/stylesheets/comments.css.scss new file mode 100644 index 0000000..e730912 --- /dev/null +++ b/app/assets/stylesheets/comments.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Comments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/mobi.css.scss b/app/assets/stylesheets/mobi.css.scss new file mode 100644 index 0000000..154a36b --- /dev/null +++ b/app/assets/stylesheets/mobi.css.scss @@ -0,0 +1,6 @@ +/* CSS for Phones only */ +@media only screen +and (max-width: 999px) +{ + +} \ No newline at end of file diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..6ec6a8f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/app/assets/stylesheets/screen.css.scss b/app/assets/stylesheets/screen.css.scss new file mode 100644 index 0000000..18f730f --- /dev/null +++ b/app/assets/stylesheets/screen.css.scss @@ -0,0 +1,127 @@ +/* CSS for PCs only */ +@media only screen +and (min-width: 1000px) +{ + + + + + a { + transition: color 0.25s; + color: #700; + text-decoration: none; + &:hover { + color: #F00; + } + } + #notice { + background: #8e8; + text-align: center; + padding: 10px; + border-bottom: 3px dashed #8d8; + font-weight: bold; + } + #alert { + background: #ebb; + text-align: center; + padding: 10px; + border-bottom: 3px dashed #fdd; + font-weight: bold; + } + #head { + width: 100%; + height: 40px; + background: #ccc; + border-bottom: 2px solid #aaa; + vertical-align: middle; + #logo { + margin: 4px; + margin-left: 20px; + height: 32px; + width: 32px; + float: left; + background: url('/assets/logo.png'); + } + #userinfo { + float: right; + padding: 0 10px; + margin-top: 2px; + img.avatar { + border: 1px solid #000; + border-radius: 16px; + vertical-align: middle; + &:hover { + box-shadow: 0 0 2px; + } + } + } + } + img.user-avatar { + border: 1px solid #000; + border-radius: 4px; + } + span.no-about { + color: #888; + font-style: italic; + } + + #main-content { + width: 650px; + margin: 0 auto; + background: #eee; + padding: 30px; + + h1 { + font-weight: normal; + font-size: 400%; + margin: 0; + color: #888; + text-shadow: 0 1px #999; + } + } + + #posts { + #post { + margin-bottom: 50px; + #post-title { + margin-bottom: 10px; + h2 { + font-weight: normal; + color: #700; + text-transform: uppercase; + display: inline; + font-size: 250%; + } + .comment-counter { + float: right; + } + } + } + } + + .post-info { + border-bottom: 2px dashed #999; + color: #888; + a { + color: #755; + &:hover{ + color: #d55; + } + } + } + + #post-content { + margin-top: 10px; + clear: both; + } + + #comments { + margin: 50px 0 0 40px; + textarea { + width: 480px; + height: 106px; + max-width: 610px; + } + } + +} \ No newline at end of file diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss new file mode 100644 index 0000000..82d020d --- /dev/null +++ b/app/assets/stylesheets/style.css.scss @@ -0,0 +1,9 @@ +/* General CSS for all screens */ +body { + margin: 0; + padding: 0; + font: 14px/1.6 "Open Sans","Lucida Sans","Lucida Grande","Lucida Sans Unicode",Calibri,sans-serif; +} + +// use screen.css +// and mobi.css \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e8065d9..c5928db 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb new file mode 100644 index 0000000..9df5451 --- /dev/null +++ b/app/controllers/blogposts_controller.rb @@ -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 diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..0d9e5b7 --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/controllers/paypal_controller.rb b/app/controllers/paypal_controller.rb new file mode 100644 index 0000000..6fc50f9 --- /dev/null +++ b/app/controllers/paypal_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/serverchecker_controller.rb b/app/controllers/serverchecker_controller.rb new file mode 100644 index 0000000..c87a4bf --- /dev/null +++ b/app/controllers/serverchecker_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..62af4b3 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..eb194da --- /dev/null +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/helpers/blogposts_helper.rb b/app/helpers/blogposts_helper.rb new file mode 100644 index 0000000..48e43d1 --- /dev/null +++ b/app/helpers/blogposts_helper.rb @@ -0,0 +1,2 @@ +module BlogpostsHelper +end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000..0ec9ca5 --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/blogpost.rb b/app/models/blogpost.rb new file mode 100644 index 0000000..4663d50 --- /dev/null +++ b/app/models/blogpost.rb @@ -0,0 +1,6 @@ +class Blogpost < ActiveRecord::Base + attr_accessible :title, :text + validates_presence_of :title, :text, :user + belongs_to :user + has_many :comments +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..bc2e39e --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,6 @@ +class Comment < ActiveRecord::Base + attr_accessible :text, :user_id, :blogpost_id + validates_presence_of :text, :user_id, :blogpost_id + belongs_to :blogpost + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..9347249 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,8 @@ +class User < ActiveRecord::Base + attr_accessible :name, :ign, :email, :about, :password, :password_confirmation + has_secure_password + validates_presence_of :password, :on => :create + + has_many :blogposts + has_many :comments +end \ No newline at end of file diff --git a/app/views/blogposts/_form.html.erb b/app/views/blogposts/_form.html.erb new file mode 100644 index 0000000..a61fb20 --- /dev/null +++ b/app/views/blogposts/_form.html.erb @@ -0,0 +1,5 @@ +<%= simple_form_for @post do |f|%> + <%= f.input :title %> + <%= f.input :text %> + <%= f.submit %> +<% end %> \ No newline at end of file diff --git a/app/views/blogposts/edit.html.erb b/app/views/blogposts/edit.html.erb new file mode 100644 index 0000000..b120662 --- /dev/null +++ b/app/views/blogposts/edit.html.erb @@ -0,0 +1,6 @@ +
| + | + | + |
|---|---|---|
| <%= link_to 'Show', comment %> | +<%= link_to 'Edit', edit_comment_path(comment) %> | +<%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ + +<%= link_to 'Edit', edit_comment_path(@comment) %> | +<%= link_to 'Back', comments_path %> diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb new file mode 100644 index 0000000..29e70f3 --- /dev/null +++ b/app/views/layouts/_head.html.erb @@ -0,0 +1,13 @@ +
New comment
+ <%= simple_form_for [@post, @comment] do |f| %> + <%= f.input :text, :label => false, :as => "text", :placeholder => "Comment" %><%= f.submit %> + <% end %> + <% end %> +