From 08026ac235b094482fee189a03653a0188252f56 Mon Sep 17 00:00:00 2001
From: Kyle Drake
Date: Wed, 13 Aug 2014 19:27:40 -0700
Subject: [PATCH 1/2] fix for missing following code, email fixes, start on
delete site
---
.gitignore | 1 +
app.rb | 17 ++++++++++++++++-
models/site.rb | 6 ++----
views/not_found.erb | 4 +++-
views/settings.erb | 33 ++++++++++++++++++++++++++++++---
views/site.erb | 3 ++-
6 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/.gitignore b/.gitignore
index d9e773be..4d898869 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,4 @@ public/site_thumbnails
public/sites
public/site_screenshots
*.swp
+files/map.txt
diff --git a/app.rb b/app.rb
index da9770c2..106c077f 100644
--- a/app.rb
+++ b/app.rb
@@ -85,7 +85,7 @@ get '/site/:username.rss' do |username|
site.to_rss.to_xml
end
-get '/site/:username' do |username|
+get '/site/:username/?' do |username|
site = Site[username: username]
not_found if site.nil?
if current_site && (site.is_blocking?(current_site) || current_site.is_blocking?(site))
@@ -531,6 +531,11 @@ post '/change_email' do
current_site.email_confirmation_token = SecureRandom.hex 3
current_site.email_confirmed = false
+ if params[:email] == current_site.email
+ current_site.errors.add :email, 'You are already using this email address for this account.'
+ halt erb(:settings)
+ end
+
if current_site.valid?
current_site.save_changes
send_confirmation_email
@@ -1146,6 +1151,16 @@ post '/site/:username/block' do |username|
end
end
+post '/site/delete' do
+ require_login
+ if current_site.username != params[:username]
+ errors.add :username, 'Could not delete site, site name did not match.'
+ halt erb(:settings)
+ end
+
+
+end
+
def require_admin
redirect '/' unless signed_in? && current_site.is_admin
end
diff --git a/models/site.rb b/models/site.rb
index de366a55..39a00fed 100644
--- a/models/site.rb
+++ b/models/site.rb
@@ -453,9 +453,7 @@ class Site < Sequel::Model
# Check for existing email
email_check = self.class.select(:id).filter(email: values[:email]).first
- if email_check && email_check.id == self.id
- errors.add :email, 'You are already using this email address for this account.'
- elsif email_check && email_check.id != self.id
+ if email_check && email_check.id != self.id
errors.add :email, 'This email address already exists on Neocities, please use your existing account instead of creating a new one.'
end
@@ -602,7 +600,7 @@ class Site < Sequel::Model
end
def latest_events(current_page=1, limit=10)
- events_dataset.order(:created_at.desc).paginate(current_page, limit)
+ events_dataset.exclude(site_id: self.id).order(:created_at.desc).paginate(current_page, limit)
end
def news_feed(current_page=1, limit=10)
diff --git a/views/not_found.erb b/views/not_found.erb
index 8f461c4b..29ec9b89 100644
--- a/views/not_found.erb
+++ b/views/not_found.erb
@@ -17,7 +17,9 @@
<% if request.referer %>
- Go Back
+
<% end %>
\ No newline at end of file
diff --git a/views/settings.erb b/views/settings.erb
index 41889bc1..f0f997a8 100644
--- a/views/settings.erb
+++ b/views/settings.erb
@@ -69,8 +69,6 @@
-
-
Change Site (User) Name
+
+ Delete Site
+
+ If you want to delete your account, you can do that here. We're sorry to see you go, but we understand if Neocities isn't right for you. If there's any specific reason you're leaving, it would be great if you let us know so we can try to make your experience better in the future.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/views/site.erb b/views/site.erb
index 71535649..a3f5d78b 100644
--- a/views/site.erb
+++ b/views/site.erb
@@ -33,7 +33,7 @@
<% if current_site && current_site != site %>
<% is_following = current_site.is_following?(site) %>
-
+
<%= is_following ? 'Unfollow' : 'Follow' %>
@@ -83,6 +83,7 @@
You should update your site !
+ <%== erb :'_news', layout: false, locals: {site: @site, events: @latest_events} %>
<% end %>
<% else %>
From 19ad676df6607cf45d540fe33514ed8aad9b68cc Mon Sep 17 00:00:00 2001
From: Kyle Drake
Date: Thu, 14 Aug 2014 11:01:56 -0700
Subject: [PATCH 2/2] de-prioritize shooting yourself in the foot
---
app.rb | 4 +---
models/site.rb | 31 ++++++++++++++++++++++++++++++-
views/settings.erb | 3 ++-
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/app.rb b/app.rb
index 106c077f..1774496b 100644
--- a/app.rb
+++ b/app.rb
@@ -1154,11 +1154,9 @@ end
post '/site/delete' do
require_login
if current_site.username != params[:username]
- errors.add :username, 'Could not delete site, site name did not match.'
+ current_site.errors.add :username, 'Could not delete site, site name did not match.'
halt erb(:settings)
end
-
-
end
def require_admin
diff --git a/models/site.rb b/models/site.rb
index 39a00fed..5a1af946 100644
--- a/models/site.rb
+++ b/models/site.rb
@@ -209,16 +209,45 @@ class Site < Sequel::Model
File.read file_path(filename)
end
+ def before_destroy
+ raise 'not finished'
+ DB.transaction {
+ remove_all_tags
+ profile_comments.destroy
+ profile_commentings.destroy
+ follows.destroy
+ followings.destroy
+ #tips.destroy
+ #tippings.destroy
+ #blocks.destroy
+ #blockings.destroy
+ #reports.destroy
+ #reportings.destroy
+ #stats.destroy
+ #events.destroy
+ #site_changes.destroy
+ # TODO FIND THE REST, ASSOCIATE THEM PROPERLY!!!
+ }
+ end
+
+ def delete_site!
+ raise 'not finished'
+ DB.transaction {
+ destroy
+ FileUtils.mv files_path, File.join(PUBLIC_ROOT, 'deleted_sites', username)
+ }
+ end
+
def ban!
if username.nil? || username.empty?
raise 'username is missing'
end
DB.transaction {
- FileUtils.mv files_path, File.join(PUBLIC_ROOT, 'banned_sites', username)
self.is_banned = true
self.updated_at = Time.now
save(validate: false)
+ FileUtils.mv files_path, File.join(PUBLIC_ROOT, 'banned_sites', username)
}
site_files.file_list.collect {|f| f.filename}.each do |f|
diff --git a/views/settings.erb b/views/settings.erb
index f0f997a8..7cc57838 100644
--- a/views/settings.erb
+++ b/views/settings.erb
@@ -110,7 +110,7 @@
-
+