Skip to content

Commit 0374607

Browse files
committed
enabled account deletion
1 parent 0d26dba commit 0374607

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

README.rdoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
* TODO: Getting avatars/uploads/cdn to work
44
* TODO: Dragging files into protip editor https://github.com/feross/drag-drop
5-
* TODO: Getting Likes / Hearts to work
65
* TODO: Check all meta tags, especially on pro tips so SEO is retained
76
* TODO: Fix commenting formatting issue (see: http://localhost:5000/p/lhsrcq/one-line-browser-notepad)
87
* TODO: Write announcement protip and link it on homepage

app/controllers/users_controller.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class UsersController < ApplicationController
44
def show
55
if params[:username] == 'random'
66
@user = User.order("random()").first
7+
elsif params[:delete_account]
8+
@user = current_user
79
else
810
@user = User.find_by_username(params[:username])
911
end
@@ -48,6 +50,19 @@ def impersonate
4850
end
4951
end
5052

53+
def destroy
54+
@user = User.find(params[:id])
55+
head(:forbidden) unless current_user.can_edit?(@user)
56+
@user.destroy
57+
if @user == current_user
58+
sign_out
59+
flash[:notice] = "You are no longer signed in to Coderwall. Your acccount, #{@user.username}, has been deleted."
60+
else
61+
flash[:notice] = "#{@user.username}'s account deleted."
62+
end
63+
redirect_to(root_url)
64+
end
65+
5166
protected
5267

5368
def new_user_params

app/views/layouts/application.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
%a.btn.active-text.mr2{:href => sign_in_path} Log In
3434
%a.btn.btn-primary{:href => sign_up_path} Sign Up
3535
%main.flex-auto.px3.py3
36+
-if flash[:notice].present?
37+
.clearfix.rounded.py2.mb2.white.bg-navy.bold.center.font-lg=flash[:notice]
3638
=yield
3739
%footer.border-top
3840
%nav.clearfix

app/views/users/show.html.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
-if current_user == @user || current_user.try(:admin?)
2121
.clearfix.mb3
2222
.right
23+
-if current_user.try(:admin?)
24+
.inline.diminish.mr1=@user.email
25+
.inline.diminish.mr1="accessed #{time_ago_in_words(@user.last_request_at)}"
26+
-if current_user.try(:admin?) || params[:delete_account]
27+
=link_to(icon('trash'), user_path(@user), method: :delete, class: 'diminish mr1', 'data-confirm': 'This makes us very sad. Are you sure?')
2328
=link_to('Sign out', sign_out_path, method: :delete, class: 'diminish')
2429
%a.ml1.btn.btn.bg-green.white{href: edit_user_path(@user)}
2530
Edit Profile

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
get '/500' => "pages#show", page: 'server_error'
1717
get '/helloworld' => "users#edit", finish_signup: true, as: :finish_signup
1818
get '/styleguide' => "pages#show", page: 'styleguide'
19+
get '/delete_account' => 'users#show', delete_account: true
1920

2021
resources :passwords, controller: "clearance/passwords", only: [:create, :new]
2122
resource :session, controller: "clearance/sessions", only: [:create]

0 commit comments

Comments
 (0)