Skip to content

Commit 1e33f24

Browse files
committedJan 19, 2016
enabled user deletes again
1 parent 38d1b87 commit 1e33f24

File tree

8 files changed

+46
-6
lines changed

8 files changed

+46
-6
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ BACKUP
6060
Guardfile
6161
verification.log
6262
npm-debug.log
63+
dump.rdb

‎app/controllers/sessions_controller.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ def signin
1717
# GET /sessions/force(.:format)
1818
def force
1919
#REMOVEME
20-
head(:forbidden) unless current_user.admin?
20+
head(:forbidden) unless Rails.env.development? || current_user.admin?
2121
sign_out
22-
sign_in(User.find(params[:id]))
22+
user = params[:id].present? ? User.find(params[:id]) : User.find_by_username(params[:username])
23+
sign_in(user)
2324
redirect_to(root_url)
2425
end
2526

‎app/controllers/users_controller.rb

+20
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ def create
9494
end
9595
end
9696

97+
def delete_account
98+
return head(:forbidden) unless signed_in?
99+
end
100+
101+
def delete_account_confirmed
102+
user = User.find(current_user.id)
103+
user.destroy
104+
sign_out
105+
redirect_to root_url
106+
end
107+
108+
def destroy
109+
destroy_params = params.permit(:id)
110+
return head(:forbidden) unless current_user.admin? || current_user.id == destroy_params[:id]
111+
112+
@user = User.find(destroy_params[:id])
113+
@user.destroy
114+
redirect_to badge_url(@user.username)
115+
end
116+
97117
# GET /settings(.:format)
98118
def edit
99119
respond_to do |format|

‎app/models/user.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ class User < ActiveRecord::Base
180180

181181
has_many :badges, order: 'created_at DESC'
182182
has_many :followed_teams
183-
has_many :user_events
183+
has_many :user_events, dependent: :destroy
184184
has_many :skills, order: "weight DESC"
185185
has_many :endorsements, foreign_key: 'endorsed_user_id'
186186
has_many :endorsings, foreign_key: 'endorsing_user_id', class_name: 'Endorsement'
187187
has_many :protips, dependent: :destroy
188188
has_many :likes
189-
has_many :comments
189+
has_many :comments, dependent: :destroy
190190

191191
has_one :github_profile , class_name: 'Users::Github::Profile', dependent: :destroy
192192
has_many :github_repositories, through: :github_profile , source: :repositories

‎app/views/users/_show_admin_panel.slim

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
=link_to("Unban this user", user_unbans_path(user), method: :post)
1616
- else
1717
=link_to("Ban this user", user_bans_path(user), method: :post)
18+
19+
li.admin-action= link_to('Delete User', user_path(user), :confirm => 'Are you sure?', :method => :delete)
20+
li.admin-action= link_to_if(user.twitter,'Clear Twitter!', clear_provider_path(user, :provider => 'twitter'), :confirm => 'Are you sure?')
1821
li.admin-action= link_to_if(user.twitter,'Clear Twitter!', clear_provider_path(user, :provider => 'twitter'), :confirm => 'Are you sure?')
1922
li.admin-action= link_to_if(user.github,'Clear GitHub!', clear_provider_path(user, :provider => 'github'), :confirm => 'Are you sure?')
2023
-if user.linkedin || user.linkedin_id
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=content_for :body_id do
2+
member-settings
3+
4+
#lflf
5+
%h1.big-title Remove Your Account
6+
.panel.cf
7+
.inside-panel-align-left
8+
#social_section.editsection
9+
%p Warning: clicking this link below will permenatly delete your Coderwall account and its data.
10+
.left
11+
.setting
12+
=form_tag delete_account_confirmed_path do |form|
13+
.save=submit_tag 'Delete your account & sign out', :class => 'button', :confirm => "This is the point of no return. Are you sure you want to delete your account?"

‎app/views/users/edit/_basic.html.slim

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
.delete
6161
p
6262
|Deleting your account is permanent and will make your username available to someone else. If you would still like to delete your account,
63-
= link_to " click here.", "/delete_account"
63+
= link_to " click here.", user_path(user), :confirm => 'Are you sure?', :method => :delete
64+
6465
.row
6566
.input-field.col.s12.m6
6667
.input-field.col.s12.m6
6768
.save =submit_tag 'Save', class: 'btn right'
68-

‎config/routes.rb

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@
319319
get '/settings' => 'users#edit', as: :settings
320320
get '/unsubscribe' => 'emails#unsubscribe'
321321
get '/delivered' => 'emails#delivered'
322+
get '/delete_account' => 'users#delete_account', as: :delete_account
323+
post '/delete_account_confirmed' => 'users#delete_account_confirmed', as: :delete_account_confirmed
322324

323325
resources :authentications, :usernames
324326
resources :invitations

0 commit comments

Comments
 (0)
Please sign in to comment.