-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from rails-decal/mark/sign-in-with-github
Sign in with GitHub, admin dashboard, users
- Loading branch information
Showing
17 changed files
with
198 additions
and
18 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
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,10 @@ | ||
class Admin::BaseController < ApplicationController | ||
before_action :admin_user | ||
|
||
private | ||
|
||
def admin_user | ||
redirect_to(root_url) unless current_user && current_user.is_staff? | ||
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,6 @@ | ||
class Admin::PagesController < Admin::BaseController | ||
|
||
def dashboard | ||
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,28 @@ | ||
class SessionsController < ApplicationController | ||
|
||
def new | ||
end | ||
|
||
def create_github | ||
user = User.from_omniauth(env['omniauth.auth']) | ||
session[:user_id] = user.id | ||
redirect_to root_url, notice: "Signed in." | ||
end | ||
|
||
def create | ||
user = User.find_by_email(params[:email]) | ||
if user && user.authenticate(params[:password]) | ||
session[:user_id] = user.id | ||
redirect_to root_url, notice: "Logged in!" | ||
else | ||
flash.now.alert = "Email or password is invalid." | ||
redirect_to new_session_path, notice: 'Email or password is invalid' | ||
end | ||
end | ||
|
||
def destroy | ||
session[:user_id] = nil | ||
redirect_to root_url, notice: "Logged out!" | ||
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,14 @@ | ||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
|
||
def github | ||
@user = User.find_for_github_oauth(request.env["omniauth.auth"]) | ||
if @user.persisted? | ||
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated | ||
set_flash_message(:notice, :success, :kind => "GitHub") if is_navigational_format? | ||
else | ||
session["devise.github_data"] = request.env["omniauth.auth"] | ||
redirect_to new_user_registration_url | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class UsersController < ApplicationController | ||
before_filter :user, only: [:show] | ||
|
||
def show | ||
end | ||
|
||
private | ||
|
||
def user | ||
@user = User.find(params[: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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.container | ||
.row | ||
.col-md-12 | ||
h1 Admin Dashboard |
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,6 @@ | ||
.container | ||
.row | ||
.col-md-12 | ||
h1 | ||
= @user.name | ||
| 's profile |
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 @@ | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'] | ||
|
||
OmniAuth.config.logger = Rails.logger | ||
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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
RailsDecal::Application.routes.draw do | ||
devise_for :users | ||
root to: "pages#home" | ||
|
||
match "apply", to: "student_applications#new", via: :get | ||
match "apply", to: "student_applications#create", as: "student_applications", via: :post | ||
|
||
resources :lectures, only: [:show, :index] | ||
|
||
devise_for :users, path: '', | ||
path_names: { sign_in: 'login', sign_up: 'sign-up', sign_out: 'logout'}, | ||
controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } | ||
|
||
resources :users, only: [:show] | ||
|
||
namespace :admin do | ||
match '/', to: redirect('/admin/dashboard'), via: :get | ||
match 'dashboard', to: 'pages#dashboard', via: :get | ||
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,6 @@ | ||
class AddProviderAndUidToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :users, :provider, :string | ||
add_column :users, :uid, :string | ||
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,10 @@ | ||
class AddMoreColumnsToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :users, :name, :string | ||
add_column :users, :nickname, :string | ||
add_column :users, :image_url, :string | ||
add_column :users, :bio, :text | ||
add_column :users, :blog, :string | ||
add_column :users, :location, :string | ||
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