Commit afd86273 by Mai Hoang Thai Ha

add cv field to user, click to download; validate: cv, register, edit info

parent dec3d955
......@@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
def configure_permitted_parameters
devise_parameter_sanitizer.permit :sign_up, keys: %i[name address phone email password]
devise_parameter_sanitizer.permit :account_update, keys: %i[name email address phone password]
devise_parameter_sanitizer.permit :account_update, keys: %i[name email address phone password cv]
end
private
......
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
ACCEPT_CONTENT_TYPE = 'application/pdf, application/msword, application/zip, application/xls, application/xlsx'.freeze
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :confirmable
has_many :apply_jobs, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy
has_many :history_jobs, dependent: :destroy
has_one_attached :cv
validates :cv, content_type: { in: ACCEPT_CONTENT_TYPE,
message: 'must be a valid cv format' },
size:
{ less_than: 5.megabytes,
message: 'should be less than 5MB' }
def update_without_password(params, *options)
if params[:password].blank?
params.delete(:password)
params.delete(:password_confirmation) if params[:password_confirmation].blank?
end
result = update(params, *options)
clean_up_passwords
result
end
protected
def password_required?
......
- provide(:title, 'Forgot password')
.container
.row.justify-content-center
.col-6
h2.text-center.my-5
| Forgot password
= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f|
= render 'users/shared/error_messages', resource: resource
.field.row.form-group.mb-4
.col-2
= f.label :email, class: 'form-label'
.col-10
= f.email_field :email, autofocus: true, autocomplete: 'email', class: 'form-control mb-2'
span.form-msg
- if devise_mapping.confirmable? && controller_name != 'confirmations'
p
= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name), class: 'text-decoration-none'
.actions.row.justify-content-end
.col-10.d-flex.justify-content-center
= f.submit 'Confirm your email', class: 'btn btn-primary w-75 my-4', data: { disable_with: false }
javascript:
Validator({
form: '#new_user',
errorSelector: '.form-msg',
rules: [
Validator.isRequired('#user_email'),
Validator.isEmail('#user_email')
]
})
......@@ -37,6 +37,12 @@
.col-9
= f.text_field :phone, autofocus: true, autocomplete: 'phone', class: 'form-control mb-2'
span.form-msg
.field.row.mb-2.form-group
.col-3
= f.label :cv, class: 'form-label'
.col-9
= f.file_field :cv, accept: ApplyJob::ACCEPT_CONTENT_TYPE, class: 'form-control', direct_upload: true
.row.my-4.justify-content-end
.col-9
hr
......
......@@ -43,20 +43,27 @@
.col-9
= f.password_field :password_confirmation, autocomplete: 'new-password', class: 'form-control mb-2'
span.form-msg
.field.row.mb-2.form-group
.col-3
= f.label :cv, class: 'form-label'
.col-9
= f.file_field :cv, accept: ApplyJob::ACCEPT_CONTENT_TYPE, class: 'form-control', direct_upload: true
.actions.row.justify-content-end
.col-9
= f.submit 'Register', class: 'btn btn-primary w-50 my-4', data: { disable_with: false }
/ javascript:
javascript:
Validator({
form: '#edit_user',
form: '#new_user',
errorSelector: '.form-msg',
rules: [
Validator.isRequired('#user_email'),
Validator.isEmail('#user_email'),
Validator.isRequired('#user_name'),
Validator.isRequired('#user_address'),
Validator.isRequired('#user_phone'),
Validator.isRequired('#user_current_password')
Validator.isRequired('#user_password'),
Validator.isRequired('#user_password_confirmation'),
Validator.isConfirmed('#user_password_confirmation', function () {
return document.querySelector('#new_user #user_password').value;
}, 'password confirmation does not match')
]
})
\ No newline at end of file
......@@ -29,7 +29,6 @@
= f.submit 'Log in', class: 'btn btn-primary w-25', data: { disable_with: false }
= link_to 'Sign up', new_registration_path(resource_name), class: 'text-decoration-none w-25 btn btn-secondary'
javascript:
Validator({
form: '#new_user',
......
......@@ -88,7 +88,15 @@
h6.mb-0 Address
.col-sm-9.text-secondary
= @user.address
hr/
.row
.col-sm-3
h6.mb-0 CV
.col-sm-9.text-secondary
- if @user.cv.attached?
= link_to @user.cv.filename, rails_blob_path(@user.cv, disposition: "attachment")
- else
= 'cv file not uploaded yet'
hr/
.row
.col-sm-12
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment