-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
130 - support user with multiple emails
- Loading branch information
Showing
37 changed files
with
702 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ruby 3.3.5 | ||
nodejs 22.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class My::EmailsController < My::ApplicationController | ||
def new | ||
@email = current_user.emails.new | ||
end | ||
|
||
def create | ||
@email = current_user.emails.new(email_params) | ||
if @email.save | ||
redirect_to my_details_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def set_primary | ||
email = Email.find(params[:id]) | ||
ActiveRecord::Base.transaction do | ||
current_user.emails.where(primary: true).update_all(primary: false) | ||
email.update!(primary: true) | ||
end | ||
|
||
flash[:notice] = "Your primary email has been ukpdated to #{email.email}" | ||
redirect_to my_details_path | ||
end | ||
|
||
def destroy | ||
email = Email.find(params[:id]) | ||
if email.destroy | ||
flash[:notice] = "Your email #{email.email} have been deleted." | ||
else | ||
flash[:error] = "Your email #{email.email} is failed to be deleted." | ||
end | ||
|
||
redirect_to my_details_path | ||
end | ||
|
||
private | ||
|
||
def email_params | ||
params.require(:email).permit(:email) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Email < ActiveRecord::Base | ||
belongs_to :user | ||
|
||
validates :email, presence: true, uniqueness: true | ||
|
||
after_save :trigger_after_confirmation, if: :saved_change_to_confirmed_at? | ||
|
||
delegate :full_name, :address, to: :user | ||
|
||
private | ||
|
||
def send_devise_notification(notification, *args) | ||
devise_mailer.send(notification, self, *args).deliver_now | ||
end | ||
|
||
def trigger_after_confirmation | ||
email_update = saved_change_to_email? && email_before_last_save.present? | ||
user.update_mailing_list_and_memberships(email_update: email_update) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<%= content_for :heading do %> | ||
Add New Email | ||
<% end %> | ||
|
||
<h2>Add New Email</h2> | ||
|
||
<%= form_for @email, url: my_emails_path, html: { class: 'standard' } do |form| %> | ||
<% if @email.errors.any? %> | ||
<div id="error_explanation" class="ui visible error message"> | ||
<h2><%= pluralize(@email.errors.count, "error") %> prohibited this from being saved:</h2> | ||
|
||
<ul> | ||
<% @email.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<div class="label"> | ||
<%= form.label :email, class: 'required' %> | ||
</div> | ||
<div class="input"> | ||
<%= form.email_field :email, type: 'email' %> | ||
</div> | ||
</div> | ||
|
||
<div class="buttons"> | ||
<%= form.submit 'Add New Email', class: 'btn btn-primary' %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateEmails < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :emails do |t| | ||
t.references :user, foreign_key: true | ||
t.string :email, null: false, index: { unique: true } | ||
t.boolean :primary, default: false, null: false | ||
|
||
## Confirmable | ||
t.string :unconfirmed_email | ||
t.string :confirmation_token | ||
t.datetime :confirmed_at | ||
t.datetime :confirmation_sent_at | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.