mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-22 05:50:47 +02:00
Allow the user to delete their own account
This commit is contained in:
parent
f8cf140bf4
commit
46b8d3ce9f
7 changed files with 43 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
|
|
||||||
before_action :admin_login_required, :only => [ :index, :show, :destroy ]
|
before_action :admin_login_required, :only => [ :index, :show ]
|
||||||
skip_before_action :login_required, :only => [ :new, :create ]
|
skip_before_action :login_required, :only => [ :new, :create ]
|
||||||
prepend_before_action :login_optional, :only => [ :new, :create ]
|
prepend_before_action :login_optional, :only => [ :new, :create ]
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
format.xml do
|
format.xml do
|
||||||
unless current_user && current_user.is_admin
|
unless current_user && current_user.is_admin
|
||||||
render :body => "401 Unauthorized: Only admin users are allowed access to this function.", :status => 401
|
render :body => t('errors.user_unauthorized'), :status => 401
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
unless check_create_user_params
|
unless check_create_user_params
|
||||||
|
@ -131,7 +131,15 @@ class UsersController < ApplicationController
|
||||||
# DELETE /users/id DELETE /users/id.xml
|
# DELETE /users/id DELETE /users/id.xml
|
||||||
def destroy
|
def destroy
|
||||||
@deleted_user = User.find(params[:id])
|
@deleted_user = User.find(params[:id])
|
||||||
|
unless current_user && (current_user.is_admin || current_user == @deleted_user)
|
||||||
|
render :body => t('errors.user_unauthorized'), :status => 401
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@saved = @deleted_user.destroy
|
@saved = @deleted_user.destroy
|
||||||
|
if current_user == @deleted_user
|
||||||
|
logout_user
|
||||||
|
end
|
||||||
@total_users = User.count
|
@total_users = User.count
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -141,10 +149,16 @@ class UsersController < ApplicationController
|
||||||
else
|
else
|
||||||
notify :error, t('users.failed_to_delete_user', :username => @deleted_user.login)
|
notify :error, t('users.failed_to_delete_user', :username => @deleted_user.login)
|
||||||
end
|
end
|
||||||
redirect_to users_url
|
if current_user == @deleted_user
|
||||||
|
redirect_to login
|
||||||
|
else
|
||||||
|
redirect_to users_url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
format.js
|
format.js
|
||||||
format.xml { head :ok }
|
format.xml do
|
||||||
|
head :ok
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,4 +18,14 @@ module PreferencesHelper
|
||||||
pref(model, pref_name) { text_field(model, pref_name, class: "form-control") }
|
pref(model, pref_name) { text_field(model, pref_name, class: "form-control") }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def profile_delete_user(user)
|
||||||
|
return link_to(
|
||||||
|
t('users.destroy_user'),
|
||||||
|
url_for({:controller => 'users', :action => 'destroy', :id => user.id}),
|
||||||
|
{:id => "delete_user_#{user.id}",
|
||||||
|
:class => "delete_user_button btn btn-danger",
|
||||||
|
:title => t('users.destroy_user'),
|
||||||
|
:x_confirm_message => t('users.destroy_confirmation', :login => user.login)
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
4
app/views/preferences/_remove_account.html.erb
Normal file
4
app/views/preferences/_remove_account.html.erb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<p><%= t 'preferences.remove_introduction' %></p>
|
||||||
|
<div class="form-group">
|
||||||
|
<%= profile_delete_user(@user) %>
|
||||||
|
</div>
|
|
@ -21,16 +21,20 @@
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<%= link_to t('preferences.tabs.tracks_behavior'), "#behavior", data: { toggle: "tab" } %>
|
<%= link_to t('preferences.tabs.tracks_behavior'), "#behavior", data: { toggle: "tab" } %>
|
||||||
</li>
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<%= link_to t('preferences.tabs.remove_account'), "#remove_account", data: { toggle: "tab" } %>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div role="tabpanel" class="tab-pane active" id="profile"><%= render :partial => 'profile'%></div>
|
<div role="tabpanel" class="tab-pane active" id="profile"><%= render :partial => 'profile'%></div>
|
||||||
<div role="tabpanel" class="tab-pane" id="authentication"><%= render :partial => 'authentication'%></div>
|
<div role="tabpanel" class="tab-pane" id="authentication"><%= render :partial => 'authentication'%></div>
|
||||||
<div role="tabpanel" class="tab-pane" id="date_and_time"><%= render :partial => 'date_and_time'%></div>
|
<div role="tabpanel" class="tab-pane" id="date_and_time"><%= render :partial => 'date_and_time'%></div>
|
||||||
<div role="tabpanel" class="tab-pane" id="behavior"><%= render :partial => 'tracks_behavior'%></div>
|
<div role="tabpanel" class="tab-pane" id="behavior"><%= render :partial => 'tracks_behavior'%></div>
|
||||||
|
<div role="tabpanel" class="tab-pane" id="remove_account"><%= render :partial => 'remove_account'%></div>
|
||||||
|
</div>
|
||||||
|
<div class="btn-group" role="group" aria-label="Basic example">
|
||||||
|
<button type="submit" id="prefs_submit" class="btn btn-default"><%= t('common.update') %></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" id="prefs_submit" class="btn btn-default"><%= t('common.update') %></button>
|
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -821,11 +821,13 @@ en:
|
||||||
authentication_header: Your authentication
|
authentication_header: Your authentication
|
||||||
current_authentication_type: Your authentication type is %{auth_type}
|
current_authentication_type: Your authentication type is %{auth_type}
|
||||||
change_authentication_type: Change your authentication type
|
change_authentication_type: Change your authentication type
|
||||||
|
remove_introduction: You can remove your user account here. Note that this is irreversible and will remove all your data! After removal you will be logged out.
|
||||||
tabs:
|
tabs:
|
||||||
authentication: Authentication
|
authentication: Authentication
|
||||||
tracks_behavior: Tracks behavior
|
tracks_behavior: Tracks behavior
|
||||||
profile: Profile
|
profile: Profile
|
||||||
date_and_time: Date and time
|
date_and_time: Date and time
|
||||||
|
remove_account: Remove account
|
||||||
generate_new_token_confirm: Are you sure? Generating a new token will replace the existing one and break any external usages of this token.
|
generate_new_token_confirm: Are you sure? Generating a new token will replace the existing one and break any external usages of this token.
|
||||||
data:
|
data:
|
||||||
import_successful: Import was successful.
|
import_successful: Import was successful.
|
||||||
|
|
|
@ -106,7 +106,7 @@ Rails.application.routes.draw do
|
||||||
# This means the controller action needs to parse the extension and set format/content type
|
# This means the controller action needs to parse the extension and set format/content type
|
||||||
# Needed for /todos/tag/first.last.m to work
|
# Needed for /todos/tag/first.last.m to work
|
||||||
get 'todos/tag/:name' => 'todos#tag', :as => :tag, :format => false, :name => /.*/
|
get 'todos/tag/:name' => 'todos#tag', :as => :tag, :format => false, :name => /.*/
|
||||||
|
|
||||||
get 'attachments/:id/:filename' => "todos#attachment"
|
get 'attachments/:id/:filename' => "todos#attachment"
|
||||||
get 'tags.autocomplete' => "todos#tags", :format => 'autocomplete'
|
get 'tags.autocomplete' => "todos#tags", :format => 'autocomplete'
|
||||||
get 'todos/done/tag/:name' => "todos#done_tag", :as => :done_tag
|
get 'todos/done/tag/:name' => "todos#done_tag", :as => :done_tag
|
||||||
|
|
|
@ -222,6 +222,7 @@ private
|
||||||
def redirect_to_login
|
def redirect_to_login
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to login_path }
|
format.html { redirect_to login_path }
|
||||||
|
format.js { render js: "redirect_to('" + login_path + "')" }
|
||||||
format.m { redirect_to login_path(:format => 'm') }
|
format.m { redirect_to login_path(:format => 'm') }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue