authentication via google
This commit is contained in:
parent
b407d40747
commit
0cefdaf15c
@ -27,7 +27,6 @@ Style/StringLiterals:
|
||||
Metrics/AbcSize:
|
||||
Exclude:
|
||||
- db/migrate/**/*
|
||||
- app/controllers/oauths_controller.rb
|
||||
|
||||
Metrics/LineLength:
|
||||
Max: 95
|
||||
@ -40,4 +39,3 @@ Metrics/LineLength:
|
||||
Metrics/MethodLength:
|
||||
Exclude:
|
||||
- db/migrate/*
|
||||
- app/controllers/oauths_controller.rb
|
||||
|
@ -2,6 +2,12 @@ class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
before_filter :require_login
|
||||
respond_to :html, :json
|
||||
|
||||
private
|
||||
|
||||
def not_authenticated
|
||||
redirect_to :root, alert: "Please login first."
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,6 @@
|
||||
class DocsController < ApplicationController
|
||||
skip_before_filter :require_login
|
||||
|
||||
def index
|
||||
@doc = {
|
||||
name: "sms-pager",
|
||||
|
@ -12,19 +12,20 @@ class OauthsController < ApplicationController
|
||||
if @user
|
||||
redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
|
||||
else
|
||||
begin
|
||||
@user = create_from(provider)
|
||||
reset_session # protect from session fixation attack
|
||||
auto_login(@user)
|
||||
redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
|
||||
rescue
|
||||
redirect_to root_path, alert: "Failed to login from #{provider.titleize}!"
|
||||
end
|
||||
msg = "Your account must be pre-approved. Please contact the administrator."
|
||||
redirect_to root_path, notice: msg
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# def create_and_login provider
|
||||
# @user = create_from(provider)
|
||||
# reset_session # protect from session fixation attack
|
||||
# auto_login(@user)
|
||||
# redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
|
||||
# end
|
||||
|
||||
def auth_params
|
||||
params.permit(:code, :provider)
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
%p= link_to 'Login with Google', auth_at_provider_path(provider: :google)
|
||||
|
||||
%h2 Something more helpful later
|
||||
%p= raw(ap @doc)
|
||||
-#
|
||||
%h2 Something more helpful later
|
||||
%p= raw(ap @doc)
|
||||
|
@ -1 +1 @@
|
||||
= yield
|
||||
= yield
|
||||
|
@ -130,8 +130,8 @@ Rails.application.config.sorcery.configure do |config|
|
||||
|
||||
config.google.key = ENV["google_key"]
|
||||
config.google.secret = ENV["google_secret"]
|
||||
config.google.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=google"
|
||||
config.google.user_info_mapping = { email: "email", username: "name" }
|
||||
config.google.callback_url = "http://localhost:3000/oauth/callback?provider=google"
|
||||
config.google.user_info_mapping = { email: "email" }
|
||||
|
||||
# config.vk.key = ""
|
||||
# config.vk.secret = ""
|
||||
|
@ -1,6 +1,14 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ParentsControllerTest < ActionController::TestCase
|
||||
include Sorcery::TestHelpers::Rails::Integration
|
||||
include Sorcery::TestHelpers::Rails::Controller
|
||||
|
||||
def setup
|
||||
@admin = people(:admin)
|
||||
login_user(@admin)
|
||||
end
|
||||
|
||||
def test_parents
|
||||
get :index
|
||||
assert response.ok?
|
||||
|
Loading…
Reference in New Issue
Block a user