From 90245e7836eb63346b218933af3a4a36333b6404 Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Mon, 11 Oct 2021 10:32:51 +0200 Subject: [PATCH] user --- app/models/user/with_authentication.rb | 9 ++++++++- config/application.rb | 5 +++++ db/schema.rb | 2 +- yarn.lock | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 yarn.lock diff --git a/app/models/user/with_authentication.rb b/app/models/user/with_authentication.rb index 5e77a816e..1ff79412d 100644 --- a/app/models/user/with_authentication.rb +++ b/app/models/user/with_authentication.rb @@ -7,8 +7,9 @@ module User::WithAuthentication has_one_time_password(encrypted: true) - validates_presence_of :email + validates_presence_of :first_name, :last_name, :email validates :role, presence: true + validate :password_complexity validates :mobile_phone, format: { with: /\A\+[0-9]+\z/ }, allow_blank: true before_validation :adjust_mobile_phone, :sanitize_fields @@ -62,5 +63,11 @@ module User::WithAuthentication self.last_name = full_sanitizer.sanitize(self.last_name)&.gsub('=', '') self.mobile_phone = full_sanitizer.sanitize(self.mobile_phone)&.gsub('=', '') end + + def password_complexity + # Regexp extracted from https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a + return if password.blank? || password =~ /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#{Rails.application.config.allowed_special_chars}]).{#{Devise.password_length.first},#{Devise.password_length.last}}$/ + errors.add :password, I18n.t('activerecord.errors.models.user.password.password_strength') + end end end diff --git a/config/application.rb b/config/application.rb index c8b105961..0261f910b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -48,6 +48,11 @@ module Osuny authentication: :plain } + config.action_view.sanitized_allowed_tags = ['strong', 'em', 'b', 'i', 'u', 'p', 'code', 'pre', 'tt', 'samp', 'kbd', 'var', 'sub', 'sup', 'dfn', 'cite', 'big', 'small', 'address', 'hr', 'br', 'div', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'abbr', 'acronym', 'a', 'img', 'blockquote', 'del', 'ins'] + config.action_view.sanitized_allowed_attributes = ['href', 'src', 'srcset', 'width', 'height', 'alt', 'cite', 'datetime', 'title', 'class', 'name', 'xml:lang', 'abbr', 'style', 'target'] + + config.allowed_special_chars = '#?!,@$%^&*+£µ-' + config.generators do |g| g.orm :active_record, primary_key_type: :uuid end diff --git a/db/schema.rb b/db/schema.rb index 6c4146d71..1f77195c1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -213,7 +213,7 @@ ActiveRecord::Schema.define(version: 2021_10_08_152623) do t.uuid "research_journal_id", null: false t.uuid "research_journal_volume_id" t.datetime "created_at", precision: 6, null: false - t.date "updated_at", null: false + t.datetime "updated_at", precision: 6, null: false t.uuid "updated_by_id" t.text "abstract" t.text "references" diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 000000000..fb57ccd13 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + -- GitLab