Commit 9f74b759 by Bui Minh Duc

implement login feature

parent 9c2d41ac
......@@ -48,6 +48,8 @@ gem 'redcarpet', '~> 3.3', '>= 3.3.4'
gem 'rubocop', '~> 0.46.0'
gem 'sidekiq', '~> 4.2', '>= 4.2.7'
gem 'omniauth-github', '~> 1.1', '>= 1.1.2'
group :development, :test do
gem 'byebug', platform: :mri
end
......
......@@ -72,6 +72,7 @@ GEM
ffi (1.9.14)
globalid (0.3.7)
activesupport (>= 4.1.0)
hashie (3.4.6)
i18n (0.7.0)
jbuilder (2.6.1)
activesupport (>= 3.0.0, < 5.1)
......@@ -80,6 +81,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jwt (1.5.6)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
......@@ -96,13 +98,29 @@ GEM
momentjs-rails (2.15.1)
railties (>= 3.1)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
mysql2 (0.4.5)
nio4r (1.2.1)
nokogiri (1.7.0)
mini_portile2 (~> 2.1.0)
oauth2 (1.3.0)
faraday (>= 0.8, < 0.11)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
octokit (4.6.2)
sawyer (~> 0.8.0, >= 0.5.3)
omniauth (1.3.2)
hashie (>= 1.2, < 4)
rack (>= 1.0, < 3)
omniauth-github (1.1.2)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
parser (2.3.3.1)
ast (~> 2.2)
powerpack (0.1.1)
......@@ -215,6 +233,7 @@ DEPENDENCIES
momentjs-rails (>= 2.9.0)
mysql2 (~> 0.4.5)
octokit (~> 4.6, >= 4.6.2)
omniauth-github (~> 1.1, >= 1.1.2)
puma (~> 3.0)
rails (~> 5.0.0, >= 5.0.0.1)
redcarpet (~> 3.3, >= 3.3.4)
......
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -25,4 +25,8 @@ class ApplicationController < ActionController::Base
false
end
end
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
end
......@@ -26,7 +26,7 @@ class MainController < ApplicationController
@repos = @repos || Repository.all
@selected_repos_name = Other.where(data_type: 0).map{ |other| other.data }
@selected_repos = Repository.where(name: @selected_repos_name).includes(issues: [:labels]).where("issues.closed_at IS NULL AND issues.is_pull IN (?)", type_of_issue_query).references(:issues)
@selected_repos = Repository.where(name: @selected_repos_name).includes(issues: :labels).where("issues.closed_at IS NULL AND issues.is_pull IN (?)", type_of_issue_query).references(:issues)
@data_table = []
@selected_repos.each do |repo|
......
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url, :notice => "Signed in!"
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "Signed out!"
end
end
......@@ -43,7 +43,10 @@ class UsersController < ApplicationController
end
end
# @pulls = Issue.where(user_id: @user.id, is_pull: true)
end
def new
@current_user = current_user
end
end
......@@ -12,4 +12,9 @@ module ApplicationHelper
mm.to_s + " minutes " + ss.to_s + " seconds"
end
end
def current_user
current_user ||= User.find(session[:user_id]) if session[:user_id]
current_user
end
end
module SessionsHelper
end
class Label < ApplicationRecord
belongs_to :repository
has_many :label_repositories
has_many :repositories, through: :label_repositories
has_and_belongs_to_many :issues
end
class LabelRepository < ApplicationRecord
belongs_to :label
belongs_to :repository
end
class Repository < ApplicationRecord
has_many :issues
has_many :labels
has_many :label_repositories
has_many :labels, through: :label_repositories
end
class User < ApplicationRecord
has_and_belongs_to_many :issues
has_many :own_issues, class_name: "Issue", foreign_key: "user_id"
def self.create_with_omniauth(auth)
user = User.find_by(id: auth["uid"])
if user.nil?
user = User.new
user.id = auth["uid"]
user.login = auth["info"]["nickname"]
user.provider = auth["provider"]
end
user.name = auth["info"]["name"]
user.save
user
end
end
......@@ -15,6 +15,20 @@
<li><%= link_to "User", users_path %></li>
<li><%= link_to "Repository", repositories_path %></li>
<li><%= link_to "Settings", settings_path %></li>
<% if current_user %>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<span class="glyphicon glyphicon-user"></span>
<%= current_user.name %>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="<%= signout_path %>"><span class="glyphicon glyphicon-log-out"></span> Log out</a></li>
</ul>
</li>
<% else %>
<li><a href="/auth/github"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
<% end %>
</ul>
</div>
</div>
......
......@@ -6,12 +6,28 @@
<div id="toolbar">
<form class="form-inline">
<div class='input-group date' id='from_date'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<div class='input-group date' id='to_date'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<div class="form-group">
<select class="selectpicker" id="selectpicker1" multiple data-live-search="true" multiple data-selected-text-format="count > 3" data-actions-box="true" style="display: none;">
<% @repo.labels.each do |label| %>
<option><%= label.name %></option>
<% end %>
</select>
</div>
<div class="form-group">
<label>Type</label>
<div class="form-group">
<%= select_tag "type", options_from_collection_for_select(@type, "first", "second", @current_type), { class: "form-control" } %>
<input type="submit" class="btn btn-default">
</div>
<%= select_tag "type", options_from_collection_for_select(@type, "first", "second", @current_type), { class: "form-control" } %>
<input type="submit" class="btn btn-default">
</div>
</form>
</div>
......@@ -60,3 +76,17 @@
</div>
</div>
<script type="text/javascript">
$(document).on('ready', function(event) {
// location.reload();
$('#from_date').datetimepicker({
format: "DD/MM/YYYY",
showClear: true
});
$('#to_date').datetimepicker({
format: "DD/MM/YYYY",
showClear: true
});
});
</script>
<div class="container">
<% if @current_user %>
<h1><%= @current_user.name %></h1>
<% else %>
<%= link_to "Sign in with Github", "/auth/github" %>
<% end %>
</div>
......@@ -74,6 +74,12 @@
<td class="col-md-3"><%= "x 0.5" %></td>
<td class="col-md-3"><%= @score_after[2] * 0.5 %></td>
</tr>
<tr>
<td class="col-md-3">Large</td>
<td class="col-md-3"><%= @score_after[3] %></td>
<td class="col-md-3"><%= "x 1.0" %></td>
<td class="col-md-3"><%= @score_after[3] * 1.0 %></td>
</tr>
<tr style="font-weight: bold">
<td class="col-md-3 text-right">Total Comment (A)</td>
<td class="col-md-3"><%= total_comment @score_after %></td>
......
Rails.application.config.middleware.use OmniAuth::Builder do
provider :github, Rails.application.secrets.GITHUB_KEY, Rails.application.secrets.GITHUB_SECRET, scope: "user:email,user:follow"
end
......@@ -16,4 +16,7 @@ Rails.application.routes.draw do
get "/settings", to: "settings#index"
post "/settings/1", to: "settings#update_setting_1"
get "/auth/:provider/callback" => "sessions#create"
get "/signout" => "sessions#destroy", :as => :signout
end
class RemoveReferenceFromLabel < ActiveRecord::Migration[5.0]
def change
# execute "DROP INDEX index_labels_on_repository_id ON labels"
remove_foreign_key :labels, :repositories
remove_reference :labels, :repository, index: true
end
end
class CreateLabelRepositories < ActiveRecord::Migration[5.0]
def change
create_table :label_repositories do |t|
t.references :label, foreign_key: true
t.references :repository, foreign_key: true
t.timestamps
end
end
end
class AddSomeFieldsToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :provider, :string
add_column :users, :uid, :string
add_column :users, :name, :string
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170116025901) do
ActiveRecord::Schema.define(version: 20170118072055) do
create_table "comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
t.string "html_url"
......@@ -59,15 +59,22 @@ ActiveRecord::Schema.define(version: 20170116025901) do
t.index ["user_id", "issue_id"], name: "index_issues_users_on_user_id_and_issue_id", using: :btree
end
create_table "label_repositories", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
t.integer "label_id"
t.integer "repository_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["label_id"], name: "index_label_repositories_on_label_id", using: :btree
t.index ["repository_id"], name: "index_label_repositories_on_repository_id", using: :btree
end
create_table "labels", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
t.string "url"
t.string "name"
t.string "color"
t.boolean "default"
t.integer "repository_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["repository_id"], name: "index_labels_on_repository_id", using: :btree
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "others", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
......@@ -134,6 +141,9 @@ ActiveRecord::Schema.define(version: 20170116025901) do
t.datetime "updated_at", null: false
t.integer "team_id"
t.boolean "team_ventura"
t.string "provider"
t.string "uid"
t.string "name"
t.index ["team_id"], name: "index_users_on_team_id", using: :btree
end
......@@ -141,7 +151,8 @@ ActiveRecord::Schema.define(version: 20170116025901) do
add_foreign_key "comments", "users"
add_foreign_key "issues", "repositories"
add_foreign_key "issues", "users"
add_foreign_key "labels", "repositories"
add_foreign_key "label_repositories", "labels"
add_foreign_key "label_repositories", "repositories"
add_foreign_key "review_comments", "issues"
add_foreign_key "review_comments", "users"
add_foreign_key "timelines", "issues"
......
......@@ -52,13 +52,20 @@ class GithubLoader
db_label = Label.new
db_label.id = label.id
db_label.url = label.url
# db_label.repository_id = repo.id
end
# db_label.repository_id = repo.id
db_label.name = normalized_label
db_label.color = label.color
db_label.default = label.default
db_label.save
label_repo = LabelRepository.find_by(label_id: db_label.id, repository_id: repo.id)
if label_repo.nil?
label_repo = LabelRepository.new
label_repo.label_id = db_label.id
label_repo.repository_id = repo.id
label_repo.save
end
end
end
end
......
......@@ -40,7 +40,7 @@ namespace :github do
$logger.info "Begin task insert repository"
loader.insert_repos($client)
loader.insert_users($client)
# loader.insert_labels($client)
loader.insert_labels($client)
$logger.info "Finished task insert repository"
end
......
{"files":{"tableExport-c85b00b832b8d61160510f2c23d9cb456a6cd26b0645291bef015eb09901b9e4.js":{"logical_path":"tableExport.js","mtime":"2016-11-29T14:55:01+07:00","size":15512,"digest":"c85b00b832b8d61160510f2c23d9cb456a6cd26b0645291bef015eb09901b9e4","integrity":"sha256-yFsAuDK41hFgUQ8sI9nLRWps0msGRSkb7wFesJkBueQ="},"application-5909bd6132b05f0ce11cbe2c603a15625db4513a023a59b81c2f70f6bd02d05a.js":{"logical_path":"application.js","mtime":"2017-01-12T16:08:57+07:00","size":830837,"digest":"5909bd6132b05f0ce11cbe2c603a15625db4513a023a59b81c2f70f6bd02d05a","integrity":"sha256-WQm9YTKwXwzhHL4sYDoVYl20UToCOlm4HC9w9r0C0Fo="},"application-c638f7a2d2650026bed6288ee69348d190e1c2409d17d921a78ba31faa8cd693.css":{"logical_path":"application.css","mtime":"2017-01-12T16:08:57+07:00","size":765136,"digest":"c638f7a2d2650026bed6288ee69348d190e1c2409d17d921a78ba31faa8cd693","integrity":"sha256-xjj3otJlACa+1iiO5pNI0ZDhwkCdF9khp4ujH6qM1pM="},"bootstrap/glyphicons-halflings-regular-13634da87d9e23f8c3ed9108ce1724d183a39ad072e73e1b3d8cbf646d2d0407.eot":{"logical_path":"bootstrap/glyphicons-halflings-regular.eot","mtime":"2016-12-28T09:30:09+07:00","size":20127,"digest":"13634da87d9e23f8c3ed9108ce1724d183a39ad072e73e1b3d8cbf646d2d0407","integrity":"sha256-E2NNqH2eI/jD7ZEIzhck0YOjmtBy5z4bPYy/ZG0tBAc="},"bootstrap/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2":{"logical_path":"bootstrap/glyphicons-halflings-regular.woff2","mtime":"2016-12-28T09:30:09+07:00","size":18028,"digest":"fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c","integrity":"sha256-/hhdEaSWdokNR7t4MxKgzaWkTEA5IUCU55V7TAQO8Rw="},"bootstrap/glyphicons-halflings-regular-a26394f7ede100ca118eff2eda08596275a9839b959c226e15439557a5a80742.woff":{"logical_path":"bootstrap/glyphicons-halflings-regular.woff","mtime":"2016-12-28T09:30:09+07:00","size":23424,"digest":"a26394f7ede100ca118eff2eda08596275a9839b959c226e15439557a5a80742","integrity":"sha256-omOU9+3hAMoRjv8u2ghZYnWpg5uVnCJuFUOVV6WoB0I="},"bootstrap/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf":{"logical_path":"bootstrap/glyphicons-halflings-regular.ttf","mtime":"2016-12-28T09:30:09+07:00","size":45404,"digest":"e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456","integrity":"sha256-45UEQJN1fYKvyxOJV9BqHqk2G9zwtELQahioBRr1dFY="},"bootstrap/glyphicons-halflings-regular-42f60659d265c1a3c30f9fa42abcbb56bd4a53af4d83d316d6dd7a36903c43e5.svg":{"logical_path":"bootstrap/glyphicons-halflings-regular.svg","mtime":"2016-12-28T09:30:09+07:00","size":108738,"digest":"42f60659d265c1a3c30f9fa42abcbb56bd4a53af4d83d316d6dd7a36903c43e5","integrity":"sha256-QvYGWdJlwaPDD5+kKry7Vr1KU69Ng9MW1t16NpA8Q+U="}},"assets":{"tableExport.js":"tableExport-c85b00b832b8d61160510f2c23d9cb456a6cd26b0645291bef015eb09901b9e4.js","application.js":"application-5909bd6132b05f0ce11cbe2c603a15625db4513a023a59b81c2f70f6bd02d05a.js","application.css":"application-c638f7a2d2650026bed6288ee69348d190e1c2409d17d921a78ba31faa8cd693.css","bootstrap/glyphicons-halflings-regular.eot":"bootstrap/glyphicons-halflings-regular-13634da87d9e23f8c3ed9108ce1724d183a39ad072e73e1b3d8cbf646d2d0407.eot","bootstrap/glyphicons-halflings-regular.woff2":"bootstrap/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2","bootstrap/glyphicons-halflings-regular.woff":"bootstrap/glyphicons-halflings-regular-a26394f7ede100ca118eff2eda08596275a9839b959c226e15439557a5a80742.woff","bootstrap/glyphicons-halflings-regular.ttf":"bootstrap/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf","bootstrap/glyphicons-halflings-regular.svg":"bootstrap/glyphicons-halflings-regular-42f60659d265c1a3c30f9fa42abcbb56bd4a53af4d83d316d6dd7a36903c43e5.svg"}}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
require 'test_helper'
class SessionsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
label: one
repository: one
two:
label: two
repository: two
require 'test_helper'
class LabelRepositoryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
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