added user test, basic user methods
This commit is contained in:
@@ -5,26 +5,15 @@ require 'rails/all'
|
||||
# Auto-require default libraries and those for the current Rails environment.
|
||||
Bundler.require :default, Rails.env
|
||||
|
||||
module Danbooru2
|
||||
module Danbooru
|
||||
class Application < Rails::Application
|
||||
# Settings in config/environments/* take precedence over those specified here.
|
||||
# Application configuration should go into files in config/initializers
|
||||
# -- all .rb files in that directory are automatically loaded.
|
||||
|
||||
# Add additional load paths for your own custom dirs
|
||||
# config.load_paths += %W( #{config.root}/extras )
|
||||
config.load_paths += %W( #{config.root}/presenters #{config.root}/logical )
|
||||
|
||||
# Only load the plugins named here, in the order given (default is alphabetical).
|
||||
# :all can be used as a placeholder for all plugins not explicitly named
|
||||
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
||||
|
||||
# Activate observers that should always be running
|
||||
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
||||
|
||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
||||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
||||
# config.time_zone = 'Central Time (US & Canada)'
|
||||
|
||||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
|
||||
# config.i18n.default_locale = :de
|
||||
@@ -35,6 +24,8 @@ module Danbooru2
|
||||
# g.template_engine :erb
|
||||
# g.test_framework :test_unit, :fixture => true
|
||||
# end
|
||||
|
||||
config.active_record.schema_format = :sql
|
||||
|
||||
# Configure sensitive parameters which will be filtered from the log file.
|
||||
config.filter_parameters << :password
|
||||
|
||||
109
config/danbooru_default_config.rb
Normal file
109
config/danbooru_default_config.rb
Normal file
@@ -0,0 +1,109 @@
|
||||
module Danbooru
|
||||
class Configuration
|
||||
# The version of this Danbooru.
|
||||
def version
|
||||
"2.0.0"
|
||||
end
|
||||
|
||||
# The name of this Danbooru.
|
||||
def app_name
|
||||
"Danbooru"
|
||||
end
|
||||
|
||||
# The default name to use for anyone who isn't logged in.
|
||||
def default_guest_name
|
||||
"Anonymous"
|
||||
end
|
||||
|
||||
# This is a salt used to make dictionary attacks on account passwords harder.
|
||||
def password_salt
|
||||
"choujin-steiner"
|
||||
end
|
||||
|
||||
# Set to true to allow new account signups.
|
||||
def enable_signups?
|
||||
true
|
||||
end
|
||||
|
||||
# Set to true to give all new users privileged access.
|
||||
def start_as_privileged?
|
||||
false
|
||||
end
|
||||
|
||||
# Set to true to give all new users contributor access.
|
||||
def start_as_contributor?
|
||||
false
|
||||
end
|
||||
|
||||
# What method to use to store images.
|
||||
# local_flat: Store every image in one directory.
|
||||
# local_hierarchy: Store every image in a hierarchical directory, based on the post's MD5 hash. On some file systems this may be faster.
|
||||
def image_store
|
||||
:local_flat
|
||||
end
|
||||
|
||||
# Thumbnail size
|
||||
def small_image_width
|
||||
150
|
||||
end
|
||||
|
||||
# Medium resize image width
|
||||
def medium_image_width
|
||||
500
|
||||
end
|
||||
|
||||
# Large resize image width
|
||||
def large_image_width
|
||||
1024
|
||||
end
|
||||
|
||||
# List of memcached servers
|
||||
def memcached_servers
|
||||
%w(localhost:11211)
|
||||
end
|
||||
|
||||
# After a post receives this many comments, new comments will no longer bump the post in comment/index.
|
||||
def comment_threshold
|
||||
40
|
||||
end
|
||||
|
||||
# Members cannot post more than X comments in an hour.
|
||||
def member_comment_limit
|
||||
2
|
||||
end
|
||||
|
||||
# Determine who can see a post.
|
||||
def can_see_post?(post, user)
|
||||
true
|
||||
end
|
||||
|
||||
# Determines who can see ads.
|
||||
def can_see_ads?(user)
|
||||
false
|
||||
end
|
||||
|
||||
# This is required for Rails 2.0.
|
||||
def session_secret_key
|
||||
"This should be at least 30 characters long"
|
||||
end
|
||||
|
||||
# Users cannot search for more than X regular tags at a time.
|
||||
def tag_query_limit
|
||||
6
|
||||
end
|
||||
|
||||
# Max number of posts to cache
|
||||
def tag_subscription_post_limit
|
||||
200
|
||||
end
|
||||
|
||||
# Max number of tag subscriptions per user
|
||||
def max_tag_subscriptions
|
||||
5
|
||||
end
|
||||
|
||||
def server_host
|
||||
Socket.gethostname
|
||||
end
|
||||
end
|
||||
end
|
||||
5
config/danbooru_local_config.rb
Normal file
5
config/danbooru_local_config.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Danbooru
|
||||
class CustomConfiguration < Configuration
|
||||
# Define your custom overloads here
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,8 @@
|
||||
# SQLite version 3.x
|
||||
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
||||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
adapter: postgresql
|
||||
database: danbooru2
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
@@ -10,13 +10,13 @@ development:
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: db/test.sqlite3
|
||||
adapter: postgresql
|
||||
database: danbooru2_test
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
production:
|
||||
adapter: sqlite3
|
||||
database: db/production.sqlite3
|
||||
adapter: postgresql
|
||||
database: danbooru2
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
require File.expand_path('../application', __FILE__)
|
||||
|
||||
# Initialize the rails application
|
||||
Danbooru2::Application.initialize!
|
||||
Danbooru::Application.initialize!
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Danbooru2::Application.configure do
|
||||
Danbooru::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/environment.rb
|
||||
|
||||
# In the development environment your application's code is reloaded on
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Danbooru2::Application.configure do
|
||||
Danboorus::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/environment.rb
|
||||
|
||||
# The production environment is meant for finished, "live" apps.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Danbooru2::Application.configure do
|
||||
Danbooru::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/environment.rb
|
||||
|
||||
# The test environment is used exclusively to run your application's
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
# If you change this key, all old signed cookies will become invalid!
|
||||
# Make sure the secret is at least 30 characters and all random,
|
||||
# no regular words or you'll be exposed to dictionary attacks.
|
||||
ActionController::Base.cookie_verifier_secret = '9d3404d788351e80007345ca60b0cc4484e1906a2feab4be105e0637946c220e1f7239902b4234892923b9b45cf6f9a0a818302d81f890849e9bfe19ce03a30d'
|
||||
ActionController::Base.cookie_verifier_secret = '214c98302eef905ab8bce4a19562e322097c526f28e718160a3c0d617ddc8edab6ae7e22cb5eec8930e215bfb936a7086d6f5b146c0092a9af1884613ce0a260'
|
||||
|
||||
31
config/initializers/core_extensions.rb
Normal file
31
config/initializers/core_extensions.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class ActiveRecord::Base
|
||||
class << self
|
||||
public :sanitize_sql_array
|
||||
end
|
||||
|
||||
%w(execute select_value select_values select_all).each do |method_name|
|
||||
define_method("#{method_name}_sql") do |sql, *params|
|
||||
connection.__send__(method_name, self.class.sanitize_sql_array([sql, *params]))
|
||||
end
|
||||
|
||||
self.class.__send__(:define_method, "#{method_name}_sql") do |sql, *params|
|
||||
connection.__send__(method_name, sanitize_sql_array([sql, *params]))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class NilClass
|
||||
def id
|
||||
raise NoMethodError
|
||||
end
|
||||
end
|
||||
|
||||
class String
|
||||
def to_escaped_for_sql_like
|
||||
return self.gsub(/\\/, '\0\0').gsub(/%/, '\\%').gsub(/_/, '\\_').gsub(/\*/, '%')
|
||||
end
|
||||
|
||||
def to_escaped_js
|
||||
return self.gsub(/\\/, '\0\0').gsub(/['"]/) {|m| "\\#{m}"}.gsub(/\r\n|\r|\n/, '\\n')
|
||||
end
|
||||
end
|
||||
10
config/initializers/danbooru_config.rb
Normal file
10
config/initializers/danbooru_config.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require "#{Rails.root}/config/danbooru_default_config"
|
||||
require "#{Rails.root}/config/danbooru_local_config"
|
||||
|
||||
module Danbooru
|
||||
def config
|
||||
@configuration ||= CustomConfiguration.new
|
||||
end
|
||||
|
||||
module_function :config
|
||||
end
|
||||
6
config/initializers/memcache.rb
Normal file
6
config/initializers/memcache.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
require 'memcache'
|
||||
|
||||
unless defined?(MEMCACHE)
|
||||
MEMCACHE = MemCache.new :c_threshold => 10_000, :compression => true, :debug => false, :namespace => Danbooru.config.app_name.gsub(/[^A-Za-z0-9]/, "_"), :readonly => false, :urlencode => false
|
||||
MEMCACHE.servers = Danbooru.config.memcached_servers
|
||||
end
|
||||
@@ -5,8 +5,8 @@
|
||||
# Make sure the secret is at least 30 characters and all random,
|
||||
# no regular words or you'll be exposed to dictionary attacks.
|
||||
ActionController::Base.session = {
|
||||
:key => '_danbooru2_session',
|
||||
:secret => '8c46b9a05b0222b74454c6f4bd461be89cc762d9ef3dab4513997670ffed45086bc7a025d45ead5accca656cfb9ab64e70dd44c4379653cf8d4ca45f455ac8ec'
|
||||
:key => '_danbooru_session',
|
||||
:secret => '3102c705148af8124298f9e89d45da3d26e47cc4d9a67cb1c8d9c42c008ee253786346efda50331bb14811f1f445c1c9ed2d51597ad2017328de0dd263048d1a'
|
||||
}
|
||||
|
||||
# Use the database for sessions instead of the cookie-based default,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Danbooru2::Application.routes.draw do |map|
|
||||
Danbooru::Application.routes.draw do |map|
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user