Commit 127448dd by Tô Ngọc Ánh

admin login

parent 1b7a0aa8
......@@ -26,6 +26,8 @@ class Users::SessionsController < Devise::SessionsController
# end
def after_sign_in_path_for(resource)
stored_location_for(resource) || my_page_path
default_path = resource.admin ? admin_applied_jobs_path : my_page_path
stored_location = stored_location_for(resource)
stored_location == root_path ? default_path : stored_location
end
end
class UsersController < ApplicationController
before_action :authenticate_user!, only: :my_page
before_action :authenticate_user!, only: %i[my_page applied_job]
def show
@user = User.find_by(id: params[:id])
end
def my_page; end
def applied_jobs
return unless current_user.admin
@applied_jobs = AppliedJob.includes(:jobs).order(created_at: :desc).page(params[:page])
end
end
day la admin applied job
\ No newline at end of file
Rails.application.routes.draw do
root to: 'home#index'
devise_for :users, controllers: { sessions: 'users/sessions', registrations: 'users/registrations' }
devise_scope :user do
get 'admin/login', to: 'users/sessions#new', as: :admin_login
end
get 'admin/applies', to: 'users#applied_jobs', as: :admin_applied_jobs
get 'cities', to: 'locations#index'
get 'industries', to: 'industries#index'
......
class ChangeAdminDefaultInUsers < ActiveRecord::Migration[5.2]
def change
change_column_default :users, :admin, from: nil, to: false
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_08_07_062519) do
ActiveRecord::Schema.define(version: 2020_09_07_013824) do
create_table "applied_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.bigint "user_id"
......@@ -103,7 +103,7 @@ ActiveRecord::Schema.define(version: 2020_08_07_062519) do
t.string "email"
t.string "full_name"
t.string "curriculum_vitae"
t.boolean "admin"
t.boolean "admin", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "encrypted_password", default: "", null: false
......
......@@ -5,3 +5,7 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
admin = User.new(email: 'admin@venjob.com', full_name: 'admin', password: '123456789', admin: true)
admin.skip_confirmation!
admin.save
......@@ -5,17 +5,17 @@ module Crawler
def initialize(logger)
@logger = logger
end
def crawl_data(page_number, base_link)
crawl_industries_locations
job_links = get_job_links(page_number, base_link)
job_links.each do |link|
next if link.empty?
crawl_job(link)
end
end
def get_job_links(page_number, link)
job_links = []
page_number.times do
......@@ -24,21 +24,21 @@ module Crawler
jobs_xml.each { |item| job_links << item.value }
next_page = document.at_css('.next-page a')
break if next_page.nil?
link = next_page[:href]
end
job_links
end
def crawl_company(company_link)
uri = URI.parse(URI.escape(company_link)) # fix error: uri must be ascii only
document = Nokogiri::HTML(URI.open(uri))
company_name = document.css('.content .name').text
return if company_name.empty?
company_address = document.css('.content p')[1].text
company_description = document.css('.main-about-us').css('.content').text
Company.find_or_create_by(name: company_name) do |company|
company.address = company_address
company.description = company_description
......@@ -46,30 +46,30 @@ module Crawler
rescue StandardError => e
@logger.error "#{e.message} - Company link: #{uri}"
end
def crawl_job(job_link)
uri = URI.parse(URI.escape(job_link)) # fix error: uri must be ascii only
document = Nokogiri::HTML(URI.open(uri))
job_title = document.at_css('.job-desc p.title').text
return if job_title.empty?
job_company_link = document.at_css('.job-desc a.job-company-name')[:href]
job_company = crawl_company(job_company_link)
return if job_company.nil?
job_location_name = document.css('.map p a').map { |val| val.text.strip }
job_locations = Location.where(city: job_location_name)
job_industry_names = document.at_xpath('//li[./strong/em[contains(@class, "mdi mdi-briefcase")]]').css('p a').map { |val| val.text.strip }
job_industries = Industry.where(name: job_industry_names)
job_salary = document.at_xpath('//li[./strong/i[contains(@class, "fa fa-usd")]]/p').try(:text).try(:strip)
job_level = document.at_xpath('//li[./strong/i[contains(@class, "mdi mdi-account")]]/p').try(:text).try(:strip)
job_experience = document.at_xpath('//li[./strong/i[contains(@class, "fa fa-briefcase")]]/p').try(:text).try(:strip)
job_exp_date = document.at_xpath('//li[./strong/i[contains(@class, "mdi mdi-calendar-check")]]/p').try(:text).try(:strip)
job_description = document.css('.job-detail-content .detail-row').to_s
Job.find_or_create_by(title: job_title,
company_id: job_company.id,
level: job_level,
......@@ -83,22 +83,22 @@ module Crawler
rescue StandardError => e
@logger.error "#{e.message} - Job link: #{uri}"
end
def crawl_industries_locations
document = Nokogiri::HTML(URI.open('https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html'))
industries = document.css('#industry option').map(&:text)
locations = document.css('#location option').map(&:text)
industries.each do |val|
Industry.find_or_create_by(name: val)
end
locations.take(Location::CITY_VIETNAM_NUMBER).each do |val|
Location.find_or_create_by(city: val) do |location|
location.oversea = false
end
end
locations.last(locations.count - Location::CITY_VIETNAM_NUMBER).each do |val|
Location.find_or_create_by(city: val) do |location|
location.oversea = true
......
......@@ -11,9 +11,9 @@ class SolrServer
private
def set_query_search(search_params)
industry_id = search_params[:industry].blank? ? "*" : RSolr.solr_escape(search_params[:industry])
location_id = search_params[:location].blank? ? "*" : RSolr.solr_escape(search_params[:location])
keyword = search_params[:search].blank? ? "*" : RSolr.solr_escape(search_params[:search])
industry_id = search_params[:industry].blank? ? '*' : RSolr.solr_escape(search_params[:industry])
location_id = search_params[:location].blank? ? '*' : RSolr.solr_escape(search_params[:location])
keyword = search_params[:search].blank? ? '*' : RSolr.solr_escape(search_params[:search])
query = "title:(#{keyword}) OR company:(#{keyword})"
fq = ["industry_ids:#{industry_id}", "location_ids:#{location_id}"]
[query, fq]
......
......@@ -7,6 +7,7 @@ namespace :delete_record do
.having("count(histories.id) > #{History::NUMBER_STORED_HISTORIES}")
users.each do |user|
break if user.histories.size <= History::NUMBER_STORED_HISTORIES
lastest = user.histories.order(updated_at: :desc).take(History::NUMBER_STORED_HISTORIES).pluck(:id)
user.histories.where.not(id: lastest).delete_all
end
......
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