diff --git a/Gemfile b/Gemfile
index 74038f21b55a54cb7ea83747c6caed2c5402f1c2..1fd0171ec7c8dd33be55972e63e1a2d5028130f3 100644
--- a/Gemfile
+++ b/Gemfile
@@ -5,4 +5,5 @@ gem 'json'
 
 group :development, :test do
   gem 'mailcatcher'
+  gem 'pry'
 end
\ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
index fc83bce14eb53ee454e8f77f3417fe8de87a76cf..2fcbb31ffbc4a8b9695e2ab8c872a4443766c041 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -5,6 +5,7 @@ GEM
       i18n (~> 0.6)
       multi_json (~> 1.0)
     addressable (2.3.2)
+    coderay (1.0.7)
     daemons (1.1.8)
     eventmachine (0.12.10)
     faraday (0.7.6)
@@ -27,6 +28,7 @@ GEM
       skinny (~> 0.2, >= 0.2.1)
       sqlite3 (~> 1.3)
       thin (~> 1.2)
+    method_source (0.8)
     mime-types (1.19)
     multi_json (1.3.6)
     multipart-post (1.1.5)
@@ -34,6 +36,10 @@ GEM
       faraday (~> 0.7)
       multi_json (~> 1.0)
     polyglot (0.3.3)
+    pry (0.9.10)
+      coderay (~> 1.0.5)
+      method_source (~> 0.8)
+      slop (~> 3.3.1)
     rack (1.4.1)
     rack-protection (1.2.0)
       rack
@@ -44,13 +50,13 @@ GEM
     skinny (0.2.1)
       eventmachine (~> 0.12)
       thin (~> 1.2)
+    slop (3.3.3)
     sqlite3 (1.3.6)
     thin (1.3.1)
       daemons (>= 1.0.9)
       eventmachine (>= 0.12.6)
       rack (>= 1.0.0)
     tilt (1.3.3)
-    tmail (1.2.7.1)
     treetop (1.4.12)
       polyglot
       polyglot (>= 0.3.1)
@@ -62,4 +68,4 @@ DEPENDENCIES
   json
   mailcatcher
   oauth2
-  tmail
+  pry
diff --git a/app/controllers/redmine_oauth_controller.rb b/app/controllers/redmine_oauth_controller.rb
index 8cbf8865748943afecfe65c80af7cf92a7b83596..19ba2953436f658cb6b623f122208467658bbc50 100644
--- a/app/controllers/redmine_oauth_controller.rb
+++ b/app/controllers/redmine_oauth_controller.rb
@@ -2,8 +2,9 @@ require 'account_controller'
 require 'json'
 
 class RedmineOauthController < AccountController
+  include Helpers::MailHelper
   def oauth_google
-    if Setting.openid?
+    if Setting.plugin_redmine_omniauth_google[:oauth_authentification]
       redirect_to oauth_client.auth_code.authorize_url(redirect_uri: oauth_google_callback_url, scope: scopes)
     else
       password_authentication
@@ -57,11 +58,6 @@ class RedmineOauthController < AccountController
     end
   end
 
-  def email_prefix email
-    prefix = email.match(/(.+?)@/) if email
-    prefix[1] if prefix
-  end
-
   def oauth_client
     @client ||= OAuth2::Client.new(settings[:client_id], settings[:client_secret],
       site: 'https://accounts.google.com',
diff --git a/app/views/hooks/_view_account_login_bottom.html.erb b/app/views/hooks/_view_account_login_bottom.html.erb
index 09d8ea9e2a9d45c9dc2f57a4389c6c354c615e1d..524d507769241e1e64bf0b7aaee9fe32f4253a68 100644
--- a/app/views/hooks/_view_account_login_bottom.html.erb
+++ b/app/views/hooks/_view_account_login_bottom.html.erb
@@ -1,3 +1,3 @@
-<% if Setting.openid? %>
+<% if Setting.plugin_redmine_omniauth_google[:oauth_authentification] %>
   <%= link_to image_tag('/plugin_assets/redmine_omniauth_google/images/google_login_icon.jpg'), oauth_google_path %>
 <% end %>
\ No newline at end of file
diff --git a/app/views/settings/_google_settings.html.erb b/app/views/settings/_google_settings.html.erb
index 1fe7a115afc45d76225421abc40db8aa0ed6297c..969f5687aeecc7f29a425d8e31afe834b9dc8bdf 100644
--- a/app/views/settings/_google_settings.html.erb
+++ b/app/views/settings/_google_settings.html.erb
@@ -5,4 +5,8 @@
 <p>
   <label>Client Secret:</label>
   <%= text_field_tag 'settings[client_secret]', @settings[:client_secret] %>
+</p>
+<p>
+  <label>Oauth authentification:</label>
+  <%= check_box_tag "settings[oauth_authentification]", true, @settings[:oauth_authentification] %>
 </p>
\ No newline at end of file
diff --git a/init.rb b/init.rb
index 009f2c77227ea85424e59e116b66d80666ad9c09..d12705b1ea64c2db69d0a1c261180176e92b1b0f 100644
--- a/init.rb
+++ b/init.rb
@@ -10,5 +10,5 @@ Redmine::Plugin.register :redmine_omniauth_google do
   author_url 'https://tsdv.net/redmine/users/105'
   settings default: {
     client_id: '214698823792.apps.googleusercontent.com',
-    client_secret: 'M0HJPMypEgrDAKKHGiP6Y2R-' }, partial: 'settings/google_settings'
-end
+    client_secret: 'M0HJPMypEgrDAKKHGiP6Y2R-', oauth_autentification: false}, partial: 'settings/google_settings'
+end
\ No newline at end of file
diff --git a/lib/helpers/mail_helper.rb b/lib/helpers/mail_helper.rb
new file mode 100644
index 0000000000000000000000000000000000000000..d1087f94a390bc8fb395b0507a10700c80d53820
--- /dev/null
+++ b/lib/helpers/mail_helper.rb
@@ -0,0 +1,8 @@
+module Helpers
+  module MailHelper
+    def email_prefix email
+      prefix = email.match(/(.+?)@/) if email
+      prefix[1] if prefix
+    end
+  end
+end
\ No newline at end of file
diff --git a/test/functional/redmine_oauth_controller_test.rb b/test/functional/redmine_oauth_controller_test.rb
index 933a41f00b8a6a06e4557296f40127e99f0865e9..15690e48791c07529b8e6397ffb413752d99a99d 100644
--- a/test/functional/redmine_oauth_controller_test.rb
+++ b/test/functional/redmine_oauth_controller_test.rb
@@ -1,7 +1,8 @@
 require File.expand_path('../../test_helper', __FILE__)
+#require File.expand_path('../../../lib/helpers/mail_helper', __FILE__)
 
 class RedmineOauthControllerTest < ActionController::TestCase
-
+  include Helpers::MailHelper
   def setup
     @default_user_credentials = { firstname: 'Cool',
                                   lastname: 'User',
@@ -30,13 +31,13 @@ class RedmineOauthControllerTest < ActionController::TestCase
     OAuth2::Response.any_instance.stubs(body: @default_response_body.merge(options).to_json)
   end
 
-  def test_oauth_google_with_disabled_openid
-    Setting.openid = false
+  def test_oauth_google_with_enabled_oauth_authentification
+    Setting.plugin_redmine_omniauth_google[:oauth_authentification] = nil
     get :oauth_google
-    assert_redirected_to signin_path
+    assert_response 404
   end
 
-  def test_oauth_google_callback_with_oauth_for_existing_non_active_user
+  def test_oauth_google_callback_for_existing_non_active_user
     Setting.self_registration = '2'
     user = new_user status: User::STATUS_REGISTERED
     assert user.save
@@ -45,7 +46,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
     assert_redirected_to signin_path
   end
 
-  def test_oauth_google_callback_with_oauth_for_existing_active_user
+  def test_oauth_google_callback_for_existing_active_user
     user = new_user
     user.activate
     assert user.save
@@ -54,7 +55,7 @@ class RedmineOauthControllerTest < ActionController::TestCase
     assert_redirected_to controller: 'my', action: 'page'
   end
 
-  def test_oauth_google_callback_with_omniauth_for_new_user_with_valid_credentials_and_sefregistration_enabled
+  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
@@ -64,21 +65,38 @@ class RedmineOauthControllerTest < ActionController::TestCase
     assert_equal user.login, email_prefix(@default_response_body[:email])
   end
 
-  def test_oauth_google_callback_with_omniauth_for_new_user_with_valid_credentials_and_sefregistration_disabled
+  def test_oauth_google_callback_for_new_user_with_valid_credentials_and_sefregistration_disabled
     Setting.self_registration = '2'
     set_response_body_stub
     get :oauth_google_callback
     assert_redirected_to signin_path
   end
 
-  def test_oauth_google_callback_with_oauth_for_new_user_with_invalid_oauth_provider
+  def test_oauth_google_callback_with_new_user_with_invalid_oauth_provider
     Setting.self_registration = '3'
     set_response_body_stub verified_email: false
     get :oauth_google_callback
     assert_redirected_to signin_path
   end
 
-  #def test_login_with
+  def test_oauth_google_callback_with_new_user_created_with_email_activation_should_have_a_token
+    Setting.self_registration = '1'
+    set_response_body_stub
+    get :oauth_google_callback
+    assert_redirected_to :signin
+    user = User.find_by_mail(@default_user_credentials[:mail])
+    assert user
+    token = Token.find_by_user_id_and_action(user.id, 'register')
+    assert token
+  end
 
-  #assert existing_user.save!
+  def test_oauth_google_callback_with_new_user_created_with_manual_activation
+      Setting.self_registration = '2'
+      set_response_body_stub
+      get :oauth_google_callback
+      assert_redirected_to :signin
+      user = User.find_by_mail(@default_user_credentials[:mail])
+      assert user
+      assert_equal User::STATUS_REGISTERED, user.status
+  end
 end
\ No newline at end of file