forked from jcnetdev/jobberrails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added jobs management in admin panel and simple authentication system
- Loading branch information
Showing
43 changed files
with
532 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Admin::CategoriesController < ApplicationController | ||
before_filter :login_required | ||
layout 'admin' | ||
|
||
# GET /admin/jobs/1 | ||
def show | ||
@category = Category.find_by_value(params[:id]) | ||
@jobs = @category.jobs.find_all_by_is_active(true, :order => "created_at DESC") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class Admin::JobsController < ApplicationController | ||
before_filter :login_required | ||
layout 'admin' | ||
|
||
# GET /admin/jobs | ||
def index | ||
@jobs = Job.find_all_by_is_active(false, :order => 'updated_at DESC') | ||
end | ||
|
||
# GET /admin/jobs/1 | ||
def show | ||
@job = Job.find(params[:id]) | ||
end | ||
|
||
# PUT /admin/jobs/1 | ||
def update | ||
@job = Job.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @job.update_attributes(:is_active => @job.is_active ? false : true) | ||
format.html { redirect_to admin_jobs_url } | ||
format.js # admin/jobs/update.js.rjs | ||
end | ||
end | ||
end | ||
|
||
# DELETE /admin/jobs/1 | ||
def destroy | ||
@job = Job.find(params[:id]) | ||
@job.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to admin_jobs_url } | ||
format.js # admin/jobs/destroy.js.rjs | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class SessionsController < ApplicationController | ||
layout 'admin' | ||
|
||
def new | ||
if session[:admin] | ||
redirect_to admin_url | ||
end | ||
end | ||
|
||
def create | ||
admin = Admin.authenticate(params[:login], params[:password]) | ||
if admin | ||
session[:admin] = admin | ||
flash[:notice] = "You are logged as #{admin.login}" | ||
redirect_to admin_url | ||
else | ||
flash[:error] = "Invalid login or password!" | ||
render :action => :new | ||
end | ||
end | ||
|
||
def destroy | ||
reset_session | ||
flash[:notice] = "You've been logged out." | ||
redirect_to login_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Admin::CategoriesHelper | ||
def admin_category_nav_item(category) | ||
category_nav_item(category, true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Admin::JobsHelper | ||
def activation_image_tag(job) | ||
activate = "activate" | ||
unless job.is_active | ||
activate = "de" + activate | ||
end | ||
image_tag("icon_#{activate}.gif", :alt => activate.capitalize, :id => "activate_#{job.id}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module SessionsHelper | ||
# checks if user is logged in | ||
def logged_in? | ||
session[:admin] ? true : false | ||
end | ||
|
||
# returns currently logged admin | ||
def current_user | ||
session[:admin] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'digest/sha1' | ||
|
||
class Admin < ActiveRecord::Base | ||
validates_length_of :login, :within => 3..40 | ||
validates_length_of :password, :within => 5..40 | ||
validates_presence_of :login, :password | ||
validates_uniqueness_of :login | ||
|
||
attr_protected :id | ||
|
||
def self.authenticate(login, pass) | ||
a = find_by_login(login) | ||
a && Admin.encrypt(pass) == a.password ? a : nil | ||
end | ||
|
||
protected | ||
def self.encrypt(pass) | ||
Digest::SHA1.hexdigest(pass) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#categories | ||
%ul | ||
- Category.list.each do |category| | ||
= admin_category_nav_item(category) | ||
= clear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.job-listings | ||
%h2= "Jobs for " + @category.name.pluralize | ||
= partial "admin/jobs/jobs_table", :jobs => @jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
- unless jobs.empty? | ||
-# Display Job Posts | ||
%table.job-posts{:cellspacing => 0} | ||
- jobs.each do |job| | ||
%tr.job_item{:id => "job_" + job.id.to_s} | ||
%td | ||
= job_type_image(job.job_type) | ||
= link_to job.title, admin_job_url(job), :title => job.title | ||
%span.la at | ||
= job_location_text(job) | ||
|
||
-# display time | ||
%td.time-posted | ||
= image_tag "clock.gif", :class => "vert-middle" | ||
= job.created_at.to_s(:job_listing) | ||
|
||
%td{:style => 'text-align:left;width:15%'} | ||
-# activate/deactivate link | ||
= link_to_remote(activation_image_tag(job), :url => admin_job_url(job.id), :method => :put) | ||
-# delete link | ||
= link_to_remote(image_tag("icon-delete.png", :alt => 'Delete'), :url => admin_job_url(job.id), :confirm => 'Are you sure you want to delete this post?', :method => :delete) | ||
|
||
- else | ||
#no-ads No jobs, yet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
page["job_#{@job.id}"].visual_effect :fade, "job_#{@job.id}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
%h2 Inactive jobs | ||
= partial "admin/jobs/jobs_table", :jobs => @jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
- if @job | ||
= br | ||
= link_to '« go back', admin_category_url(@job.category) | ||
#job_details | ||
-# display job outdated warning if applicable | ||
- if @job.created_at < 40.days.ago | ||
.old-ad | ||
This job ad has been posted over 40 days ago... | ||
|
||
-# show applicants count | ||
.applied-to-job | ||
= @job.job_applicants.size | ||
%p | ||
- if @job.job_applicants.size != 1 | ||
applicants | ||
- else | ||
applicant | ||
|
||
-# show job title | ||
%h2 | ||
= job_type_image(@job.job_type) | ||
= @job.title | ||
|
||
-# show job location | ||
%p | ||
%span.fading at | ||
- unless @job.url.blank? or @job.url == "http://" | ||
= link_to @job.company, @job.url | ||
- else | ||
%strong= @job.company | ||
|
||
- if @job.located_at == "Anywhere" | ||
%strong= "(" + @job.located_at + ")" | ||
- else | ||
%span.fading in | ||
%strong= @job.located_at | ||
|
||
-# show job description | ||
.job-description | ||
= @job.description_html | ||
= br | ||
|
||
#job_bottom | ||
#number_views | ||
Published at: | ||
%strong= @job.created_at.to_s(:post_listing_date) | ||
= br | ||
Viewed: | ||
%strong= pluralize(@job.view_count, "time") | ||
= clear | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
page.replace "activate_#{@job.id}", activation_image_tag(@job) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#header | ||
%h1#logo= link_to AppConfig.site_name, root_path | ||
- if logged_in? | ||
%ul#top | ||
%li= link_to "Pages", "#" | ||
= bull | ||
%li= link_to "Categories", "#" | ||
= bull | ||
%li= link_to "Change your password", "#" | ||
= bull | ||
%li= link_to "Logout", logout_path | ||
|
||
= partial "layouts/flash_boxes" | ||
|
||
- unless logged_in? | ||
#categs-nav |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
!!! Strict | ||
%html{html_attrs} | ||
%head | ||
%meta{"http-equiv" => "Content-type", "content" => "text/html; charset=utf-8"} | ||
= title :site => AppConfig.site_name | ||
= stylesheets | ||
= javascripts | ||
= feed_links | ||
%body | ||
#container | ||
= partial "layouts/admin_header" | ||
- if logged_in? | ||
= partial "admin/categories/list" | ||
#content | ||
= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.login_status | ||
- if logged_in? | ||
= "You are logged as #{current_user.login} " + link_to('Logout', logout_path) | ||
- else | ||
= link_to 'Login', login_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- form_tag session_path, :id => 'publish_form' do | ||
%fieldset | ||
%legend Login | ||
%table{:border => 0, :cellspacing => 2, :cellpadding => 2} | ||
%tr | ||
%td.publish-label Username: | ||
%td= text_field_tag :login, params[:login], :size => 40 | ||
%tr | ||
%td.publish-label Password: | ||
%td= password_field_tag :password, params[:password], :size => 40 | ||
%fieldset | ||
= submit_tag 'Login', :id => 'submit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Admin.seed(:login, :password) do |s| | ||
s.login = 'admin' | ||
s.password = 'd033e22ae348aeb5660fc2140aec35850c4da997' # admin | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateAdmins < ActiveRecord::Migration | ||
def self.up | ||
create_table :admins do |t| | ||
t.string :login | ||
t.string :password | ||
|
||
t.timestamps | ||
end | ||
|
||
end | ||
|
||
def self.down | ||
drop_table :admins | ||
end | ||
end |
Oops, something went wrong.