mattfawcett-phpbb-auth 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/MIT-LICENSE +20 -0
- data/README +51 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/phpbb_auth.rb +3 -0
- data/lib/phpbb_auth/models/phpbb_session.rb +11 -0
- data/lib/phpbb_auth/models/phpbb_user.rb +6 -0
- data/lib/phpbb_auth/phpbb_auth.rb +23 -0
- data/phpbb-auth.gemspec +73 -0
- data/spec/config/phpbb_auth_settings.rb +6 -0
- data/spec/db/forum.db +0 -0
- data/spec/db/test.db +0 -0
- data/spec/fixtures/forum_schema.rb +99 -0
- data/spec/fixtures/test_schema.rb +8 -0
- data/spec/models/phpbb_session_spec.rb +41 -0
- data/spec/models/phpbb_user_spec.rb +11 -0
- data/spec/phpbb_auth_spec.rb +37 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +138 -0
- data/uninstall.rb +1 -0
- metadata +93 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Matt Fawcett
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
phpbb-auth
|
2
|
+
==========
|
3
|
+
|
4
|
+
A Rails plugin / gem that allows you to use an existing PHPBB installation for handling users / authentication.
|
5
|
+
|
6
|
+
How it works
|
7
|
+
==========
|
8
|
+
You have a config file which tells the plugin what the session will be called and also add a row to database.yml to tell the plugin how to connect to your PHPBB database. You can then call the current_user method from a controller and it looks in your phpbb database sessions table to find a match for your cookie. If there is a match and the user is logged in then it will look to see if you have a user in your apps database that matches the PHPBB session user. If not it will create one. You will be returned the object of the user you hold locally. You can configure what the model name is for your locally stored user. You can also configure what the fields that get copied from the phpbb users row.
|
9
|
+
|
10
|
+
|
11
|
+
Constraints
|
12
|
+
===========
|
13
|
+
This does not work with versions of rails < 2.3.3 as it relied on https://rails.lighthouseapp.com/projects/8994/tickets/765-primary_key-option-for-belongs_to
|
14
|
+
|
15
|
+
Your rails app must have access to the phpbb sesion. Best way to do this is have both site son subdomains of the same domain. Configure phpbb so that it doesn't set the cookie for that particular subdomain only. (eg ".realalehunter.co.uk" instead of "forum.realalehunter.co.uk")
|
16
|
+
|
17
|
+
|
18
|
+
Example
|
19
|
+
=======
|
20
|
+
# Login to the phpbb admin and follow the "cookie seetting" link, take a note of the Cookie name. Ensure that the cookie domain and path are setup in a way that allows your rails app to access. Eg if your rails app is on www.realalehunter.co.uk and your forum on forum.realalehunter.co.uk, ensure that the cookie domain is .realalehunter.co.uk rather than forum.realalehunter.co.uk
|
21
|
+
|
22
|
+
# Now install the gem
|
23
|
+
gem install mattfawcett-phpbb-auth
|
24
|
+
|
25
|
+
# Tell environment.rb that you want to use the gem
|
26
|
+
config.gem "mattfawcett-phpbb-auth", :source => "http://gems.github.com"
|
27
|
+
|
28
|
+
# Add an entries to database.yml for phpbb_database_development, phpbb_database_production and phpbb_database_development
|
29
|
+
|
30
|
+
# in your config directory create a file called phpbb_auth_settings.rb, copy whats below into the file and change to match your setup
|
31
|
+
PHPBB_AUTH_FORUM_DATABASE_TABLE_PREFIX = 'phpbb_'
|
32
|
+
PHPBB_AUTH_COOKIE_NAME = "phpbb3_7uah4"
|
33
|
+
PHPBB_AUTH_LOCAL_USER_MODEL_NAME = "User" #this is the name of the model that you will use to store information about users in your rails app
|
34
|
+
PHPBB_AUTH_REMOTE_REMOTE_IDENTIFIER = 'user_email' #I use email to identify somebody, you may want to use the username instead
|
35
|
+
PHPBB_AUTH_REMOTE_LOCAL_IDENTIFIER = 'email' #this is the name of a field on your local user model that will be used to lookup the value of remote identifier.
|
36
|
+
PHPBB_AUTH_COLUMNS_TO_DUPLICATE = {:user_website => :website} #specify any additional fields that you would like copying to your local user model
|
37
|
+
|
38
|
+
# in application controller, include the module
|
39
|
+
include PhpbbAuth
|
40
|
+
|
41
|
+
# create a method called set_current_user
|
42
|
+
def set_current_user
|
43
|
+
@current_user = current_user
|
44
|
+
end
|
45
|
+
|
46
|
+
# add a before filter to the controller to run the method
|
47
|
+
before_filter :set_current_user
|
48
|
+
|
49
|
+
#you will then have access to the @current_user variable in your controllers and views. This will be either nil if the user is not logged in, or an instance of your local User
|
50
|
+
|
51
|
+
Copyright (c) 2009 Matt Fawcett, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "phpbb-auth"
|
8
|
+
gem.summary = %Q{Use phpbb for authentication in your rails app}
|
9
|
+
gem.description = %Q{Use phpbb for authentication in your rails app}
|
10
|
+
gem.email = "mail@matthewfawcett.co.uk"
|
11
|
+
gem.homepage = "http://github.com/mattfawcett/phpbb-auth"
|
12
|
+
gem.authors = ["Matt Fawcett"]
|
13
|
+
gem.add_development_dependency "rspec"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
if File.exist?('VERSION')
|
40
|
+
version = File.read('VERSION')
|
41
|
+
else
|
42
|
+
version = ""
|
43
|
+
end
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "phpbb-auth #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/phpbb_auth"
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/phpbb_auth.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class PhpbbSession < ActiveRecord::Base
|
2
|
+
establish_connection "phpbb_database_#{RAILS_ENV}"
|
3
|
+
def self.table_name() "#{PHPBB_AUTH_FORUM_DATABASE_TABLE_PREFIX}sessions" end
|
4
|
+
|
5
|
+
belongs_to :phpbb_user, :foreign_key => :session_user_id, :primary_key => :user_id
|
6
|
+
|
7
|
+
def logged_in?
|
8
|
+
session_user_id > 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "#{RAILS_ROOT}/config/phpbb_auth_settings"
|
2
|
+
|
3
|
+
module PhpbbAuth
|
4
|
+
def current_user
|
5
|
+
unless cookies["#{PHPBB_AUTH_COOKIE_NAME}_sid"].nil?
|
6
|
+
@phpbb_session = PhpbbSession.find_by_session_id(cookies["#{PHPBB_AUTH_COOKIE_NAME}_sid"])
|
7
|
+
unless @phpbb_session.nil? || !@phpbb_session.logged_in?
|
8
|
+
local_user = eval(PHPBB_AUTH_LOCAL_USER_MODEL_NAME).find(:first, :conditions => {PHPBB_AUTH_REMOTE_LOCAL_IDENTIFIER => @phpbb_session.phpbb_user.send(PHPBB_AUTH_REMOTE_REMOTE_IDENTIFIER)})
|
9
|
+
if !local_user
|
10
|
+
# We don't have the user registered in the local database, lets create them
|
11
|
+
local_user = eval(PHPBB_AUTH_LOCAL_USER_MODEL_NAME).new(PHPBB_AUTH_REMOTE_LOCAL_IDENTIFIER => @phpbb_session.phpbb_user.send(PHPBB_AUTH_REMOTE_REMOTE_IDENTIFIER))
|
12
|
+
unless PHPBB_AUTH_COLUMNS_TO_DUPLICATE.nil?
|
13
|
+
PHPBB_AUTH_COLUMNS_TO_DUPLICATE.each do |remote_name, local_name|
|
14
|
+
local_user.send("#{local_name}=", @phpbb_session.phpbb_user.send(remote_name))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
local_user.save!
|
18
|
+
end
|
19
|
+
return local_user
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/phpbb-auth.gemspec
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{phpbb-auth}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matt Fawcett"]
|
12
|
+
s.date = %q{2009-08-31}
|
13
|
+
s.description = %q{Use phpbb for authentication in your rails app}
|
14
|
+
s.email = %q{mail@matthewfawcett.co.uk}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"MIT-LICENSE",
|
24
|
+
"README",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"init.rb",
|
28
|
+
"install.rb",
|
29
|
+
"lib/phpbb_auth.rb",
|
30
|
+
"lib/phpbb_auth/models/phpbb_session.rb",
|
31
|
+
"lib/phpbb_auth/models/phpbb_user.rb",
|
32
|
+
"lib/phpbb_auth/phpbb_auth.rb",
|
33
|
+
"phpbb-auth.gemspec",
|
34
|
+
"spec/config/phpbb_auth_settings.rb",
|
35
|
+
"spec/db/forum.db",
|
36
|
+
"spec/db/test.db",
|
37
|
+
"spec/fixtures/forum_schema.rb",
|
38
|
+
"spec/fixtures/test_schema.rb",
|
39
|
+
"spec/models/phpbb_session_spec.rb",
|
40
|
+
"spec/models/phpbb_user_spec.rb",
|
41
|
+
"spec/phpbb_auth_spec.rb",
|
42
|
+
"spec/spec.opts",
|
43
|
+
"spec/spec_helper.rb",
|
44
|
+
"uninstall.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/mattfawcett/phpbb-auth}
|
47
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.5}
|
50
|
+
s.summary = %q{Use phpbb for authentication in your rails app}
|
51
|
+
s.test_files = [
|
52
|
+
"spec/config/phpbb_auth_settings.rb",
|
53
|
+
"spec/models/phpbb_user_spec.rb",
|
54
|
+
"spec/models/phpbb_session_spec.rb",
|
55
|
+
"spec/phpbb_auth_spec.rb",
|
56
|
+
"spec/fixtures/test_schema.rb",
|
57
|
+
"spec/fixtures/forum_schema.rb",
|
58
|
+
"spec/spec_helper.rb"
|
59
|
+
]
|
60
|
+
|
61
|
+
if s.respond_to? :specification_version then
|
62
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
PHPBB_AUTH_FORUM_DATABASE_TABLE_PREFIX = 'phpbb_'
|
2
|
+
PHPBB_AUTH_COOKIE_NAME = "phpbb3_7uah4"
|
3
|
+
PHPBB_AUTH_LOCAL_USER_MODEL_NAME = "User"
|
4
|
+
PHPBB_AUTH_REMOTE_REMOTE_IDENTIFIER = 'user_email'
|
5
|
+
PHPBB_AUTH_REMOTE_LOCAL_IDENTIFIER = 'email'
|
6
|
+
PHPBB_AUTH_COLUMNS_TO_DUPLICATE = {:user_website => :website}
|
data/spec/db/forum.db
ADDED
Binary file
|
data/spec/db/test.db
ADDED
Binary file
|
@@ -0,0 +1,99 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
|
4
|
+
create_table "phpbb_sessions", :force => true do |t|
|
5
|
+
t.string "session_id", :limit => 255
|
6
|
+
t.integer "session_user_id", :limit => 3, :default => 0, :null => false
|
7
|
+
t.integer "session_forum_id", :limit => 3, :default => 0, :null => false
|
8
|
+
t.integer "session_last_visit", :default => 0, :null => false
|
9
|
+
t.integer "session_start", :default => 0, :null => false
|
10
|
+
t.integer "session_time", :default => 0, :null => false
|
11
|
+
t.string "session_ip", :limit => 40, :default => "", :null => false
|
12
|
+
t.string "session_browser", :limit => 150, :default => "", :null => false
|
13
|
+
t.string "session_forwarded_for", :default => "", :null => false
|
14
|
+
t.string "session_page", :default => "", :null => false
|
15
|
+
t.boolean "session_viewonline", :default => true, :null => false
|
16
|
+
t.boolean "session_autologin", :default => false, :null => false
|
17
|
+
t.boolean "session_admin", :default => false, :null => false
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
create_table "phpbb_users", :force => true do |t|
|
22
|
+
t.integer "user_id", :limit => 11
|
23
|
+
t.integer "user_type", :limit => 1, :default => 0, :null => false
|
24
|
+
t.integer "group_id", :limit => 3, :default => 3, :null => false
|
25
|
+
t.text "user_permissions", :limit => 16777215, :null => false
|
26
|
+
t.integer "user_perm_from", :limit => 3, :default => 0, :null => false
|
27
|
+
t.string "user_ip", :limit => 40, :default => "", :null => false
|
28
|
+
t.integer "user_regdate", :default => 0, :null => false
|
29
|
+
t.string "username", :default => "", :null => false
|
30
|
+
t.string "username_clean", :default => "", :null => false
|
31
|
+
t.string "user_password", :limit => 40, :default => "", :null => false
|
32
|
+
t.integer "user_passchg", :default => 0, :null => false
|
33
|
+
t.boolean "user_pass_convert", :default => false, :null => false
|
34
|
+
t.string "user_email", :limit => 100, :default => "", :null => false
|
35
|
+
t.integer "user_email_hash", :limit => 8, :default => 0, :null => false
|
36
|
+
t.string "user_birthday", :limit => 10, :default => "", :null => false
|
37
|
+
t.integer "user_lastvisit", :default => 0, :null => false
|
38
|
+
t.integer "user_lastmark", :default => 0, :null => false
|
39
|
+
t.integer "user_lastpost_time", :default => 0, :null => false
|
40
|
+
t.string "user_lastpage", :limit => 200, :default => "", :null => false
|
41
|
+
t.string "user_last_confirm_key", :limit => 10, :default => "", :null => false
|
42
|
+
t.integer "user_last_search", :default => 0, :null => false
|
43
|
+
t.integer "user_warnings", :limit => 1, :default => 0, :null => false
|
44
|
+
t.integer "user_last_warning", :default => 0, :null => false
|
45
|
+
t.integer "user_login_attempts", :limit => 1, :default => 0, :null => false
|
46
|
+
t.integer "user_inactive_reason", :limit => 1, :default => 0, :null => false
|
47
|
+
t.integer "user_inactive_time", :default => 0, :null => false
|
48
|
+
t.integer "user_posts", :limit => 3, :default => 0, :null => false
|
49
|
+
t.string "user_lang", :limit => 30, :default => "", :null => false
|
50
|
+
t.decimal "user_timezone", :precision => 5, :scale => 2, :default => 0.0, :null => false
|
51
|
+
t.boolean "user_dst", :default => false, :null => false
|
52
|
+
t.string "user_dateformat", :limit => 30, :default => "d M Y H:i", :null => false
|
53
|
+
t.integer "user_style", :limit => 2, :default => 0, :null => false
|
54
|
+
t.integer "user_rank", :limit => 3, :default => 0, :null => false
|
55
|
+
t.string "user_colour", :limit => 6, :default => "", :null => false
|
56
|
+
t.integer "user_new_privmsg", :default => 0, :null => false
|
57
|
+
t.integer "user_unread_privmsg", :default => 0, :null => false
|
58
|
+
t.integer "user_last_privmsg", :default => 0, :null => false
|
59
|
+
t.boolean "user_message_rules", :default => false, :null => false
|
60
|
+
t.integer "user_full_folder", :default => -3, :null => false
|
61
|
+
t.integer "user_emailtime", :default => 0, :null => false
|
62
|
+
t.integer "user_topic_show_days", :limit => 2, :default => 0, :null => false
|
63
|
+
t.string "user_topic_sortby_type", :limit => 1, :default => "t", :null => false
|
64
|
+
t.string "user_topic_sortby_dir", :limit => 1, :default => "d", :null => false
|
65
|
+
t.integer "user_post_show_days", :limit => 2, :default => 0, :null => false
|
66
|
+
t.string "user_post_sortby_type", :limit => 1, :default => "t", :null => false
|
67
|
+
t.string "user_post_sortby_dir", :limit => 1, :default => "a", :null => false
|
68
|
+
t.boolean "user_notify", :default => false, :null => false
|
69
|
+
t.boolean "user_notify_pm", :default => true, :null => false
|
70
|
+
t.integer "user_notify_type", :limit => 1, :default => 0, :null => false
|
71
|
+
t.boolean "user_allow_pm", :default => true, :null => false
|
72
|
+
t.boolean "user_allow_viewonline", :default => true, :null => false
|
73
|
+
t.boolean "user_allow_viewemail", :default => true, :null => false
|
74
|
+
t.boolean "user_allow_massemail", :default => true, :null => false
|
75
|
+
t.integer "user_options", :default => 895, :null => false
|
76
|
+
t.string "user_avatar", :default => "", :null => false
|
77
|
+
t.integer "user_avatar_type", :limit => 1, :default => 0, :null => false
|
78
|
+
t.integer "user_avatar_width", :limit => 2, :default => 0, :null => false
|
79
|
+
t.integer "user_avatar_height", :limit => 2, :default => 0, :null => false
|
80
|
+
t.text "user_sig", :limit => 16777215, :null => false
|
81
|
+
t.string "user_sig_bbcode_uid", :limit => 8, :default => "", :null => false
|
82
|
+
t.string "user_sig_bbcode_bitfield", :default => "", :null => false
|
83
|
+
t.string "user_from", :limit => 100, :default => "", :null => false
|
84
|
+
t.string "user_icq", :limit => 15, :default => "", :null => false
|
85
|
+
t.string "user_aim", :default => "", :null => false
|
86
|
+
t.string "user_yim", :default => "", :null => false
|
87
|
+
t.string "user_msnm", :default => "", :null => false
|
88
|
+
t.string "user_jabber", :default => "", :null => false
|
89
|
+
t.string "user_website", :limit => 200, :default => "", :null => false
|
90
|
+
t.text "user_occ", :null => false
|
91
|
+
t.text "user_interests", :null => false
|
92
|
+
t.string "user_actkey", :limit => 32, :default => "", :null => false
|
93
|
+
t.string "user_newpasswd", :limit => 40, :default => "", :null => false
|
94
|
+
t.string "user_form_salt", :limit => 32, :default => "", :null => false
|
95
|
+
t.string "user_openid", :default => "", :null => false
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe PhpbbSession do
|
4
|
+
before(:each) do
|
5
|
+
PhpbbSession.delete_all
|
6
|
+
PhpbbUser.delete_all
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should connect to the correct database to return a session row" do
|
10
|
+
PhpbbSession.create!(valid_PhpbbSession_attributes)
|
11
|
+
@session = PhpbbSession.find_by_session_id('2d4b5dd208b7baa6d548aea9d655b392')
|
12
|
+
@session.session_user_id.should eql(1) #guest user
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return a user for a particular session if they are logged in" do
|
16
|
+
@user = PhpbbUser.create!(valid_PhpbbUser_attributes)
|
17
|
+
PhpbbSession.create!(valid_PhpbbSession_attributes(:session_user_id => @user.user_id))
|
18
|
+
@session = PhpbbSession.find_by_session_id('2d4b5dd208b7baa6d548aea9d655b392')
|
19
|
+
@session.phpbb_user.username.should eql("matt")
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
describe PhpbbSession, ".logged_in?" do
|
25
|
+
before(:each) do
|
26
|
+
@session = PhpbbSession.new
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return true when my session_user_id is > 1" do
|
30
|
+
@session.session_user_id = 20
|
31
|
+
@session.should be_logged_in
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return false when my session_user_id is <= 1" do
|
35
|
+
@session.session_user_id = 1
|
36
|
+
@session.should_not be_logged_in
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/phpbb_auth'
|
3
|
+
|
4
|
+
describe PhpbbAuth do
|
5
|
+
include PhpbbAuth
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@user = PhpbbUser.create!(valid_PhpbbUser_attributes)
|
9
|
+
@session = PhpbbSession.create!(valid_PhpbbSession_attributes(:session_user_id => @user.user_id))
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "current_user" do
|
13
|
+
it "should return nil if I don't have a session cookie at all" do
|
14
|
+
self.stub!(:cookies).and_return({})
|
15
|
+
current_user.should be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return nil if the session is not recognised by the db" do
|
19
|
+
self.stub!(:cookies).and_return({'phpbb3_7uah4_sid' => '123456789'})
|
20
|
+
current_user.should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should create and return a user in the application database if the session is valid and a user doesn't exist" do
|
24
|
+
self.stub!(:cookies).and_return({'phpbb3_7uah4_sid' => '2d4b5dd208b7baa6d548aea9d655b392'})
|
25
|
+
current_user.should be_a(User)
|
26
|
+
current_user.email.should eql("mail@nospam.co.uk")
|
27
|
+
current_user.website.should eql("http://matthewfawcett.co.uk")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return a user if session valid and user already exists in application database" do
|
31
|
+
@local_user = User.create!(:email => "mail@nospam.co.uk")
|
32
|
+
self.stub!(:cookies).and_return({'phpbb3_7uah4_sid' => '2d4b5dd208b7baa6d548aea9d655b392'})
|
33
|
+
current_user.should == @local_user
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
RAILS_ENV = "test"
|
2
|
+
RAILS_ROOT = File.dirname(__FILE__)
|
3
|
+
require 'rubygems'
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
|
7
|
+
ActiveRecord::Base.configurations['test'] = {
|
8
|
+
:adapter => 'sqlite3',
|
9
|
+
:dbfile => 'db/test.db',
|
10
|
+
}
|
11
|
+
ActiveRecord::Base.configurations['phpbb_database_test'] = {
|
12
|
+
:adapter => 'sqlite3',
|
13
|
+
:dbfile => 'db/forum.db',
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
Spec::Runner.configure do |config|
|
18
|
+
config.before(:each) do
|
19
|
+
load_schemas
|
20
|
+
end
|
21
|
+
require File.dirname(__FILE__) + "/../lib/phpbb_auth"
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_schemas
|
25
|
+
ActiveRecord::Base.establish_connection('phpbb_database_test')
|
26
|
+
load(File.dirname(__FILE__) + "/fixtures/forum_schema.rb")
|
27
|
+
ActiveRecord::Base.establish_connection('test')
|
28
|
+
load(File.dirname(__FILE__) + "/fixtures/test_schema.rb")
|
29
|
+
end
|
30
|
+
|
31
|
+
def mock_user
|
32
|
+
mock_model(User, :id => 12, :email => "mail@nospam.co.uk")
|
33
|
+
end
|
34
|
+
|
35
|
+
def empty_tables
|
36
|
+
PhpbbSession.delete_all
|
37
|
+
PhpbbUser.delete_all
|
38
|
+
end
|
39
|
+
|
40
|
+
def valid_PhpbbSession_attributes(overwrite_attributes = {})
|
41
|
+
{
|
42
|
+
:session_last_visit => 1.minute.ago,
|
43
|
+
:session_browser => "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.5) Gecko/2008121621 Ubuntu/8.04 (hardy) Firefox/3.0.5",
|
44
|
+
:session_start => 1.minute.ago,
|
45
|
+
:session_time => 1.minute.ago,
|
46
|
+
:session_id => "2d4b5dd208b7baa6d548aea9d655b392",
|
47
|
+
:session_viewonline => "1",
|
48
|
+
:session_ip => "127.0.0.1",
|
49
|
+
:session_admin => "0",
|
50
|
+
:session_page => "../index.php",
|
51
|
+
:session_forum_id => "0",
|
52
|
+
:session_forwarded_for => "",
|
53
|
+
:session_autologin => "0",
|
54
|
+
:session_user_id => "1",
|
55
|
+
}.merge(overwrite_attributes)
|
56
|
+
end
|
57
|
+
def valid_PhpbbUser_attributes(overwrite_attributes = {})
|
58
|
+
{
|
59
|
+
:user_id => 2,
|
60
|
+
:user_type => 3,
|
61
|
+
:group_id => 10,
|
62
|
+
:user_permissions => "zik0zjzik0zjzik0w0\nzik0zi000000\nzik0zi000000\nzik0zi...",
|
63
|
+
:user_perm_from => 0,
|
64
|
+
:user_ip => "",
|
65
|
+
:user_regdate => 1170504862,
|
66
|
+
:username => "matt",
|
67
|
+
:username_clean => "matt",
|
68
|
+
:user_password => "$H$93xTU0YcEwMg2lkx5nN84UYbchanged",
|
69
|
+
:user_passchg => 0,
|
70
|
+
:user_pass_convert => false,
|
71
|
+
:user_email => "mail@nospam.co.uk",
|
72
|
+
:user_email_hash => -136655181925,
|
73
|
+
:user_birthday => "0- 0- 0",
|
74
|
+
:user_lastvisit => 1219841542,
|
75
|
+
:user_lastmark => 1212931539,
|
76
|
+
:user_lastpost_time => 1219997228,
|
77
|
+
:user_lastpage => "",
|
78
|
+
:user_last_confirm_key => "4KK3B3FD3P",
|
79
|
+
:user_last_search => 1214674888,
|
80
|
+
:user_warnings => 0,
|
81
|
+
:user_last_warning => 0,
|
82
|
+
:user_login_attempts => 0,
|
83
|
+
:user_inactive_reason => 0,
|
84
|
+
:user_inactive_time => 0,
|
85
|
+
:user_posts => 50,
|
86
|
+
:user_lang => "en",
|
87
|
+
:user_timezone => 1,
|
88
|
+
:user_dst => false,
|
89
|
+
:user_dateformat => "d M Y h:i a",
|
90
|
+
:user_style=> 1,
|
91
|
+
:user_rank => 1,
|
92
|
+
:user_colour => "AA0000",
|
93
|
+
:user_new_privmsg => 0,
|
94
|
+
:user_unread_privmsg => 0,
|
95
|
+
:user_last_privmsg => 1213370330,
|
96
|
+
:user_message_rules => false,
|
97
|
+
:user_full_folder => -3,
|
98
|
+
:user_emailtime => 1212924689,
|
99
|
+
:user_topic_show_days => 0,
|
100
|
+
:user_topic_sortby_type => "t",
|
101
|
+
:user_topic_sortby_dir => "d",
|
102
|
+
:user_post_show_days => 0,
|
103
|
+
:user_post_sortby_type => "t",
|
104
|
+
:user_post_sortby_dir => "a",
|
105
|
+
:user_notify => false,
|
106
|
+
:user_notify_pm => true,
|
107
|
+
:user_notify_type => 0,
|
108
|
+
:user_allow_pm => true,
|
109
|
+
:user_allow_viewonline => true,
|
110
|
+
:user_allow_viewemail => true,
|
111
|
+
:user_allow_massemail => true,
|
112
|
+
:user_options => 1919,
|
113
|
+
:user_avatar => "",
|
114
|
+
:user_avatar_type => 0,
|
115
|
+
:user_avatar_width => 0,
|
116
|
+
:user_avatar_height => 0,
|
117
|
+
:user_sig => "some sig",
|
118
|
+
:user_sig_bbcode_uid => "39nm3i65",
|
119
|
+
:user_sig_bbcode_bitfield => "IA==",
|
120
|
+
:user_from => "Leeds",
|
121
|
+
:user_icq => "",
|
122
|
+
:user_aim => "",
|
123
|
+
:user_yim => "",
|
124
|
+
:user_msnm => "",
|
125
|
+
:user_jabber => "",
|
126
|
+
:user_website => "http://matthewfawcett.co.uk",
|
127
|
+
:user_occ => "",
|
128
|
+
:user_interests => "",
|
129
|
+
:user_actkey => "",
|
130
|
+
:user_newpasswd => "",
|
131
|
+
:user_form_salt => "af92d6547f0009e2"
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
#declare a user class as ifit was one in the application
|
136
|
+
class User < ActiveRecord::Base
|
137
|
+
end
|
138
|
+
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattfawcett-phpbb-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Fawcett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-31 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Use phpbb for authentication in your rails app
|
26
|
+
email: mail@matthewfawcett.co.uk
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- MIT-LICENSE
|
39
|
+
- README
|
40
|
+
- Rakefile
|
41
|
+
- VERSION
|
42
|
+
- init.rb
|
43
|
+
- install.rb
|
44
|
+
- lib/phpbb_auth.rb
|
45
|
+
- lib/phpbb_auth/models/phpbb_session.rb
|
46
|
+
- lib/phpbb_auth/models/phpbb_user.rb
|
47
|
+
- lib/phpbb_auth/phpbb_auth.rb
|
48
|
+
- phpbb-auth.gemspec
|
49
|
+
- spec/config/phpbb_auth_settings.rb
|
50
|
+
- spec/db/forum.db
|
51
|
+
- spec/db/test.db
|
52
|
+
- spec/fixtures/forum_schema.rb
|
53
|
+
- spec/fixtures/test_schema.rb
|
54
|
+
- spec/models/phpbb_session_spec.rb
|
55
|
+
- spec/models/phpbb_user_spec.rb
|
56
|
+
- spec/phpbb_auth_spec.rb
|
57
|
+
- spec/spec.opts
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
- uninstall.rb
|
60
|
+
has_rdoc: false
|
61
|
+
homepage: http://github.com/mattfawcett/phpbb-auth
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.2.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Use phpbb for authentication in your rails app
|
86
|
+
test_files:
|
87
|
+
- spec/config/phpbb_auth_settings.rb
|
88
|
+
- spec/models/phpbb_user_spec.rb
|
89
|
+
- spec/models/phpbb_session_spec.rb
|
90
|
+
- spec/phpbb_auth_spec.rb
|
91
|
+
- spec/fixtures/test_schema.rb
|
92
|
+
- spec/fixtures/forum_schema.rb
|
93
|
+
- spec/spec_helper.rb
|