From b79d8ae03339e2957c50111f0eae405ca1440674 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 5 Sep 2013 13:10:23 -0700 Subject: Move handle method to Email model and have it work for local and non-local emails. --- users/app/models/email.rb | 4 ++++ users/app/models/local_email.rb | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'users/app') diff --git a/users/app/models/email.rb b/users/app/models/email.rb index 1bcff1c..89c31bb 100644 --- a/users/app/models/email.rb +++ b/users/app/models/email.rb @@ -19,4 +19,8 @@ class Email < String self end + def handle + self.split('@').first + end + end diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb index c1f7c11..6303bb6 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -20,10 +20,6 @@ class LocalEmail < Email [handle] end - def handle - gsub(/@#{domain}/i, '') - end - def domain LocalEmail.domain end -- cgit v1.2.3 From 8e8f5ddda08a883842a8c3e2ffa994e12b25dd39 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 5 Sep 2013 13:56:02 -0700 Subject: Ensure that address in identity really is a LocalEmail. --- users/app/models/identity.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'users/app') diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb index 355f67a..e197c9c 100644 --- a/users/app/models/identity.rb +++ b/users/app/models/identity.rb @@ -10,6 +10,7 @@ class Identity < CouchRest::Model::Base validate :unique_forward validate :alias_available + validate :address_local_email design do view :by_user_id @@ -79,4 +80,9 @@ class Identity < CouchRest::Model::Base end end + def address_local_email + return if address.valid? #this ensures it is LocalEmail + self.errors.add(:address, address.errors.messages[:email].first) #assumes only one error + end + end -- cgit v1.2.3 From 3ef22b5a856e1f576fb0a6a589b6b7ab41e1dd18 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 5 Sep 2013 14:00:50 -0700 Subject: For moment, have identity's address handle aliased from login so we can use LoginFormatValidation. However, this is not how we will want it eventually. One issue is that the errors messages are set on login, rather than the appropriate field. --- users/app/models/identity.rb | 6 ++++++ users/app/models/login_format_validation.rb | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'users/app') diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb index e197c9c..91345a0 100644 --- a/users/app/models/identity.rb +++ b/users/app/models/identity.rb @@ -1,4 +1,5 @@ class Identity < CouchRest::Model::Base + include LoginFormatValidation use_database :identities @@ -64,6 +65,11 @@ class Identity < CouchRest::Model::Base write_attribute('keys', keys.merge(type => value)) end + # for LoginFormatValidation + def login + self.address.handle + end + protected def unique_forward diff --git a/users/app/models/login_format_validation.rb b/users/app/models/login_format_validation.rb index 1d02bd1..c1fcf70 100644 --- a/users/app/models/login_format_validation.rb +++ b/users/app/models/login_format_validation.rb @@ -1,19 +1,21 @@ module LoginFormatValidation extend ActiveSupport::Concern + #TODO: Probably will replace this. Playing with using it for aliases too, but won't want it connected to login field. + included do # Have multiple regular expression validations so we can get specific error messages: validates :login, :format => { :with => /\A.{2,}\z/, - :message => "Login must have at least two characters"} + :message => "Must have at least two characters"} validates :login, :format => { :with => /\A[a-z\d_\.-]+\z/, :message => "Only lowercase letters, digits, . - and _ allowed."} validates :login, :format => { :with => /\A[a-z].*\z/, - :message => "Login must begin with a lowercase letter"} + :message => "Must begin with a lowercase letter"} validates :login, :format => { :with => /\A.*[a-z\d]\z/, - :message => "Login must end with a letter or digit"} + :message => "Must end with a letter or digit"} end end -- cgit v1.2.3 From a9c68ba0bbba7a95e9b4a3ff24554d1b0af6cbc5 Mon Sep 17 00:00:00 2001 From: jessib Date: Mon, 23 Sep 2013 12:23:08 -0700 Subject: This ensures that email addresses contain only lowercase letters, and that an identity's destination is a valid Email. --- users/app/models/email.rb | 8 +++++++- users/app/models/identity.rb | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'users/app') diff --git a/users/app/models/email.rb b/users/app/models/email.rb index 89c31bb..f38f2f5 100644 --- a/users/app/models/email.rb +++ b/users/app/models/email.rb @@ -3,10 +3,16 @@ class Email < String validates :email, :format => { - :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, + :with => /\A([^@\s]+)@((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})\Z/, #checks format, but allows lowercase :message => "needs to be a valid email address" } + validates :email, + :format => { + :with => /\A[^A-Z]*\Z/, #forbids uppercase characters + :message => "letters must be lowercase" + } + def to_partial_path "emails/email" end diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb index 91345a0..e0a24e9 100644 --- a/users/app/models/identity.rb +++ b/users/app/models/identity.rb @@ -12,6 +12,7 @@ class Identity < CouchRest::Model::Base validate :unique_forward validate :alias_available validate :address_local_email + validate :destination_email design do view :by_user_id @@ -91,4 +92,9 @@ class Identity < CouchRest::Model::Base self.errors.add(:address, address.errors.messages[:email].first) #assumes only one error end + def destination_email + return if destination.valid? #this ensures it is Email + self.errors.add(:destination, destination.errors.messages[:email].first) #assumes only one error #TODO + end + end -- cgit v1.2.3 From 193bf6446b384dce1699e8fb82be6f16cb8cb5f6 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 23 Sep 2013 19:55:22 +0200 Subject: use token auth when accessing the api from webapp One failing integration test still needs to be fixed --- users/app/assets/javascripts/srp | 2 +- users/app/assets/javascripts/users.js | 20 +++++++++++++++++++- users/app/controllers/v1/sessions_controller.rb | 1 + users/app/views/users/_edit.html.haml | 5 +++-- 4 files changed, 24 insertions(+), 4 deletions(-) (limited to 'users/app') diff --git a/users/app/assets/javascripts/srp b/users/app/assets/javascripts/srp index 9c61d52..d22bf3b 160000 --- a/users/app/assets/javascripts/srp +++ b/users/app/assets/javascripts/srp @@ -1 +1 @@ -Subproject commit 9c61d52f1f975ec0eefe5b4a0b71ac529300cbe7 +Subproject commit d22bf3b9fe2fd31192e1e1b358e97e5a0f3f90b3 diff --git a/users/app/assets/javascripts/users.js b/users/app/assets/javascripts/users.js index 4c9b510..9d1a0f0 100644 --- a/users/app/assets/javascripts/users.js +++ b/users/app/assets/javascripts/users.js @@ -3,7 +3,12 @@ // LOCAL FUNCTIONS // - var poll_users, prevent_default, form_failed, form_passed, clear_errors; + var poll_users, + prevent_default, + form_failed, + form_passed, + clear_errors, + update_user; prevent_default = function(event) { return event.preventDefault(); @@ -19,6 +24,17 @@ return $('#messages').empty(); }; + update_user = function(submitEvent) { + var form = submitEvent.target; + var token = form.dataset.token; + var url = form.action; + return $.ajax({ + url: url, + type: 'PUT', + headers: { Authorization: 'Token token="' + token + '"' }, + data: $(form).serialize() + }); + }; // // PUBLIC FUNCTIONS @@ -76,6 +92,8 @@ $('#new_session').submit(srp.login); $('#update_login_and_password').submit(prevent_default); $('#update_login_and_password').submit(srp.update); + $('#update_pgp_key').submit(prevent_default); + $('#update_pgp_key').submit(update_user); return $('#user-typeahead').typeahead({ source: poll_users }); diff --git a/users/app/controllers/v1/sessions_controller.rb b/users/app/controllers/v1/sessions_controller.rb index 1b20a82..eb6c322 100644 --- a/users/app/controllers/v1/sessions_controller.rb +++ b/users/app/controllers/v1/sessions_controller.rb @@ -24,6 +24,7 @@ module V1 def update authenticate! @token = Token.create(:user_id => current_user.id) + session[:token] = @token.id render :json => login_response end diff --git a/users/app/views/users/_edit.html.haml b/users/app/views/users/_edit.html.haml index 5f74d32..ae3f32d 100644 --- a/users/app/views/users/_edit.html.haml +++ b/users/app/views/users/_edit.html.haml @@ -10,7 +10,8 @@ -# however, we don't want the user to change their login without generating a new key, so we hide the ui for this -# (although it works perfectly fine to change username if the field was visible). -# -- form_options = {:url => '/not-used', :html => {:class => user_form_class('form-horizontal'), :id => 'update_login_and_password'}, :validate => true} + +- form_options = {:url => '/not-used', :html => {:class => user_form_class('form-horizontal'), :id => 'update_login_and_password', :data => {token: session[:token]}}, :validate => true} = simple_form_for @user, form_options do |f| %legend= t(:change_password) = hidden_field_tag 'user_param', @user.to_param @@ -28,7 +29,7 @@ -# this will be replaced by a identities controller/view at some point -# -- form_options = {:html => {:class => user_form_class('form-horizontal'), :id => 'update_pgp_key'}, :validate => true} +- form_options = {:html => {:class => user_form_class('form-horizontal'), :id => 'update_pgp_key', :data => {token: session[:token]}}, :validate => true} = simple_form_for [:api, @user], form_options do |f| %legend= t(:advanced_options) = f.input :public_key, :as => :text, :hint => t(:use_ascii_key), :input_html => {:class => "full-width", :rows => 4} -- cgit v1.2.3 From 4f8414298750193b6de3daff08364ec745a6a761 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 25 Sep 2013 10:12:08 +0200 Subject: visual feedback when submitting forms (#3164) This also helps with the failing integration test. We needed a way to tell the ajax request was back. Observing the button state now works for that. --- users/app/assets/javascripts/users.js | 13 ++++++++++++- users/app/views/users/_edit.html.haml | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'users/app') diff --git a/users/app/assets/javascripts/users.js b/users/app/assets/javascripts/users.js index 9d1a0f0..aaeba6e 100644 --- a/users/app/assets/javascripts/users.js +++ b/users/app/assets/javascripts/users.js @@ -28,12 +28,22 @@ var form = submitEvent.target; var token = form.dataset.token; var url = form.action; - return $.ajax({ + var req = $.ajax({ url: url, type: 'PUT', headers: { Authorization: 'Token token="' + token + '"' }, data: $(form).serialize() }); + req.done( function() { + $(form).find('input[type="submit"]').button('reset'); + }); + }; + + markAsSubmitted = function(submitEvent) { + var form = submitEvent.target; + $(form).addClass('submitted') + // bootstrap loading state: + $(form).find('input[type="submit"]').button('loading'); }; // @@ -86,6 +96,7 @@ // $(document).ready(function() { + $('form').submit(markAsSubmitted); $('#new_user').submit(prevent_default); $('#new_user').submit(srp.signup); $('#new_session').submit(prevent_default); diff --git a/users/app/views/users/_edit.html.haml b/users/app/views/users/_edit.html.haml index ae3f32d..9d2473b 100644 --- a/users/app/views/users/_edit.html.haml +++ b/users/app/views/users/_edit.html.haml @@ -35,7 +35,7 @@ = f.input :public_key, :as => :text, :hint => t(:use_ascii_key), :input_html => {:class => "full-width", :rows => 4} .control-group .controls - = f.submit t(:save), :class => 'btn' + = f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."} -# -# DESTROY ACCOUNT -- cgit v1.2.3 From af9d843d646cf500306de0ad20896c05ecaccd78 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 26 Sep 2013 12:06:25 -0700 Subject: Since local part of email is case sensitive, want to allow remote email addresses with uppercase letters in local part. --- users/app/models/email.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'users/app') diff --git a/users/app/models/email.rb b/users/app/models/email.rb index f38f2f5..a9a503f 100644 --- a/users/app/models/email.rb +++ b/users/app/models/email.rb @@ -3,16 +3,10 @@ class Email < String validates :email, :format => { - :with => /\A([^@\s]+)@((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})\Z/, #checks format, but allows lowercase + :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, #local part of email is case-sensitive, so allow uppercase letter. :message => "needs to be a valid email address" } - validates :email, - :format => { - :with => /\A[^A-Z]*\Z/, #forbids uppercase characters - :message => "letters must be lowercase" - } - def to_partial_path "emails/email" end -- cgit v1.2.3