summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
Diffstat (limited to 'users/app')
-rw-r--r--users/app/controllers/users_controller.rb3
-rw-r--r--users/app/models/local_email.rb11
-rw-r--r--users/app/models/user.rb2
-rw-r--r--users/app/views/emails/_email.html.haml11
-rw-r--r--users/app/views/users/edit.html.haml2
5 files changed, 13 insertions, 16 deletions
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index 79de630..75ae2da 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -33,9 +33,10 @@ class UsersController < ApplicationController
def update
@user.attributes = params[:user]
- @email_alias = @user.email_aliases.last
if @user.changed? and @user.save
flash[:notice] = t(:user_updated_successfully)
+ elsif !@user.email_aliases.last.valid?
+ @email_alias = @user.email_aliases.pop
end
respond_with @user, :location => edit_user_path(@user, :anchor => @anchor)
end
diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb
index 587acc6..bd9dea3 100644
--- a/users/app/models/local_email.rb
+++ b/users/app/models/local_email.rb
@@ -7,16 +7,13 @@ class LocalEmail
before_validation :strip_domain_if_needed
validates :username,
- :format => { :with => /\A([^@\s]+)(@.*)?\Z/, :message => "needs to be a valid login or email address"}
+ :presence => true,
+ :format => { :with => /\A([^@\s]+)(@#{APP_CONFIG[:domain]})?\Z/i, :message => "needs to be a valid login or email address @#{APP_CONFIG[:domain]}"}
validate :unique_on_server
validate :unique_alias_for_user
validate :differs_from_login
- validates :username,
- :presence => true,
- :format => { :with => /[^@]*(@#{APP_CONFIG[:domain]})?\Z/i,
- :message => "may not contain an '@' or needs to end in @#{APP_CONFIG[:domain]}"}
validates :casted_by, :presence => true
def email
@@ -38,7 +35,7 @@ class LocalEmail
def unique_on_server
has_email = User.find_by_login_or_alias(username)
- if has_email && has_email != self.base_doc
+ if has_email && has_email != self.casted_by
errors.add :username, "has already been taken"
end
end
@@ -60,7 +57,7 @@ class LocalEmail
end
def strip_domain_if_needed
- self.username.gsub /@#{APP_CONFIG[:domain]}/i, ''
+ self.username.gsub! /@#{APP_CONFIG[:domain]}/i, ''
end
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index f89d01c..63f4d0f 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -72,7 +72,7 @@ class User < CouchRest::Model::Base
end
def email_address
- login + '@' + APP_CONFIG[:domain]
+ LocalEmail.new(login)
end
# Since we are storing admins by login, we cannot allow admins to change their login.
diff --git a/users/app/views/emails/_email.html.haml b/users/app/views/emails/_email.html.haml
index 3feb6f0..f5eb2d0 100644
--- a/users/app/views/emails/_email.html.haml
+++ b/users/app/views/emails/_email.html.haml
@@ -1,6 +1,5 @@
-- if email.valid?
- %li.pull-right
- %code= email
- = link_to(user_email_alias_path(@user, email), :method => :delete) do
- %i.icon-remove
- .clearfix
+%li.pull-right
+ %code= email
+ = link_to(user_email_alias_path(@user, email), :method => :delete) do
+ %i.icon-remove
+.clearfix
diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml
index 3f62e5f..69864e5 100644
--- a/users/app/views/users/edit.html.haml
+++ b/users/app/views/users/edit.html.haml
@@ -7,7 +7,7 @@
- content_for :email do
%legend=t :email_address
Your email address is
- = user.email_address
+ = render user.email_address
= user_form_with 'email_forward_field', :legend => :forward_email
= user_form_with 'email_aliases', :legend => :add_email_alias
= render 'tabs/tabs', :tabs => [:account, :email]