diff options
author | Azul <azul@leap.se> | 2012-12-09 13:19:54 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-12-09 13:19:54 +0100 |
commit | 9d99d340cfd3c55f21d38c1ba9f3f4574e40c46c (patch) | |
tree | 702e054dd3ba027795cd57ff980311a52a575016 | |
parent | 4dffda05477f74c90197948bb6f13bedc8b2a19f (diff) |
basic form added to user settings, simple model created
-rw-r--r-- | users/app/controllers/email_aliases_controller.rb (renamed from users/app/controllers/email_alias_controller.rb) | 7 | ||||
-rw-r--r-- | users/app/helpers/email_aliases_helper.rb | 11 | ||||
-rw-r--r-- | users/app/models/email_alias.rb | 6 | ||||
-rw-r--r-- | users/app/models/user.rb | 6 | ||||
-rw-r--r-- | users/app/views/users/_email_aliases.html.haml | 10 | ||||
-rw-r--r-- | users/app/views/users/edit.html.haml | 1 | ||||
-rw-r--r-- | users/config/routes.rb | 4 |
7 files changed, 40 insertions, 5 deletions
diff --git a/users/app/controllers/email_alias_controller.rb b/users/app/controllers/email_aliases_controller.rb index 979c8ad..751df85 100644 --- a/users/app/controllers/email_alias_controller.rb +++ b/users/app/controllers/email_aliases_controller.rb @@ -2,6 +2,8 @@ class EmailAliasesController < ApplicationController before_filter :fetch_user + respond_to :html + # get a list of email aliases for the given user? def index @aliases = @user.email_aliases @@ -11,20 +13,21 @@ class EmailAliasesController < ApplicationController def create @alias = @user.add_email_alias(params[:email_alias]) flash[:notice] = t(:email_alias_created_successfully) unless @alias.errors - respond_with @alias + respond_with @alias, :location => edit_user_path(@user, :anchor => :email) end def update @alias = @user.get_email_alias(params[:id]) @alias.set_email(params[:email_alias]) flash[:notice] = t(:email_alias_updated_successfully) unless @alias.errors - respond_with @alias + respond_with @alias, :location => edit_user_path(@user, :anchor => :email) end def destroy @alias = @user.get_email_alias(params[:id]) flash[:notice] = t(:email_alias_destroyed_successfully) @alias.destroy + redirect_to edit_user_path(@user, :anchor => :email) end protected diff --git a/users/app/helpers/email_aliases_helper.rb b/users/app/helpers/email_aliases_helper.rb new file mode 100644 index 0000000..b56b068 --- /dev/null +++ b/users/app/helpers/email_aliases_helper.rb @@ -0,0 +1,11 @@ +module EmailAliasesHelper + + def email_alias_form(options = {}) + simple_form_for [@user, EmailAlias.new()], + :html => {:class => "form-horizontal email-alias form"}, + :validate => true do |f| + yield f + end + end + +end diff --git a/users/app/models/email_alias.rb b/users/app/models/email_alias.rb new file mode 100644 index 0000000..25e4b27 --- /dev/null +++ b/users/app/models/email_alias.rb @@ -0,0 +1,6 @@ +class EmailAlias + include CouchRest::Model::Embeddable + + property :email, String + timestamps! +end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index ae271ce..81d5262 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -1,11 +1,13 @@ class User < CouchRest::Model::Base property :login, String, :accessible => true - property :email, String, :accessible => true - property :email_forward, String, :accessible => true property :password_verifier, String, :accessible => true property :password_salt, String, :accessible => true + property :email, String, :accessible => true + property :email_forward, String, :accessible => true + property :email_aliases, [EmailAlias] + validates :login, :password_salt, :password_verifier, :presence => true diff --git a/users/app/views/users/_email_aliases.html.haml b/users/app/views/users/_email_aliases.html.haml new file mode 100644 index 0000000..54eac0f --- /dev/null +++ b/users/app/views/users/_email_aliases.html.haml @@ -0,0 +1,10 @@ +%legend= t(:email_aliases) +%ul + - @user.email_aliases.each do |email| + %li= email += email_alias_form do |f| + =f.input :email, :placeholder => "alias@#{request.domain}" + .pull-right + %button{:type => :submit, :class => 'btn'} + %i.icon-plus + Add Email Alias diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml index b33c19b..eb1bca4 100644 --- a/users/app/views/users/edit.html.haml +++ b/users/app/views/users/edit.html.haml @@ -14,3 +14,4 @@ .tab-pane#email = user_form_with 'email_field', :legend => :set_email_address = user_form_with 'email_forward_field', :legend => :forward_email + = render 'email_aliases' diff --git a/users/config/routes.rb b/users/config/routes.rb index 6de216f..3c5fb73 100644 --- a/users/config/routes.rb +++ b/users/config/routes.rb @@ -10,6 +10,8 @@ Rails.application.routes.draw do resources :sessions, :only => [:new, :create, :update, :destroy] get "signup" => "users#new", :as => "signup" - resources :users + resources :users do + resources :email_aliases + end end |