diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 877cc49e..198ae8b7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class UsersController < ApplicationController - before_action :find_user, only: [:edit, :update] + before_action :find_user, only: [:edit, :update, :destroy] before_action :ensure_unauthenticated, only: [:new, :create] # POST /u @@ -72,6 +72,15 @@ class UsersController < ApplicationController end end + # DELETE /u/:user_uid + def destroy + if current_user && current_user == @user + @user.destroy + session.delete(:user_id) + end + redirect_to root_path + end + # GET /u/terms def terms redirect_to root_path unless current_user diff --git a/app/models/user.rb b/app/models/user.rb index 88f253a3..4f1b31ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,8 @@ class User < ApplicationRecord after_create :initialize_main_room before_save { email.try(:downcase!) } + before_destroy :destroy_rooms + has_many :rooms belongs_to :main_room, class_name: 'Room', foreign_key: :room_id, required: false @@ -83,6 +85,11 @@ class User < ApplicationRecord private + # Destory a users rooms when they are removed. + def destroy_rooms + rooms.destroy_all + end + # Initializes a room for the user and assign a BigBlueButton user id. def initialize_main_room self.uid = "gl-#{(0...12).map { (65 + rand(26)).chr }.join.downcase}" diff --git a/app/views/shared/modals/_delete_account_modal.html.erb b/app/views/shared/modals/_delete_account_modal.html.erb new file mode 100644 index 00000000..90b60174 --- /dev/null +++ b/app/views/shared/modals/_delete_account_modal.html.erb @@ -0,0 +1,25 @@ +