Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Commit c388cc3

Browse files
committed
implement user management
1 parent 3ef0142 commit c388cc3

32 files changed

+697
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
/log/*
1616
!/log/.keep
1717
/tmp
18+
.byebug_history

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ gem 'puma'
3535
gem 'pg'
3636
gem 'redis'
3737
gem 'sinatra', :require => false
38-
38+
gem 'devise'
3939
gem 'rollbar'
40+
gem 'devise-bootstrap-views'
4041

4142
# Use ActiveModel has_secure_password
4243
# gem 'bcrypt', '~> 3.1.7'

Gemfile.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ GEM
5050
arel (6.0.3)
5151
autoprefixer-rails (6.4.1)
5252
execjs
53+
bcrypt (3.1.11)
5354
binding_of_caller (0.7.2)
5455
debug_inspector (>= 0.0.1)
5556
bootstrap (4.0.0.alpha3.1)
@@ -67,6 +68,13 @@ GEM
6768
concurrent-ruby (1.0.2)
6869
connection_pool (2.2.0)
6970
debug_inspector (0.0.2)
71+
devise (4.2.0)
72+
bcrypt (~> 3.0)
73+
orm_adapter (~> 0.1)
74+
railties (>= 4.1.0, < 5.1)
75+
responders
76+
warden (~> 1.2.3)
77+
devise-bootstrap-views (0.0.9)
7078
domain_name (0.5.20160826)
7179
unf (>= 0.0.5, < 1.0.0)
7280
erubis (2.7.0)
@@ -106,6 +114,7 @@ GEM
106114
newrelic_rpm (3.15.2.317)
107115
nokogiri (1.6.8.1)
108116
mini_portile2 (~> 2.1.0)
117+
orm_adapter (0.5.0)
109118
pg (0.18.4)
110119
puma (3.4.0)
111120
rack (1.6.4)
@@ -142,6 +151,8 @@ GEM
142151
rdoc (4.2.2)
143152
json (~> 1.4)
144153
redis (3.3.1)
154+
responders (2.3.0)
155+
railties (>= 4.2.0, < 5.1)
145156
rollbar (2.8.3)
146157
multi_json
147158
sass (3.4.22)
@@ -185,6 +196,8 @@ GEM
185196
unf (0.1.4)
186197
unf_ext
187198
unf_ext (0.0.7.2)
199+
warden (1.2.6)
200+
rack (>= 1.0)
188201
web-console (2.3.0)
189202
activemodel (>= 4.0)
190203
binding_of_caller (>= 0.7.2)
@@ -199,6 +212,8 @@ DEPENDENCIES
199212
bootstrap (~> 4.0.0.alpha3.1)
200213
byebug
201214
coffee-rails (~> 4.1.0)
215+
devise
216+
devise-bootstrap-views
202217
highcharts-rails
203218
jbuilder (~> 2.0)
204219
jquery-rails

app/assets/javascripts/scans.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ $(function () {
33

44
function fetch_analytics() {
55
var sid = $('#vulnerability-container').data('scan')
6+
if (sid == undefined) {
7+
return;
8+
}
9+
610
$.ajax({
711
url: '/scan/' + sid + '/vulnerabilities/chart',
812
method: 'GET',

app/assets/stylesheets/application.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
1111
* file per style scope.
1212
*
13+
*= require devise_bootstrap_views
1314
*= require_tree .
1415
*= require_self
1516
*/
1617

17-
@import "bootstrap";
18+
@import "bootstrap";

app/controllers/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ class ApplicationController < ActionController::Base
22
# Prevent CSRF attacks by raising an exception.
33
# For APIs, you may want to use :null_session instead.
44
protect_from_forgery with: :exception
5+
before_action :authenticate_user!
56
end

app/controllers/scans_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class ScansController < ApplicationController
33
before_action :load_scan, only: [:show, :vulnerability_chart]
44

55
def index
6+
@scans = current_user.scans
67
end
78

89
def show
@@ -24,7 +25,7 @@ def create
2425
cookies: headers, # rename column to headers
2526
json: json
2627
}
27-
@scan = Scan.create!(options)
28+
@scan = current_user.scans.create!(options)
2829

2930
headers, cookies = headers_parser(headers)
3031
job_options = {

app/models/scan.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class Scan < ActiveRecord::Base
22
has_many :vulnerabilities
3+
belongs_to :user
34
end

app/models/user.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class User < ActiveRecord::Base
2+
# Include default devise modules. Others available are:
3+
# :confirmable, :lockable, :timeoutable and :omniauthable
4+
devise :database_authenticatable, :registerable,
5+
:recoverable, :rememberable, :trackable, :validatable
6+
7+
has_many :scans
8+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<%= bootstrap_devise_error_messages! %>
2+
<div class="panel panel-default devise-bs">
3+
<div class="panel-heading">
4+
<h4><%= t('.resend_confirmation_instructions', :default => 'Resend confirmation instructions') %></h4>
5+
</div>
6+
<div class="panel-body">
7+
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post, role: "form" }) do |f| %>
8+
<div class="form-group">
9+
<%= f.label :email %>
10+
<%= f.email_field :email, autofocus: true, class: "form-control" %>
11+
</div>
12+
13+
<%= f.submit t('.resend_confirmation_instructions', :default => 'Resend confirmation instructions'), class: "btn btn-primary" %>
14+
<% end %>
15+
</div>
16+
</div>
17+
18+
<%= render "devise/shared/links" %>

0 commit comments

Comments
 (0)