devise-multi_email 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d9dc3a93e09984b89cf88cb94b4bb158ca942dd
4
+ data.tar.gz: d298b22cd393f35811e02dcc011ec90874ed8e8e
5
+ SHA512:
6
+ metadata.gz: 5a052c760a050ab2cf8a10102a7d9817f098e5c212d9279fa0c7163497919b220e8d8b89d10da402e8ddbc83afb9e2a8efe99af57c20c7391f23c39c91383a4e
7
+ data.tar.gz: b8a2b9620fb3d23d38c0985f57f965abce55146522a0bd2d7198e250f3896b9abf89bfec6548661aaea139bddc96fef9ab247bf0348a2f59944ba8ec4ec6f3ac
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/rails_app/log/*
11
+ /.ruby-version
12
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in devise-multi_email.gemspec
4
+ gemspec
5
+
6
+ gem 'rails'
7
+
8
+ group :development, :test do
9
+ gem 'rspec', '~> 3'
10
+ gem 'sqlite3'
11
+ gem 'capybara'
12
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 WANG QIANG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Devise::MultiEmail [![Build Status](https://travis-ci.org/allenwq/devise-multi_email.svg?branch=master)](https://travis-ci.org/allenwq/devise-multi_email)
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'devise-multi_email'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install devise-multi_email
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/devise-multi_email. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "devise/multi_email"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'devise/multi_email/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'devise-multi_email'
8
+ spec.version = Devise::MultiEmail::VERSION
9
+ spec.authors = ['ALLEN WANG QIANG']
10
+ spec.email = ['rovingbreeze@gmail.com']
11
+
12
+ spec.summary = %q{Let devise support multiple emails.}
13
+ spec.description = %q{Devise authenticatable, confirmable and validatable with multiple emails.}
14
+ spec.homepage = 'https://github.com/allenwq/devise-multi_email.git'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'devise'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.10'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'devise/multi_email/version'
2
+ require 'devise'
3
+
4
+ Devise.add_module :multi_email_authenticatable, model: 'devise/multi_email/models/authenticatable'
5
+ Devise.add_module :multi_email_confirmable, model: 'devise/multi_email/models/confirmable'
6
+ Devise.add_module :multi_email_validatable, model: 'devise/multi_email/models/validatable'
@@ -0,0 +1,86 @@
1
+ module Devise
2
+ module Models
3
+ module EmailAuthenticatable
4
+ USER_ASSOCIATION = :user
5
+
6
+ def devise_scope
7
+ user_association = self.class.reflect_on_association(USER_ASSOCIATION)
8
+ if user_association
9
+ user_association.class_name.constantize
10
+ else
11
+ raise "#{self.class.name}: Association :#{USER_ASSOCIATION} not found: Have you declared that ?"
12
+ end
13
+ end
14
+ end
15
+
16
+ module MultiEmailAuthenticatable
17
+ extend ActiveSupport::Concern
18
+ EMAILS_ASSOCIATION = :emails
19
+
20
+ included do
21
+ devise :database_authenticatable
22
+
23
+ attr_accessor :current_login_email
24
+
25
+ email_class.send :include, EmailAuthenticatable
26
+ end
27
+
28
+ def self.required_fields(klass)
29
+ []
30
+ end
31
+
32
+ # Gets the primary email record.
33
+ def primary_email_record
34
+ valid_emails = emails.each.select do |email_record|
35
+ !email_record.destroyed? && !email_record.marked_for_destruction?
36
+ end
37
+
38
+ result = valid_emails.find(&:primary?)
39
+ result ||= valid_emails.first
40
+ result
41
+ end
42
+
43
+ # Gets the primary email address of the user.
44
+ def email
45
+ primary_email_record.try(:email)
46
+ end
47
+
48
+ # Sets the default email address of the user.
49
+ def email=(email)
50
+ record = primary_email_record
51
+ if email
52
+ record ||= emails.build
53
+ record.email = email
54
+ record.primary = true
55
+ elsif email.nil? && record
56
+ record.mark_for_destruction
57
+ end
58
+ end
59
+
60
+ module ClassMethods
61
+ def find_first_by_auth_conditions(tainted_conditions, opts = {})
62
+ email = tainted_conditions.delete(:email)
63
+ if email && email.is_a?(String)
64
+ conditions = devise_parameter_filter.filter(tainted_conditions).to_h.merge(opts).
65
+ reverse_merge(emails: { email: email })
66
+
67
+ resource = joins(:emails).find_by(conditions)
68
+ resource.current_login_email = email if resource.respond_to?(:current_login_email=)
69
+ resource
70
+ else
71
+ super(tainted_conditions, opts)
72
+ end
73
+ end
74
+
75
+ def email_class
76
+ email_association = reflect_on_association(EMAILS_ASSOCIATION)
77
+ if email_association
78
+ email_association.class_name.constantize
79
+ else
80
+ raise "#{self.class.name}: Association :#{EMAILS_ASSOCIATION} not found: It might because your declaration is after `devise :multi_email_confirmable`."
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,113 @@
1
+ module Devise
2
+ module Models
3
+ module EmailConfirmable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ devise :confirmable
8
+
9
+ extend ClassReplacementMethods
10
+ end
11
+
12
+ module ClassReplacementMethods
13
+ def allow_unconfirmed_access_for
14
+ 0.day
15
+ end
16
+ end
17
+ end
18
+
19
+ module MultiEmailConfirmable
20
+ extend ActiveSupport::Concern
21
+
22
+ included do
23
+ devise :confirmable
24
+ include InstanceReplacementMethods
25
+ extend ClassReplacementMethods
26
+
27
+ email_class.send :include, EmailConfirmable
28
+ end
29
+
30
+ def self.required_fields(klass)
31
+ []
32
+ end
33
+
34
+ module InstanceReplacementMethods
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
47
+
48
+ # This need to be forwarded to the email that the user logged in with
49
+ def active_for_authentication?
50
+ login_email = current_login_email_record
51
+
52
+ if login_email && !login_email.primary?
53
+ super && login_email.active_for_authentication?
54
+ else
55
+ super
56
+ end
57
+ end
58
+
59
+ # Shows email not confirmed instead of account inactive when the email that user used to login is not confirmed
60
+ def inactive_message
61
+ login_email = current_login_email_record
62
+
63
+ if login_email && !login_email.primary? && !login_email.confirmed?
64
+ :unconfirmed
65
+ else
66
+ super
67
+ end
68
+ end
69
+
70
+ protected
71
+
72
+ # Overrides Devise::Models::Confirmable#postpone_email_change?
73
+ def postpone_email_change?
74
+ false
75
+ end
76
+
77
+ # Email should handle the confirmation token.
78
+ def generate_confirmation_token
79
+ end
80
+
81
+ # Email will send reconfirmation instructions.
82
+ def send_reconfirmation_instructions
83
+ end
84
+
85
+ # Email will send confirmation instructions.
86
+ def send_on_create_confirmation_instructions
87
+ end
88
+
89
+ private
90
+
91
+ def current_login_email_record
92
+ if respond_to?(:current_login_email) && current_login_email
93
+ send(self.class::EMAILS_ASSOCIATION).find_by(email: current_login_email)
94
+ end
95
+ end
96
+ end
97
+
98
+ module ClassReplacementMethods
99
+ # Overrides Devise::Models::Confirmable.confirm_by_token
100
+ # Forward the logic to email.
101
+ def confirm_by_token(token)
102
+ email_class.confirm_by_token(token)
103
+ end
104
+
105
+ # Overrides Devise::Models::Confirmable.send_confirmation_instructions
106
+ # Forward the logic to email.
107
+ def send_confirmation_instructions(params)
108
+ email_class.send_confirmation_instructions(params)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,52 @@
1
+ module Devise
2
+ module Models
3
+ module EmailValidatable
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+
7
+ base.class_eval do
8
+ validates_presence_of :email, if: :email_required?
9
+ validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
10
+ validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
11
+ end
12
+ end
13
+
14
+ def email_required?
15
+ true
16
+ end
17
+
18
+ module ClassMethods
19
+ Devise::Models.config(self, :email_regexp)
20
+ end
21
+ end
22
+
23
+ module MultiEmailValidatable
24
+ extend ActiveSupport::Concern
25
+
26
+ included do
27
+ devise :validatable
28
+
29
+ after_validation :propagate_email_errors
30
+ email_class.send :include, EmailValidatable
31
+ end
32
+
33
+ def self.required_fields(klass)
34
+ []
35
+ end
36
+
37
+ private
38
+
39
+ def email_changed?
40
+ false
41
+ end
42
+
43
+ def propagate_email_errors
44
+ return if (email_errors = errors.delete(self.class::EMAILS_ASSOCIATION)).nil?
45
+
46
+ email_errors.each do |error|
47
+ errors.add(:email, error)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module Devise
2
+ module MultiEmail
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-multi_email
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ALLEN WANG QIANG
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: devise
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Devise authenticatable, confirmable and validatable with multiple emails.
56
+ email:
57
+ - rovingbreeze@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - devise-multi_email.gemspec
73
+ - lib/devise/multi_email.rb
74
+ - lib/devise/multi_email/models/authenticatable.rb
75
+ - lib/devise/multi_email/models/confirmable.rb
76
+ - lib/devise/multi_email/models/validatable.rb
77
+ - lib/devise/multi_email/version.rb
78
+ homepage: https://github.com/allenwq/devise-multi_email.git
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Let devise support multiple emails.
102
+ test_files: []