devise-multi_email 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d9dc3a93e09984b89cf88cb94b4bb158ca942dd
4
- data.tar.gz: d298b22cd393f35811e02dcc011ec90874ed8e8e
3
+ metadata.gz: a2b9c44fd5e0d7e67068e283c110c3d5bcf2578d
4
+ data.tar.gz: 6c6101cc82b5f18131fb3a44383953424ad4c433
5
5
  SHA512:
6
- metadata.gz: 5a052c760a050ab2cf8a10102a7d9817f098e5c212d9279fa0c7163497919b220e8d8b89d10da402e8ddbc83afb9e2a8efe99af57c20c7391f23c39c91383a4e
7
- data.tar.gz: b8a2b9620fb3d23d38c0985f57f965abce55146522a0bd2d7198e250f3896b9abf89bfec6548661aaea139bddc96fef9ab247bf0348a2f59944ba8ec4ec6f3ac
6
+ metadata.gz: 77aae6065dcb2ce816df78945ea39addbb4c3550f80252ad5048ea81fbd38f7360ec92678574a554a54591c4c1fac9eee23433935145a1fe2ee2e4e37d563e08
7
+ data.tar.gz: ef10791a3e1818069f8138373eb11fb277e63f4fbdaa5c40ed451f9c9bf1a6ea4b756762a94024499aa6389f742fa54ba23084cb31256421819a4f80b463bf0d
@@ -0,0 +1,6 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.start do
5
+ add_filter 'spec/'
6
+ end
data/Gemfile CHANGED
@@ -9,4 +9,6 @@ group :development, :test do
9
9
  gem 'rspec', '~> 3'
10
10
  gem 'sqlite3'
11
11
  gem 'capybara'
12
+ gem 'coveralls', require: false
12
13
  end
14
+
data/README.md CHANGED
@@ -1,28 +1,106 @@
1
- # Devise::MultiEmail [![Build Status](https://travis-ci.org/allenwq/devise-multi_email.svg?branch=master)](https://travis-ci.org/allenwq/devise-multi_email)
1
+ # Devise::MultiEmail [![Build Status](https://travis-ci.org/allenwq/devise-multi_email.svg?branch=master)](https://travis-ci.org/allenwq/devise-multi_email) [![Coverage Status](https://coveralls.io/repos/allenwq/devise-multi_email/badge.svg?branch=master&service=github)](https://coveralls.io/github/allenwq/devise-multi_email?branch=master)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/devise/multi_email`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Let [devise](https://github.com/plataformatec/devise) support multilpe emails, it allows you to:
4
+ - Login with multiple emails
5
+ - Send confirmations to multiple emails
6
+ - Recover the password with any of the emails
7
+ - Validations for multiple emails
4
8
 
5
- TODO: Delete this and the text above, and describe your gem
9
+ `:multi_email_authenticatable`, `:multi_email_confirmable` and `:multi_email_validatable` are provided by devise-multi_email.
6
10
 
7
- ## Installation
11
+ ## Getting Started
8
12
 
9
- Add this line to your application's Gemfile:
13
+ Add this line to your application's Gemfile, devise-multi_email has been tested with devise 4.0 and rails 4.2:
10
14
 
11
15
  ```ruby
12
16
  gem 'devise-multi_email'
13
17
  ```
14
18
 
15
- And then execute:
19
+ Suppose you have already setup devise, your `User` model might look like this:
16
20
 
17
- $ bundle
21
+ ```ruby
22
+ class User < ActiveRecord::Base
23
+ devise :database_authenticatable, :registerable
24
+ end
25
+ ```
26
+
27
+ In order to let your `User` support multiple emails, with `devise-multi_email` what you need to do is just:
28
+
29
+ ```ruby
30
+ class User < ActiveRecord::Base
31
+ has_many :emails
32
+
33
+ # Replace :database_authenticatable, with :multi_email_authenticatable
34
+ devise :multi_email_authenticatable, :registerable
35
+ end
36
+
37
+ class Email < ActiveRecord::Base
38
+ belongs_to :user
39
+ end
40
+ ```
41
+
42
+ Note that `:email` column should be moved from users table to the emails table, and a new `primary` boolean column should be added to the emails table (so that all the emails will be sent to the primary email, and `user.email` will give you the primary email address). Your emails table's migration should look like:
43
+ ```ruby
44
+ create_table :emails do |t|
45
+ t.integer :user_id
46
+ t.string :email
47
+ t.boolean :primary
48
+ end
49
+ ```
18
50
 
19
- Or install it yourself as:
51
+ ## Confirmable with multiple emails
52
+ Sending different confirmaitons to different emails is supported. What you need to do is:
20
53
 
21
- $ gem install devise-multi_email
54
+ Declare `devise :multi_email_confirmable` in your `User` model:
55
+ ```ruby
56
+ class User < ActiveRecord::Base
57
+ has_many :emails
58
+
59
+ # You should not declare :confiramble and :multi_email_confirmable at the same time.
60
+ devise :multi_email_authenticatable, :registerable, :multi_email_confirmable
61
+ end
62
+ ```
63
+
64
+ Add `:confirmation_token`, `:confirmed_at` and `:confirmation_sent_at` to your emails table:
65
+ ```ruby
66
+ create_table :emails do |t|
67
+ t.integer :user_id
68
+ t.string :email
69
+ t.boolean :primary, default: false
70
+
71
+ ## Confirmable
72
+ t.string :confirmation_token
73
+ t.datetime :confirmed_at
74
+ t.datetime :confirmation_sent_at
75
+ end
76
+ ```
77
+
78
+ Then all the methods in devise confirmable are avalible in your `Email` model. You can do `Email#send_confirmation_instructions` for each of your email. And `User#send_confirmation_instructions` will be delegated to the primary email.
79
+
80
+ ## Validatable with multiple emails
81
+ Declare `devise :multi_email_validatable` in the user model, then all the user emails will be validated:
82
+
83
+ ```ruby
84
+ class User < ActiveRecord::Base
85
+ has_many :emails
86
+
87
+ # You should not declare :validatable and :multi_email_validatable at the same time.
88
+ devise :multi_email_authenticatable, :registerable, :multi_email_validatable
89
+ end
90
+ ```
91
+
92
+ ## What's more
93
+
94
+ The gem works with all other devise modules just as normal, you don't need to add the `multi_email` prefix.
95
+ ```ruby
96
+ devise :multi_email_authenticatable, :multi_email_confirmable, :multi_email_validatable, :lockable,
97
+ :recoverable, :registerable, :rememberable, :timeoutable, :trackable
98
+ ```
22
99
 
23
- ## Usage
100
+ ## Issues
101
+ You need to implement add/delete emails for a user as well as set/unset primary email.
24
102
 
25
- TODO: Write usage instructions here
103
+ You can do `email.send_confirmation_instructions` for every email, but you also need to handle this logic in some place(excpet for the primary email). e.g. After a new email was added by a user, you might want to provide some buttons to allow user to resend confirmation instrucitons for that email.
26
104
 
27
105
  ## Development
28
106
 
@@ -33,17 +33,8 @@ module Devise
33
33
 
34
34
  module InstanceReplacementMethods
35
35
  delegate :skip_confirmation!, :skip_confirmation_notification!, :skip_reconfirmation!, :confirmation_required?,
36
- :confirmation_token, :confirmed_at, :confirmation_sent_at, :confirm, :confirmed?,
37
- :reconfirmation_required?, to: :primary_email_record
38
-
39
- def unconfirmed_email
40
- primary_email_record.try(:unconfirmed_email)
41
- end
42
-
43
- def pending_reconfirmation?
44
- primary_email = primary_email_record
45
- primary_email && primary_email.pending_reconfirmation?
46
- end
36
+ :confirmation_token, :confirmed_at, :confirmation_sent_at, :confirm, :confirmed?, :unconfirmed_email,
37
+ :reconfirmation_required?, :pending_reconfirmation?, to: :primary_email_record, allow_nil: true
47
38
 
48
39
  # This need to be forwarded to the email that the user logged in with
49
40
  def active_for_authentication?
@@ -25,6 +25,7 @@ module Devise
25
25
 
26
26
  included do
27
27
  devise :validatable
28
+ validates Devise::Models::MultiEmailAuthenticatable::EMAILS_ASSOCIATION, presence: true
28
29
 
29
30
  after_validation :propagate_email_errors
30
31
  email_class.send :include, EmailValidatable
@@ -41,7 +42,12 @@ module Devise
41
42
  end
42
43
 
43
44
  def propagate_email_errors
44
- return if (email_errors = errors.delete(self.class::EMAILS_ASSOCIATION)).nil?
45
+ email_error_key = self.class::EMAILS_ASSOCIATION
46
+ if respond_to?("#{self.class::EMAILS_ASSOCIATION}_attributes=")
47
+ email_error_key = "#{email_error_key}.email".to_sym
48
+ end
49
+
50
+ return if (email_errors = errors.delete(email_error_key)).nil?
45
51
 
46
52
  email_errors.each do |error|
47
53
  errors.add(:email, error)
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module MultiEmail
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise-multi_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ALLEN WANG QIANG
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-11 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
+ - ".simplecov"
64
65
  - ".travis.yml"
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Gemfile