Skip to content

Commit

Permalink
Company registration and login
Browse files Browse the repository at this point in the history
This is the very beginning part of the company dashboard.
This commit adds the company registration and login and requires login to
register a new job.
  • Loading branch information
duduribeiro committed Feb 21, 2018
1 parent e731f52 commit 22ea341
Show file tree
Hide file tree
Showing 48 changed files with 629 additions and 48 deletions.
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
AllCops:
Exclude:
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'tmp/**/*'
- 'bin/**/*'
- 'node_modules/**/*'
- 'db/**/*'
- 'config/**/*'
TargetRubyVersion: 2.4.2

Metrics/BlockLength:
Expand Down
5 changes: 1 addition & 4 deletions .scss-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ linters:
properties: []

VendorPrefix:
enabled: true
identifier_list: base
additional_identifiers: []
excluded_identifiers: []
enabled: false

ZeroUnit:
enabled: true
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ gem 'summernote-rails'
gem 'turbolinks', '~> 5'
gem 'uglifier', '>= 1.3.0'

# Authentication
gem 'clearance'

# Json generation
gem 'jbuilder', '~> 2.5'

Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ GEM
arel (8.0.0)
ast (2.4.0)
awesome_print (1.7.0)
bcrypt (3.1.11)
bindex (0.5.0)
brakeman (3.6.2)
bugsnag (5.3.2)
Expand All @@ -54,6 +55,10 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
clearance (1.16.1)
bcrypt
email_validator (~> 1.4)
rails (>= 3.1)
code_analyzer (0.4.7)
sexp_processor
coderay (1.1.1)
Expand All @@ -71,6 +76,8 @@ GEM
dotenv-rails (2.2.1)
dotenv (= 2.2.1)
railties (>= 3.2, < 5.2)
email_validator (1.6.0)
activemodel
erubi (1.6.1)
erubis (2.7.0)
execjs (2.7.0)
Expand Down Expand Up @@ -265,6 +272,7 @@ DEPENDENCIES
brakeman
bugsnag
capybara
clearance
coffee-rails (~> 4.2)
dotenv-rails
factory_girl_rails
Expand Down
98 changes: 98 additions & 0 deletions app/assets/stylesheets/_login.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
@import "variables";
$background-color: #fff;
$field-border-color: #ebebeb;
$field-focus-border-color: #dcdcdc;
$selection-background-color: #b5e2e7;
$shadow-color: rgba(0, 0, 0, 0.25);
$title-color: #757575;
$white: #fff;


.other-links {
text-align: center;
}

.sign-box {
background-color: $background-color;
-moz-box-shadow: 0 1px 5px $shadow-color;
-webkit-box-shadow: 0 1px 5px $shadow-color;
box-shadow: 0 1px 5px $shadow-color;
margin: 50px auto;
padding: 10px;
width: 340px;

::selection {
background-color: $selection-background-color;
}

::-moz-selection {
background-color: $selection-background-color;
}

h1 {
color: $title-color;
font-size: 175%;
font-weight: 300;
text-align: center;
}

h1,
input {
font-family: "Open Sans", Helvetica, sans-serif;
}

.field {
border: 0;
border-bottom: 2px solid $field-border-color;
display: block;
height: 50px;
margin: 0 auto 15px;
padding: 0 15px;
width: 75%;
}

.field:focus {
border-bottom-color: $primary-color;
outline: none;
}

.field:hover {
border-bottom-color: $field-focus-border-color;
}

.field:invalid {
box-shadow: none;
}

.field:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px $white inset;
}

.btn-sign {
background-color: $primary-color;
border: 0;
box-shadow: 0 5px 0 $dark-primary-color;
color: $white;
display: block;
height: 50px;
margin: 30px auto;
position: relative;
width: 85%;
}

.btn-sign:hover {
-moz-box-shadow: 0 3px 0 $dark-primary-color;
-webkit-box-shadow: 0 3px 0 $dark-primary-color;
box-shadow: 0 3px 0 $dark-primary-color;
top: 2px;
}

.btn-sign:active {
box-shadow: none;
top: 5px;
}

.btn-sign:focus {
outline: none;
}
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$footer-border-color: #e0e0e0;
$footer-bg-color: #fff;
$footer-heart-color: #e90606;

$primary-color: #ff6f27;
$dark-primary-color: darken($primary-color,15%);
11 changes: 10 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
$icon-font-path: "bootstrap-sass/assets/fonts/bootstrap/";
$error-color: #b94a48;
$error-background-color: #f2dede;

@import "font-awesome-sprockets";
@import "font-awesome";
@import "bootstrap-sass/assets/stylesheets/bootstrap";
@import "summernote";
@import "apply_to_job";
@import "login";
@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,700');

@import "footer";
Expand Down Expand Up @@ -148,7 +151,7 @@ body {
}

.btn-register-vacancy {
background-color:#ff6f27;
background-color: $primary-color;
width: 300px;
height: 35px;
border-radius: 5px;
Expand Down Expand Up @@ -215,3 +218,9 @@ body {
margin-top: 0;
}
}

.error-list {
border: 1px solid $error-color;
color: $error-color;
background-color: $error-background-color;
}
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

# :nodoc:
class ApplicationController < ActionController::Base
include Clearance::Controller
protect_from_forgery with: :exception
end
9 changes: 9 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class UsersController < Clearance::UsersController
private

def user_params
params.require(:user).permit(:email, :password, company_attributes: %i[name url])
end
end
2 changes: 2 additions & 0 deletions app/controllers/vacancies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class VacanciesController < ApplicationController
before_action :require_login, except: %i(index show)

rescue_from ActiveRecord::RecordInvalid, with: :render_new

def index
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: 'no-reply@openjobs.me'
layout 'mailer'
end
9 changes: 9 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class UserMailer < ApplicationMailer
def welcome_email(user)
@user = user

mail(to: user.email, subject: t('.welcome_email.subject'))
end
end
15 changes: 15 additions & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class Company < ApplicationRecord
URL_REGEX = /\A^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$\Z/ix

has_many :users
has_many :vacancies

validates :name, :url, presence: true
validates :url, format: { with: URL_REGEX }

before_validation do
self.url = "http://#{url}" unless url.nil? || url[0, 4] == 'http'
end
end
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class User < ApplicationRecord
include Clearance::User

belongs_to :company

accepts_nested_attributes_for :company
end
14 changes: 3 additions & 11 deletions app/models/vacancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
class Vacancy < ApplicationRecord
include FriendlyId

EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
URL_REGEX = /\A^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$\Z/ix
MAX_VALID_PERIOD = 30.days

friendly_id :slug_candidates, use: :slugged

scope :recent, -> { where('created_at >= ?', MAX_VALID_PERIOD.ago.beginning_of_day).order(created_at: :desc) }

validates :job_title, :location, :description, :how_to_apply, :company_name, :company_url, :company_email,
presence: true
belongs_to :company

validates :company_email, format: { with: EMAIL_REGEX }
validates :company_url, format: { with: URL_REGEX }
scope :recent, -> { where('created_at >= ?', MAX_VALID_PERIOD.ago.beginning_of_day).order(created_at: :desc) }

before_validation do
self.company_url = "http://#{company_url}" unless company_url.nil? || company_url[0, 4] == 'http'
end
validates :job_title, :location, :description, :how_to_apply, presence: true

private

Expand Down
8 changes: 8 additions & 0 deletions app/views/clearance_mailer/change_password.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p><%= t(".opening") %></p>

<p>
<%= link_to t(".link_text", default: "Change my password"),
edit_user_password_url(@user, token: @user.confirmation_token.html_safe) %>
</p>

<p><%= raw t(".closing") %></p>
5 changes: 5 additions & 0 deletions app/views/clearance_mailer/change_password.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= t(".opening") %>
<%= edit_user_password_url(@user, token: @user.confirmation_token.html_safe) %>
<%= raw t(".closing") %>
7 changes: 7 additions & 0 deletions app/views/passwords/create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="clearance" class="sign-up">
<div class="login-container">
<div class="sign-box">
<small><%= t(".description") %></small>
</div>
</div>
</div>
14 changes: 14 additions & 0 deletions app/views/passwords/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div id="clearance" class="sign-up">
<div class="login-container">
<div class="sign-box">
<h1><%= t(".title") %></h1>

<%= form_for :password_reset, url: user_password_path(@user, token: @user.confirmation_token),
html: { method: :put } do |form| %>
<%= form.password_field :password, autofocus: true, class: 'field', placeholder: t('helpers.label.password_reset.password') %>
<%= form.submit class: 'btn btn-sign' %>
<% end %>
</div>
</div>
</div>
15 changes: 15 additions & 0 deletions app/views/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div id="clearance" class="sign-up">
<div class="login-container">
<div class="sign-box">
<h1><%= t(".title") %></h1>

<small><%= t(".description") %></small>

<%= form_for :password, url: passwords_path do |form| %>
<%= form.text_field :email, autofocus: true, class: 'field', type: 'email', placeholder: User.human_attribute_name('email') %>
<%= form.submit class: 'btn btn-sign' %>
<% end %>
</div>
</div>
</div>
20 changes: 20 additions & 0 deletions app/views/sessions/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="login-container">
<div class="sign-box">
<%= form_for :session, url: session_path do |form| %>
<h1><%= title %></h1>

<%= form.text_field :email, autofocus: true, class: 'field', type: 'email', placeholder: User.human_attribute_name('email') %>
<%= form.password_field :password, class: 'field', placeholder: User.human_attribute_name('password') %>
<%= form.submit class: 'btn btn-sign' %>

<div class="other-links">
<% if Clearance.configuration.allow_sign_up? %>
<%= link_to t(".sign_up"), sign_up_path %> |
<% end %>
<%= link_to t(".forgot_password"), new_password_path %>
</div>
<% end %>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="clearance" class="sign-in">
<%= render partial: '/sessions/form', locals: { title: t('.title') } %>
</div>
3 changes: 3 additions & 0 deletions app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="<%= menu_class(root_path) %>"><%= link_to t("menu.all_vacancies"), root_path %></li>
<% if signed_in? %>
<li><%= link_to t(".sign_out"), sign_out_path, method: :delete %></li>
<% end %>
</ul>

<%= form_tag vacancies_path, class: "navbar-form navbar-right", method: :get do %>
Expand Down
Loading

0 comments on commit 22ea341

Please sign in to comment.