mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
Search engines are ranking profiles above the actual site, so we're going to tell search engines not to index them.
125 lines
3.1 KiB
Ruby
125 lines
3.1 KiB
Ruby
def dashboard_if_signed_in
|
|
redirect '/dashboard' if signed_in?
|
|
end
|
|
|
|
def require_login_ajax
|
|
halt 'You are not logged in!' unless signed_in?
|
|
halt 'Please contact support.' if banned?
|
|
end
|
|
|
|
def csrf_safe?
|
|
csrf_token == params[:csrf_token] || csrf_token == request.env['HTTP_X_CSRF_TOKEN']
|
|
end
|
|
|
|
def csrf_token
|
|
session[:_csrf_token] ||= SecureRandom.base64(32)
|
|
end
|
|
|
|
def is_education?
|
|
current_site && current_site.is_education
|
|
end
|
|
|
|
def require_login
|
|
redirect '/' unless signed_in? && current_site
|
|
enforce_ban if banned?
|
|
signout if deleted?
|
|
end
|
|
|
|
def signed_in?
|
|
!session[:id].nil?
|
|
end
|
|
|
|
def current_site
|
|
return nil if session[:id].nil?
|
|
@_site ||= Site[id: session[:id]]
|
|
end
|
|
|
|
def parent_site
|
|
return nil if current_site.nil?
|
|
current_site.parent? ? current_site : current_site.parent
|
|
end
|
|
|
|
def deleted?
|
|
return true if current_site && current_site.is_deleted
|
|
false
|
|
end
|
|
|
|
def banned?(ip_check=false)
|
|
return true if session[:banned]
|
|
return true if current_site && (current_site.is_banned || parent_site.is_banned)
|
|
|
|
return true if ip_check && Site.banned_ip?(request.ip)
|
|
false
|
|
end
|
|
|
|
def enforce_ban
|
|
signout
|
|
session[:banned] = true
|
|
redirect '/'
|
|
end
|
|
|
|
def meta_robots(newtag=nil)
|
|
if newtag
|
|
@_meta_robots = newtag
|
|
end
|
|
|
|
@_meta_robots
|
|
tag = newtag || @_meta_robots
|
|
end
|
|
|
|
def title
|
|
out = "Neocities"
|
|
return out if request.path == '/'
|
|
return "#{out} - #{@title}" if @title
|
|
"#{out} - #{request.path.gsub('/', '').capitalize}"
|
|
end
|
|
|
|
def encoding_fix(file)
|
|
begin
|
|
Rack::Utils.escape_html file
|
|
rescue ArgumentError => e
|
|
if e.message =~ /invalid byte sequence in UTF-8/ ||
|
|
e.message =~ /incompatible character encodings/
|
|
return Rack::Utils.escape_html(file.force_encoding('BINARY'))
|
|
end
|
|
fail
|
|
end
|
|
end
|
|
|
|
def send_confirmation_email(site=current_site)
|
|
if site.email_confirmation_count > Site::MAXIMUM_EMAIL_CONFIRMATIONS
|
|
flash[:error] = 'You sent too many email confirmation requests, cannot continue.'
|
|
redirect request.referrer
|
|
end
|
|
|
|
DB['UPDATE sites set email_confirmation_count=email_confirmation_count+1 WHERE id=?', site.id].first
|
|
|
|
EmailWorker.perform_async({
|
|
from: 'web@neocities.org',
|
|
reply_to: 'contact@neocities.org',
|
|
to: site.email,
|
|
subject: "[Neocities] Confirm your email address",
|
|
body: Tilt.new('./views/templates/email/confirm.erb', pretty: true).render(self, site: site)
|
|
})
|
|
end
|
|
|
|
def dont_browser_cache
|
|
headers['Cache-Control'] = 'private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0'
|
|
headers['Pragma'] = 'no-cache'
|
|
headers['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
|
|
@dont_browser_cache = true
|
|
end
|
|
|
|
def email_not_validated?
|
|
return false if current_site && current_site.created_at < Site::EMAIL_VALIDATION_CUTOFF_DATE
|
|
|
|
current_site && current_site.parent? && !current_site.is_education && !current_site.email_confirmed && !current_site.supporter?
|
|
end
|
|
|
|
def sanitize_comment(text)
|
|
Rinku.auto_link Sanitize.fragment(text), :all, 'target="_blank" rel="nofollow"'
|
|
end
|
|
|
|
def flash_display(opts={})
|
|
erb :'_flash', layout: false, locals: {opts: opts}
|
|
end
|