diff --git a/app/controllers/profile/home_controller.rb b/app/controllers/profile/home_controller.rb deleted file mode 100644 index 6331cf2..0000000 --- a/app/controllers/profile/home_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Profile::HomeController < ApplicationController - before_action :authenticate_user! - - def index - end -end diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb new file mode 100644 index 0000000..8e62364 --- /dev/null +++ b/app/controllers/profile_controller.rb @@ -0,0 +1,27 @@ +class ProfileController < ApplicationController + before_action :authenticate_user! + + def edit + end + + def update_email + if current_user.valid_password?(params["current_password"]) && current_user.update(email: params["email"]) + flash[:notice] = I18n.translate("flashes.profile.update.success") + redirect_to profile_path + else + flash[:alert] = I18n.translate("flashes.profile.update.fail") + redirect_to profile_path + end + end + + def update_password + if !params["password"].blank? && current_user.valid_password?(params["current_password"]) && params["password"] == params["password_confirmation"] && current_user.update(password: params["password"]) + bypass_sign_in(current_user) + flash[:notice] = I18n.translate("flashes.profile.update.success") + redirect_to profile_path + else + flash[:alert] = I18n.translate("flashes.profile.update.fail") + redirect_to profile_path + end + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f33302e..7cec72b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,7 +19,7 @@
Find me in app/views/profile/home/index.html.erb
diff --git a/config/locales/en/fields.en.yml b/config/locales/en/fields.en.yml index 9ec575d..5a5e259 100644 --- a/config/locales/en/fields.en.yml +++ b/config/locales/en/fields.en.yml @@ -8,4 +8,11 @@ en: edit: "Edit" new: "New" name: "Name" - save: "Save" \ No newline at end of file + save: "Save" + email: "E-mail" + password: "Password" + current_password: "Current password" + update_email: "Update e-mail" + new_password: "New password" + new_password_confirmation: "Confirm the new password" + update_password: "Update password" \ No newline at end of file diff --git a/config/locales/en/flashes.en.yml b/config/locales/en/flashes.en.yml index a5188fd..074cc82 100644 --- a/config/locales/en/flashes.en.yml +++ b/config/locales/en/flashes.en.yml @@ -9,4 +9,8 @@ en: fail: "Count creation failed." destroy: fail: "Count deletion has failed." - success: "Count has been deleted successfully." \ No newline at end of file + success: "Count has been deleted successfully." + profile: + update: + success: "Profile updated successfully." + fail: "Updating the profile failed." \ No newline at end of file diff --git a/config/locales/fr/fields.fr.yml b/config/locales/fr/fields.fr.yml index 0e46a0d..39c2f6c 100644 --- a/config/locales/fr/fields.fr.yml +++ b/config/locales/fr/fields.fr.yml @@ -9,3 +9,10 @@ fr: new: "Nouveau" name: "Nom" save: "Sauvegarder" + email: "Courriel" + password: "Mot de passe" + current_password: "Mot de passe actuel" + update_email: "Mettre à jour le courriel" + new_password: "Nouveau mot de passe" + new_password_confirmation: "Confirmez le nouveau mot de passe" + update_password: "Mettre à jour de mot de passe" diff --git a/config/locales/fr/flashes.fr.yml b/config/locales/fr/flashes.fr.yml index 1193b3c..13c195c 100644 --- a/config/locales/fr/flashes.fr.yml +++ b/config/locales/fr/flashes.fr.yml @@ -9,4 +9,8 @@ fr: fail: "La création du compte a échoué." destroy: fail: "La suppression du compte a échoué." - success: "Le compte a été supprimé avec succès." \ No newline at end of file + success: "Le compte a été supprimé avec succès." + profile: + update: + success: "Le profil a bien été mis à jour." + fail: "La mise à jour du profil a échoué." \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cb94004..6d30f9e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,11 @@ Rails.application.routes.draw do - namespace :profile do - root "home#index" - end - resources :count, except: [:show] + get "profile", to: "profile#edit" + post "profile/update_email", to: "profile#update_email" + post "profile/update_password", to: "profile#update_password" + root "home#index" devise_for :users, controllers: {