feat: added possibility to edit your password and your email on your profile
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
86f5e7d088
commit
09c9feeeef
@ -1,6 +0,0 @@
|
|||||||
class Profile::HomeController < ApplicationController
|
|
||||||
before_action :authenticate_user!
|
|
||||||
|
|
||||||
def index
|
|
||||||
end
|
|
||||||
end
|
|
27
app/controllers/profile_controller.rb
Normal file
27
app/controllers/profile_controller.rb
Normal file
@ -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
|
@ -19,7 +19,7 @@
|
|||||||
<li><%= link_to t("fields.home"), root_path, class: "nav-link px-2 #{current_page?(root_path) ? "text-secondary" : "text-white"}" %></li>
|
<li><%= link_to t("fields.home"), root_path, class: "nav-link px-2 #{current_page?(root_path) ? "text-secondary" : "text-white"}" %></li>
|
||||||
<% if current_user %>
|
<% if current_user %>
|
||||||
<li><%= link_to t("fields.count"), count_index_path, class: "nav-link px-2 #{current_page?(count_index_path) ? "text-secondary" : "text-white"}" %></li>
|
<li><%= link_to t("fields.count"), count_index_path, class: "nav-link px-2 #{current_page?(count_index_path) ? "text-secondary" : "text-white"}" %></li>
|
||||||
<li><%= link_to t("fields.profile"), profile_root_path, class: "nav-link px-2 #{current_page?(profile_root_path) ? "text-secondary" : "text-white"}" %></li>
|
<li><%= link_to t("fields.profile"), profile_path, class: "nav-link px-2 #{current_page?(profile_path) ? "text-secondary" : "text-white"}" %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
46
app/views/profile/edit.html.erb
Normal file
46
app/views/profile/edit.html.erb
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<div class="mt-2 mb-4">
|
||||||
|
|
||||||
|
<div class="mt-2 mb-4">
|
||||||
|
<h3><%= t("fields.update_email") %></h3>
|
||||||
|
<%= form_tag profile_update_email_path, method: :post do %>
|
||||||
|
<div class="col-2 mt-2">
|
||||||
|
<%= label_tag :email, t("fields.email") %>
|
||||||
|
<%= email_field_tag :email, current_user.email, class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-2 mt-2">
|
||||||
|
<%= label_tag :current_password, t("fields.current_password") %>
|
||||||
|
<%= password_field_tag :current_password, nil, class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= submit_tag t("fields.save"), class: "btn btn-primary mt-2" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2 mb-4">
|
||||||
|
<h3><%= t("fields.update_password") %></h3>
|
||||||
|
<%= form_tag profile_update_password_path, method: :post do %>
|
||||||
|
<div class="col-2 mt-2">
|
||||||
|
<%= label_tag :email, t("fields.email") %>
|
||||||
|
<%= email_field_tag :email, current_user.email, class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-2 mt-2">
|
||||||
|
<%= label_tag :password, t("fields.new_password") %>
|
||||||
|
<%= password_field_tag :password, nil, class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-2 mt-2">
|
||||||
|
<%= label_tag :password_confirmation, t("fields.new_password_confirmation") %>
|
||||||
|
<%= password_field_tag :password_confirmation, nil, class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-2 mt-2">
|
||||||
|
<%= label_tag :current_password, t("fields.current_password") %>
|
||||||
|
<%= password_field_tag :current_password, nil, class: "form-control" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= submit_tag t("fields.save"), class: "btn btn-primary mt-2" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -1,2 +0,0 @@
|
|||||||
<h1>Profile::Home#index</h1>
|
|
||||||
<p>Find me in app/views/profile/home/index.html.erb</p>
|
|
@ -8,4 +8,11 @@ en:
|
|||||||
edit: "Edit"
|
edit: "Edit"
|
||||||
new: "New"
|
new: "New"
|
||||||
name: "Name"
|
name: "Name"
|
||||||
save: "Save"
|
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"
|
@ -9,4 +9,8 @@ en:
|
|||||||
fail: "Count creation failed."
|
fail: "Count creation failed."
|
||||||
destroy:
|
destroy:
|
||||||
fail: "Count deletion has failed."
|
fail: "Count deletion has failed."
|
||||||
success: "Count has been deleted successfully."
|
success: "Count has been deleted successfully."
|
||||||
|
profile:
|
||||||
|
update:
|
||||||
|
success: "Profile updated successfully."
|
||||||
|
fail: "Updating the profile failed."
|
@ -9,3 +9,10 @@ fr:
|
|||||||
new: "Nouveau"
|
new: "Nouveau"
|
||||||
name: "Nom"
|
name: "Nom"
|
||||||
save: "Sauvegarder"
|
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"
|
||||||
|
@ -9,4 +9,8 @@ fr:
|
|||||||
fail: "La création du compte a échoué."
|
fail: "La création du compte a échoué."
|
||||||
destroy:
|
destroy:
|
||||||
fail: "La suppression du compte a échoué."
|
fail: "La suppression du compte a échoué."
|
||||||
success: "Le compte a été supprimé avec succès."
|
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é."
|
@ -1,11 +1,11 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
namespace :profile do
|
|
||||||
root "home#index"
|
|
||||||
end
|
|
||||||
|
|
||||||
resources :count, except: [:show]
|
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"
|
root "home#index"
|
||||||
|
|
||||||
devise_for :users, controllers: {
|
devise_for :users, controllers: {
|
||||||
|
Loading…
Reference in New Issue
Block a user