rails 4 and tons of stuff

This commit is contained in:
jomo
2014-04-14 06:26:37 +02:00
parent b740c4db3a
commit 7135d2690c
41 changed files with 349 additions and 206 deletions

View File

@@ -1,5 +1,5 @@
class Blogpost < ActiveRecord::Base
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"

View File

@@ -1,5 +1,5 @@
class Comment < ActiveRecord::Base
attr_accessible :content, :author, :blogpost, :post
validates_presence_of :content, :author, :blogpost
validates_length_of :content, in: 4..1000

View File

@@ -4,8 +4,6 @@ class Forum < ActiveRecord::Base
belongs_to :role_read, class_name: "Role", foreign_key: "role_read_id"
belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id"
attr_accessible :name, :position, :role_read, :role_write, :role_read_id, :role_write_id, :forumgroup, :forumgroup_id
def to_s
name
end

View File

@@ -4,7 +4,7 @@ class Forumgroup < ActiveRecord::Base
belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id"
accepts_nested_attributes_for :forums
attr_accessible :name, :position, :role_read, :role_write, :role_read_id, :role_write_id
validates_presence_of :name, :position
validates_length_of :name, in: 2..20

View File

@@ -4,7 +4,7 @@ class Forumthread < ActiveRecord::Base
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
has_many :threadreplies
attr_accessible :title, :content, :sticky, :locked, :user_author, :user_editor, :forum
validates_presence_of :title, :author, :forum
validates_presence_of :content

View File

@@ -1,7 +1,7 @@
class Role < ActiveRecord::Base
include Comparable
has_many :users
attr_accessible :name, :value
def to_s
self.name

View File

@@ -3,7 +3,7 @@ class Threadreply < ActiveRecord::Base
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
attr_accessible :title, :content, :sticky, :locked, :user_author, :user_editor, :forumthread
validates_presence_of :content
validates_length_of :content, in: 2..10000

View File

@@ -3,7 +3,7 @@ class User < ActiveRecord::Base
include Rails.application.routes.url_helpers
belongs_to :role
attr_accessible :uuid, :confirmed, :name, :password, :password_confirmation, :ign, :email, :email_token, :about, :last_ip, :skype, :skype_public, :youtube, :youtube_channelname, :twitter, :last_seen, :role, :role_id
has_secure_password
@@ -17,8 +17,8 @@ class User < ActiveRecord::Base
validates_length_of :about, maximum: 5000
validates_length_of :ign, minimum: 2, maximum: 16
validates :email, uniqueness: {case_sensitive: false}, format: {with: /^.+@.+\..{2,}$/i, message: "That doesn't look like an email adress."}
validates :ign, uniqueness: {case_sensitive: false}, format: {with: /^[a-z\d_]+$/i, message: "That is probably not your username."}
validates :email, uniqueness: {case_sensitive: false}, format: {with: /\A.+@.+\..{2,}\z/i, message: "That doesn't look like an email adress."}
validates :ign, uniqueness: {case_sensitive: false}, format: {with: /\A[a-z\d_]+\z/i, message: "That is probably not your username."}
validate :has_paid, :if => lambda {|user| user.ign_changed? }
@@ -101,12 +101,10 @@ class User < ActiveRecord::Base
response = open("https://sessionserver.mojang.com/session/minecraft/profile/#{CGI.escape(self.uuid)}", read_timeout: 0.5)
if response.status[0] == "200"
session_profile = JSON.load(response.read)
if session_profile["legacy"] == true
return open("https://minecraft.net/haspaid.jsp?#{{user: self.ign}.to_query}", read_timeout: 0.5).read == "true"
else
return true
end
# unpaid accounts are called 'demo' accounts
return session_profile["demo"] == true
elsif response.status[0] == "204"
# user doesn't exist
return false
else
puts "---"