diff --git a/app/models/user.rb b/app/models/user.rb index 6866657..03ad841 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -104,18 +104,18 @@ class User < ActiveRecord::Base validates_presence_of :login validates_presence_of :email - validates_format_of :login, :message => _('incorrect login format'), :with => Profile::IDENTIFIER_FORMAT, :if => (lambda {|user| !user.login.blank?}) + validates_format_of :login, :message => :login_format, :with => Profile::IDENTIFIER_FORMAT, :if => (lambda {|user| !user.login.blank?}) validates_presence_of :password, :if => :password_required? validates_presence_of :password_confirmation, :if => :password_required? - validates_length_of :password, :message => _('length must be within 4 to 40 characters'), :within => 4..40, :if => :password_required? + validates_length_of :password, :within => 4..40, :if => :password_required? validates_confirmation_of :password, :if => :password_required? - validates_length_of :login, :message => _('length must be within 2 to 40 characters'), :within => 2..40, :if => (lambda {|user| !user.login.blank?}) - validates_length_of :email, :message => _('length must be within 3 to 100 characters'),:within => 3..100, :if => (lambda {|user| !user.email.blank?}) + validates_length_of :login, :within => 2..40, :if => (lambda {|user| !user.login.blank?}) + validates_length_of :email, :within => 3..100, :if => (lambda {|user| !user.email.blank?}) validates_uniqueness_of :login, :case_sensitive => false, :scope => :environment_id validates_uniqueness_of :email, :case_sensitive => false, :scope => :environment_id before_save :encrypt_password before_save :normalize_email, if: proc{ |u| u.email.present? } - validates_format_of :email, :message => _('incorrect email format'), :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|user| !user.email.blank?}) + validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|user| !user.email.blank?}) validates_inclusion_of :terms_accepted, :in => [ '1' ], :if => lambda { |u| ! u.terms_of_use.blank? }, :message => N_('{fn} must be checked in order to signup.').fix_i18n diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index 842c28a..fa68faf 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -221,6 +221,9 @@ <<: *errors_template full_messages: format: "%{attribute} %{message}" + models: + user: + login_format: "with invalid format. It must contain only lowercase letters, digits, '_' and '-', and must begin with a letter or a digit." en: <<: *en-US diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 0637aee..322c4db 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -229,9 +229,11 @@ <<: *errors_messages template: <<: *errors_template - full_messages: format: "%{attribute} %{message}" + models: + user: + login_format: "com formato inválido. Só pode conter letras minúsculas não acentudadas, dígitos, '_' e '-', e deve iniciar com uma letra ou um dígito." pt: <<: *pt-BR diff --git a/config/locales/pt-PT.yml b/config/locales/pt-PT.yml index 7493e7b..1d136e8 100644 --- a/config/locales/pt-PT.yml +++ b/config/locales/pt-PT.yml @@ -229,3 +229,4 @@ full_messages: format: "%{attribute} %{message}" + diff --git a/db/schema.rb b/db/schema.rb index 87ace0e..35cc893 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150712194411) do +ActiveRecord::Schema.define(:version => 20150722042714) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -163,8 +163,6 @@ ActiveRecord::Schema.define(:version => 20150712194411) do t.integer "author_id" t.integer "created_by_id" t.boolean "show_to_followers", :default => true - t.integer "sash_id" - t.integer "level", :default => 0 end add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count" @@ -191,17 +189,6 @@ ActiveRecord::Schema.define(:version => 20150712194411) do add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" - create_table "badges_sashes", :force => true do |t| - t.integer "badge_id" - t.integer "sash_id" - t.boolean "notified_user", :default => false - t.datetime "created_at" - end - - add_index "badges_sashes", ["badge_id", "sash_id"], :name => "index_badges_sashes_on_badge_id_and_sash_id" - add_index "badges_sashes", ["badge_id"], :name => "index_badges_sashes_on_badge_id" - add_index "badges_sashes", ["sash_id"], :name => "index_badges_sashes_on_sash_id" - create_table "blocks", :force => true do |t| t.string "title" t.integer "box_id" @@ -297,10 +284,8 @@ ActiveRecord::Schema.define(:version => 20150712194411) do t.string "referrer" t.text "settings" t.integer "paragraph_id" - t.string "paragraph_uuid" end - add_index "comments", ["paragraph_uuid"], :name => "index_comments_on_paragraph_uuid" add_index "comments", ["source_id", "spam"], :name => "index_comments_on_source_id_and_spam" create_table "contact_lists", :force => true do |t| @@ -370,7 +355,6 @@ ActiveRecord::Schema.define(:version => 20150712194411) do t.string "default_language" t.string "noreply_email" t.string "redirection_after_signup", :default => "keep_on_same_page" - t.text "send_email_plugin_allow_to" t.string "date_format", :default => "month_name_with_year" end @@ -407,17 +391,6 @@ ActiveRecord::Schema.define(:version => 20150712194411) do add_index "friendships", ["person_id", "friend_id"], :name => "index_friendships_on_person_id_and_friend_id" add_index "friendships", ["person_id"], :name => "index_friendships_on_person_id" - create_table "gamification_plugin_badges", :force => true do |t| - t.string "name" - t.integer "level" - t.string "description" - t.string "custom_fields" - t.integer "owner_id" - t.string "owner_type" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "images", :force => true do |t| t.integer "parent_id" t.string "content_type" @@ -474,46 +447,6 @@ ActiveRecord::Schema.define(:version => 20150712194411) do t.datetime "updated_at" end - create_table "mark_comment_as_read_plugin", :force => true do |t| - t.integer "comment_id" - t.integer "person_id" - end - - add_index "mark_comment_as_read_plugin", ["comment_id", "person_id"], :name => "index_mark_comment_as_read_plugin_on_comment_id_and_person_id", :unique => true - - create_table "merit_actions", :force => true do |t| - t.integer "user_id" - t.string "action_method" - t.integer "action_value" - t.boolean "had_errors", :default => false - t.string "target_model" - t.integer "target_id" - t.text "target_data" - t.boolean "processed", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "merit_activity_logs", :force => true do |t| - t.integer "action_id" - t.string "related_change_type" - t.integer "related_change_id" - t.string "description" - t.datetime "created_at" - end - - create_table "merit_score_points", :force => true do |t| - t.integer "score_id" - t.integer "num_points", :default => 0 - t.string "log" - t.datetime "created_at" - end - - create_table "merit_scores", :force => true do |t| - t.integer "sash_id" - t.string "category", :default => "default" - end - create_table "national_region_types", :force => true do |t| t.string "name" end @@ -530,15 +463,6 @@ ActiveRecord::Schema.define(:version => 20150712194411) do add_index "national_regions", ["name"], :name => "name_index" add_index "national_regions", ["national_region_code"], :name => "code_index" - create_table "pairwise_plugin_choices_related", :force => true do |t| - t.integer "choice_id" - t.integer "parent_choice_id" - t.integer "question_id" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "price_details", :force => true do |t| t.decimal "price", :default => 0.0 t.integer "product_id" @@ -646,21 +570,15 @@ ActiveRecord::Schema.define(:version => 20150712194411) do t.boolean "allow_members_to_invite", :default => true t.boolean "invite_friends_only", :default => false t.boolean "secret", :default => false - t.integer "sash_id" - t.integer "level", :default => 0 end add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" add_index "profiles", ["created_at"], :name => "index_profiles_on_created_at" - add_index "profiles", ["enabled"], :name => "index_profiles_on_enabled" add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" add_index "profiles", ["friends_count"], :name => "index_profiles_on_friends_count" add_index "profiles", ["identifier"], :name => "index_profiles_on_identifier" add_index "profiles", ["members_count"], :name => "index_profiles_on_members_count" add_index "profiles", ["region_id"], :name => "index_profiles_on_region_id" - add_index "profiles", ["type"], :name => "index_profiles_on_type" - add_index "profiles", ["validated"], :name => "index_profiles_on_validated" - add_index "profiles", ["visible"], :name => "index_profiles_on_visible" create_table "proposals_discussion_plugin_proposal_evaluations", :force => true do |t| t.integer "proposal_task_id" @@ -718,12 +636,6 @@ ActiveRecord::Schema.define(:version => 20150712194411) do t.boolean "is_global" end - add_index "role_assignments", ["accessor_id", "accessor_type", "resource_id", "resource_type"], :name => "index_on_role_assigments_accessor_resource_role" - add_index "role_assignments", ["accessor_id", "accessor_type", "role_id"], :name => "index_on_role_assigments_accessor_role" - add_index "role_assignments", ["accessor_id", "accessor_type"], :name => "index_role_assignments_on_accessor_id_and_accessor_type" - add_index "role_assignments", ["resource_id", "resource_type", "role_id"], :name => "index_on_role_assigments_resource_role" - add_index "role_assignments", ["resource_id", "resource_type"], :name => "index_role_assignments_on_resource_id_and_resource_type" - create_table "roles", :force => true do |t| t.string "name" t.string "key" @@ -733,11 +645,6 @@ ActiveRecord::Schema.define(:version => 20150712194411) do t.integer "profile_id" end - create_table "sashes", :force => true do |t| - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "scraps", :force => true do |t| t.text "content" t.integer "sender_id" diff --git a/script/updatepo/data/pt.upo b/script/updatepo/data/pt.upo index cc89297..364e84f 100644 --- a/script/updatepo/data/pt.upo +++ b/script/updatepo/data/pt.upo @@ -128,8 +128,3 @@ msgid "Saved with success!"# msgstr "Salvo com sucesso!" msgid "Select at least one category"# msgstr "Selecione pelo menos uma categoria" msgid "Task Acceptance"# msgstr "Aceitar Tarefa" msgid "Select an acceptance email template:"# msgstr "Selecionar modelo de email para aceitar:" -msgid "incorrect email format"# msgstr "formato do email inválido. O mesmo só pode ser composto por letras minúsculas, números, '_' e '-'. Adicionalmente não é permitido usar acentuação nem começar com '_' ou '-'" -msgid "incorrect login format"# msgstr "formato do login inválido. O mesmo só pode ser composto por letras minúsculas, números, '_' e '-'. Adicionalmente não é permitido usar acentuação nem começar com '_' ou '-'" -msgid "length must be within 4 to 40 characters"# msgstr "o tamanho do campo deve ser entre 4 e 40 caracteres" -msgid "length must be within 2 to 40 characters"# msgstr "o tamanho do campo deve ser entre 2 e 40 caracteres" -msgid "length must be within 3 to 100 characters"# msgstr "o tamanho do campo deve ser entre 3 e 100 caracteres" diff --git a/test/unit/api/session_test.rb b/test/unit/api/session_test.rb index e83ce61..9b1a64a 100644 --- a/test/unit/api/session_test.rb +++ b/test/unit/api/session_test.rb @@ -39,7 +39,32 @@ class SessionTest < ActiveSupport::TestCase assert json['private_token'].blank? end - should 'do not register a user without email' do + should 'not register a user with invalid login' do + params = {:login => "c", :password => "newuserapi", :password_confirmation => "newuserapi", :email => "newuserapi@email.com" } + post "/api/v1/register?#{params.to_query}" + assert_equal 400, last_response.status + json = JSON.parse(last_response.body) + msg = json['message'].split(':') + key = msg[0][2, 5] + val = msg[1][2, 38] + assert_equal "login", key + assert_equal "is too short (minimum is 2 characters)", val + end + + should 'not register a user with invalid login pt' do + I18n.locale = "pt-BR" + params = {:lang => "pt-BR", :login => "c", :password => "newuserapi", :password_confirmation => "newuserapi", :email => "newuserapi@email.com" } + post "/api/v1/register?#{params.to_query}" + assert_equal 400, last_response.status + json = JSON.parse(last_response.body) + msg = json['message'].split(':') + key = msg[0][2, 5] + val = msg[1][2, 35] + assert_equal "login", key + assert val.include? "muito curto" + end + + should 'not register a user without email' do params = {:login => "newuserapi", :password => "newuserapi", :password_confirmation => "newuserapi", :email => nil } post "/api/v1/register?#{params.to_query}" assert_equal 400, last_response.status -- libgit2 0.21.2