Skip to content
Snippets Groups Projects
Unverified Commit 9d0cdb23 authored by alihadi-mazeh's avatar alihadi-mazeh Committed by GitHub
Browse files

Userparamlimits (#4056)


* Added upper and lower limits to room names

* Added validations for user name length, email length, password length and presence of language. Also added validations for the same parameters on the front end

* Eslint changes to SignUpFormHelper.jsx

* formatting changes for readability

* Chained validations for name and email. password validation was removed due to issues with rspec validating it

* Rubocop changes

Co-authored-by: default avatarAhmad Farhat <ahmad.af.farhat@gmail.com>
parent f916d0b3
Branches
Tags
No related merge requests found
......@@ -3,9 +3,15 @@ import { yupResolver } from '@hookform/resolvers/yup';
const validationSchema = yup.object({
// TODO: amir - Revisit validations.
name: yup.string().required('Please enter a full name.'),
email: yup.string().required('Please enter an email.').email('Entered value does not match email format.'),
password: yup.string()
name: yup.string().required('Please enter a full name.')
.min(2, 'Name must be at least 2 characters long')
.max(255, 'Name must be at most 255 characters long'),
email: yup.string().required('Please enter an email.').email('Entered value does not match email format.')
.min(6, 'Email must be at least 6 characters long')
.max(255, 'Email must be at most 255 characters long'),
password: yup.string().max(255, 'Password must be at most 255 characters long')
.matches(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[`@%~!#£$\\^&*()\][+={}/|:;"'<>\-,.?_ ]).{8,}$/,
'Password must have at least:',
......
......@@ -22,17 +22,21 @@ class User < ApplicationRecord
enum status: { active: 0, pending: 1, banned: 2 }
validates :name, presence: true # TODO: amir - Change into full_name or seperate first and last name.
validates :name, presence: true,
length: { minimum: 2, maximum: 255 } # TODO: amir - Change into full_name or seperate first and last name.
validates :email,
format: /\A[\w\-.]+@[\w\-.]+\.[a-z]+\z/i,
presence: true,
uniqueness: { case_sensitive: false, scope: :provider }
uniqueness: { case_sensitive: false, scope: :provider },
length: { minimum: 5, maximum: 255 }
validates :provider, presence: true
validates :status, presence: true
validates :password,
presence: true,
on: :create, unless: :external_id?
on: :create, unless: :external_id?,
length: { maximum: 255 }
validates :password,
format: %r{\A(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[`@%~!#£$\\^&*()\]\[+={}/|:;"'<>\-,.?_ ]).{8,}\z},
......@@ -47,6 +51,7 @@ class User < ApplicationRecord
validates :verification_digest, uniqueness: true, if: :verification_digest?
validates :session_token, presence: true, uniqueness: true
validates :session_expiry, presence: true
validates :language, presence: true
validate :check_user_role_provider, if: :role_changed?
......
......@@ -11,8 +11,8 @@ RSpec.describe Room, type: :model do
it { is_expected.to belong_to(:user) }
it { is_expected.to have_many(:recordings).dependent(:destroy) }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_least(2) }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_length_of(:name).is_at_least(2).is_at_most(255) }
# Can't test validation on friendly_id and meeting_id due to before_validations
context 'presentation validations' do
......
......@@ -22,6 +22,10 @@ RSpec.describe User, type: :model do
it { is_expected.to validate_presence_of(:session_token) }
it { is_expected.to validate_presence_of(:session_expiry) }
it { is_expected.to validate_presence_of(:language) }
it { is_expected.to validate_length_of(:name).is_at_least(2).is_at_most(255) }
it { is_expected.to validate_length_of(:email).is_at_least(5).is_at_most(255) }
context 'password complexity' do
it 'passes if there is atleast 1 capital, 1 lowercase, 1 number, 1 symbol' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment