diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/auth/passwords_controller.rb similarity index 94% rename from app/controllers/users/passwords_controller.rb rename to app/controllers/auth/passwords_controller.rb index 6517b6581..0f6e1c9b0 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/auth/passwords_controller.rb @@ -1,4 +1,4 @@ -class Users::PasswordsController < Devise::PasswordsController +class Auth::PasswordsController < Devise::PasswordsController include Helpers::Email def reset_confirmation diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb similarity index 90% rename from app/controllers/users/sessions_controller.rb rename to app/controllers/auth/sessions_controller.rb index f81f8fb05..a117aecff 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -1,4 +1,4 @@ -class Users::SessionsController < Devise::SessionsController +class Auth::SessionsController < Devise::SessionsController include Helpers::Email def create diff --git a/app/controllers/users/account_controller.rb b/app/controllers/users/account_controller.rb deleted file mode 100644 index f696d3ae7..000000000 --- a/app/controllers/users/account_controller.rb +++ /dev/null @@ -1,27 +0,0 @@ -class Users::AccountController < ApplicationController - def index - check_logged_in - end - - def edit - check_logged_in - end - - def update - if current_user.update(user_params) - redirect_to(users_account_path) - end - end - -private - - def check_logged_in - if current_user.nil? - redirect_to(new_user_session_path) - end - end - - def user_params - params.require(:user).permit(:email, :name, :password) - end -end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb deleted file mode 100644 index 2c3775488..000000000 --- a/app/controllers/users/registrations_controller.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Users::RegistrationsController < Devise::RegistrationsController - skip_before_action :require_no_authentication - - def new - self.resource = resource_class.new - respond_with resource - end - -protected - - def after_update_path_for(_resource) - users_account_path - end -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 000000000..6435a03d8 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,23 @@ +class UsersController < ApplicationController + before_action :authenticate_user! + + def update + if current_user.update(user_params) + redirect_to(user_path) + end + end + + def new + @resource = User.new + end + + def create + User.create!(user_params) + end + +private + + def user_params + params.require(:user).permit(:email, :name, :password) + end +end diff --git a/app/models/user.rb b/app/models/user.rb index cd129255c..81d3d2d9c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,7 @@ class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :recoverable, :rememberable, :validatable, - :trackable, :registerable + :trackable belongs_to :organisation has_many :owned_case_logs, through: :organisation diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index be85834c2..abbd8b4b5 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -1,18 +1,26 @@ -<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> +<% content_for :before_content do %> + <%= govuk_back_link( + text: 'Back', + href: :back, + ) %> +<% end %> + +<%= form_for(current_user, as: :user, url: account_update_path(), html: { method: :patch }) do |f| %>