Commit c16cff12 authored by Vasily Gotovko's avatar Vasily Gotovko

Use old style for hash

parent acc9a34d
......@@ -6,21 +6,21 @@ class RedmineOauthController < AccountController
include Helpers::Checker
def oauth_google
if Setting.plugin_redmine_omniauth_google[:oauth_authentification]
redirect_to oauth_client.auth_code.authorize_url(redirect_uri: oauth_google_callback_url, scope: scopes)
redirect_to oauth_client.auth_code.authorize_url(:redirect_uri => oauth_google_callback_url, :scope => scopes)
else
password_authentication
end
end
def oauth_google_callback
token = oauth_client.auth_code.get_token(params[:code], redirect_uri: oauth_google_callback_url)
token = oauth_client.auth_code.get_token(params[:code], :redirect_uri => oauth_google_callback_url)
result = token.get('https://www.googleapis.com/oauth2/v1/userinfo')
info = JSON.parse(result.body)
if info && info["verified_email"]
if allowed_domain_for?(info["email"])
try_to_login info
else
flash[:error] = l(:notice_domain_not_allowed, domain: parse_email(info["email"])[:domain])
flash[:error] = l(:notice_domain_not_allowed, :domain => parse_email(info["email"])[:domain])
redirect_to signin_path
end
else
......@@ -70,9 +70,9 @@ class RedmineOauthController < AccountController
def oauth_client
@client ||= OAuth2::Client.new(settings[:client_id], settings[:client_secret],
site: 'https://accounts.google.com',
authorize_url: '/o/oauth2/auth',
token_url: '/o/oauth2/token')
:site => 'https://accounts.google.com',
:authorize_url => '/o/oauth2/auth',
:token_url => '/o/oauth2/token')
end
def settings
......@@ -82,4 +82,4 @@ class RedmineOauthController < AccountController
def scopes
'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
end
end
\ No newline at end of file
end
<%= stylesheet_link_tag 'buttons', plugin: 'redmine_omniauth_google' %>
<%= stylesheet_link_tag 'buttons', :plugin => 'redmine_omniauth_google' %>
<% if Setting.plugin_redmine_omniauth_google[:oauth_authentification] %>
<%= link_to oauth_google_path do %>
<%= button_tag class: 'button-login' do %>
<%= image_tag('/plugin_assets/redmine_omniauth_google/images/google_login_icon.png', class: 'button-login-icon', alt: l(:login_via_google)) %>
<%= content_tag :div, l(:login_via_google), class: 'button-login-text' %>
<%= button_tag :class => 'button-login' do %>
<%= image_tag('/plugin_assets/redmine_omniauth_google/images/google_login_icon.png', :class => 'button-login-icon', :alt => l(:login_via_google)) %>
<%= content_tag :div, l(:login_via_google), :class => 'button-login-text' %>
<% end %>
<% end %>
<% end %>
......@@ -8,9 +8,9 @@
</p>
<p>
<label>Available domains</label>
<%= text_area_tag "settings[allowed_domains]", @settings[:allowed_domains], rows: 5 %>
<%= text_area_tag "settings[allowed_domains]", @settings[:allowed_domains], :rows => 5 %>
</p>
<p>
<label>Oauth authentification:</label>
<%= check_box_tag "settings[oauth_authentification]", true, @settings[:oauth_authentification] %>
</p>
\ No newline at end of file
</p>
# English strings go here for Rails i18n
en:
notice_unable_to_obtain_google_credentials: "Unable to obtain credentials from Google."
notice_domain_not_allowed: "You can not login using %{domain} domain."
login_via_google: "Login via Google"
\ No newline at end of file
login_via_google: "Login via Google"
get 'oauth_google', to: 'redmine_oauth#oauth_google'
get 'oauth2callback', to: 'redmine_oauth#oauth_google_callback', as: 'oauth_google_callback'
get 'oauth_google', :to => 'redmine_oauth#oauth_google'
get 'oauth2callback', :to => 'redmine_oauth#oauth_google_callback', :as => 'oauth_google_callback'
......@@ -9,10 +9,10 @@ Redmine::Plugin.register :redmine_omniauth_google do
url 'https://github.com/twinslash/redmine_omniauth_google'
author_url 'http://twinslash.com'
settings default: {
client_id: "",
client_secret: "",
oauth_autentification: false,
allowed_domains: ""
}, partial: 'settings/google_settings'
settings :default => {
:client_id => "",
:client_secret => "",
:oauth_autentification => false,
:allowed_domains => ""
}, :partial => 'settings/google_settings'
end
......@@ -2,7 +2,7 @@ module Helpers
module MailHelper
def parse_email email
email_data = email && email.is_a?(String) ? email.match(/(.*?)@(.*)/) : nil
{login: email_data[1], domain: email_data[2]} if email_data
{:login => email_data[1], :domain => email_data[2]} if email_data
end
end
end
\ No newline at end of file
end
module Hooks
class ViewAccountLoginBottomHook < Redmine::Hook::ViewListener
def view_account_login_bottom context = {}
def view_account_login_bottom(context = {})
context[:controller].send(:render_to_string, {
partial: "hooks/view_account_login_bottom",
locals: context
})
:partial => "hooks/view_account_login_bottom",
:locals => context})
end
end
end
\ No newline at end of file
end
......@@ -3,18 +3,18 @@ require File.expand_path('../../test_helper', __FILE__)
class RedmineOauthControllerTest < ActionController::TestCase
include Helpers::MailHelper
def setup
@default_user_credentials = { firstname: 'Cool',
lastname: 'User',
mail: 'user@somedomain.com'}
@default_response_body = {verified_email: true,
name: 'Cool User',
given_name: 'Cool',
family_name: 'User',
email: 'user@somedomain.com'}
@default_user_credentials = { :firstname => 'Cool',
:lastname => 'User',
:mail => 'user@somedomain.com'}
@default_response_body = {:verified_email => true,
:name => 'Cool User',
:given_name => 'Cool',
:family_name => 'User',
:email => 'user@somedomain.com'}
User.current = nil
Setting.openid = '1'
OAuth2::AccessToken.any_instance.stubs(get: OAuth2::Response.new(nil))
OAuth2::Client.any_instance.stubs(get_token: OAuth2::AccessToken.new('code', 'redirect_uri'))
OAuth2::AccessToken.any_instance.stubs(:get => OAuth2::Response.new(nil))
OAuth2::Client.any_instance.stubs(:get_token => OAuth2::AccessToken.new('code', 'redirect_uri'))
end
#creates a new user with the credentials listed in the options and fills in the missing data by default data
......@@ -27,7 +27,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
#creates a new user with the credentials listed in the options and fills in the missing data by default data
def set_response_body_stub options = {}
OAuth2::Response.any_instance.stubs(body: @default_response_body.merge(options).to_json)
OAuth2::Response.any_instance.stubs(:body => @default_response_body.merge(options).to_json)
end
def test_oauth_google_with_enabled_oauth_authentification
......@@ -38,7 +38,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
def test_oauth_google_callback_for_existing_non_active_user
Setting.self_registration = '2'
user = new_user status: User::STATUS_REGISTERED
user = new_user :status => User::STATUS_REGISTERED
assert user.save
set_response_body_stub
get :oauth_google_callback
......@@ -51,14 +51,14 @@ class RedmineOauthControllerTest < ActionController::TestCase
assert user.save
set_response_body_stub
get :oauth_google_callback
assert_redirected_to controller: 'my', action: 'page'
assert_redirected_to :controller => 'my', :action => 'page'
end
def test_oauth_google_callback_for_new_user_with_valid_credentials_and_sefregistration_enabled
Setting.self_registration = '3'
set_response_body_stub
get :oauth_google_callback
assert_redirected_to controller: 'my', action: 'account'
assert_redirected_to :controller => 'my', :action => 'account'
user = User.find_by_mail(@default_response_body[:email])
assert_equal user.mail, @default_response_body[:email]
assert_equal user.login, parse_email(@default_response_body[:email])[:login]
......@@ -73,7 +73,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
def test_oauth_google_callback_with_new_user_with_invalid_oauth_provider
Setting.self_registration = '3'
set_response_body_stub verified_email: false
set_response_body_stub :verified_email => false
get :oauth_google_callback
assert_redirected_to signin_path
end
......@@ -103,7 +103,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
Setting.plugin_redmine_omniauth_google[:allowed_domains] = "twinslash.com"
set_response_body_stub
get :oauth_google_callback
assert_redirected_to :signin
assert_redirected_to :signin
end
def test_oauth_google_callback_with_allowed_email_domain
......@@ -111,6 +111,6 @@ class RedmineOauthControllerTest < ActionController::TestCase
Setting.plugin_redmine_omniauth_google[:allowed_domains] = parse_email(@default_response_body[:email])[:domain]
set_response_body_stub
get :oauth_google_callback
assert_redirected_to controller: 'my', action: 'account'
assert_redirected_to :controller => 'my', :action => 'account'
end
end
\ No newline at end of file
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