diff options
author | Jason Hollingsworth <jhworth.developer@gmail.com> | 2014-02-08 21:08:49 -0600 |
---|---|---|
committer | Jason Hollingsworth <jhworth.developer@gmail.com> | 2014-02-13 22:59:39 -0600 |
commit | 29cfd33d949d21d67f3892473c24d4f0a127dfe6 (patch) | |
tree | e9ed4a10e06f7eba224150a643cb87507fc2ddc7 /app/models/email.rb | |
parent | d41e404e09c79394ff1938eee01b56345edc6ed9 (diff) | |
download | gitlab-ce-29cfd33d949d21d67f3892473c24d4f0a127dfe6.tar.gz |
Add email aliases for users
Emails are used to associate commits with users. The emails
are not verified and don't have to be valid email addresses. They
are assigned on a first come, first serve basis.
Notifications are sent when an email is added.
Diffstat (limited to 'app/models/email.rb')
-rw-r--r-- | app/models/email.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/models/email.rb b/app/models/email.rb new file mode 100644 index 00000000000..22e71e4f107 --- /dev/null +++ b/app/models/email.rb @@ -0,0 +1,33 @@ +# == Schema Information +# +# Table name: emails +# +# id :integer not null, primary key +# user_id :integer not null +# email :string not null +# created_at :datetime not null +class Email < ActiveRecord::Base + attr_accessible :email, :user_id + + # + # Relations + # + belongs_to :user + + # + # Validations + # + validates :user_id, presence: true + validates :email, presence: true, email: { strict_mode: true }, uniqueness: true + validate :unique_email, if: ->(email) { email.email_changed? } + + before_validation :cleanup_email + + def cleanup_email + self.email = self.email.downcase.strip + end + + def unique_email + self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email) + end +end
\ No newline at end of file |