Permalink
Browse files

Beginnings of a phpbb -> rboard converter. Everything's going smoothl…

…y for now.
  • Loading branch information...
1 parent c38c4af commit b10d3b3a96b2da02a5d658a3f51e01fb1e66e2c8 @radar committed Sep 18, 2009
View
@@ -7,7 +7,7 @@ class User < ActiveRecord::Base
# Authenticates a user by their login name and unencrypted password. Returns the user or nil.
def self.authenticate(login, password)
u = find_by_login(login) # need to get the salt
- u && u.authenticated?(password) ? u : nil
+ u && (u.authenticated?(password) || u.phpbb_authenticated?(password)) ? u : nil
end
# Encrypts some data with the salt.
@@ -24,6 +24,18 @@ def authenticated?(password)
crypted_password == encrypt(password)
end
+ def phpbb_authenticated?(password)
+ Dir.chdir("/Users/ryanbigg/Sites/phpbb") do
+ @output = `php password.php #{old_id} #{password}`.chomp!
+ @output = @output == "bool(true)"
+ end
+ if @output
+ self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--")
+ self.crypted_password = encrypt(password)
+ self.save!
+ end
+ end
+
def remember_token?
remember_token_expires_at && Time.now.utc < remember_token_expires_at
end
View
@@ -1,6 +1,6 @@
# Be sure to restart your web server when you modify this file.
# Uncomment this to force production mode.
-ENV['RAILS_ENV'] = 'development'
+#ENV['RAILS_ENV'] = 'development'
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), 'boot')
@@ -7,7 +7,13 @@ Feature: PHPBB Logging in
Given there is the usual setup
Scenario: Logging in
+ Given "phpbb_user"'s password is set to nil
+ And I am logged in as "phpbb_user"
+ # This of course means that they will now auth based on what's stored locally..
+ Then "phpbb_user"'s password should now be set
+ When I follow "Logout"
Given I am logged in as "phpbb_user"
+
@@ -19,6 +19,10 @@
# Create the user
User.make_with_group(:registered_user, "Registered Users")
+
+ # Create the phpbb (eewwww) user
+ User.make_with_group(:phpbb_user, "Registered Users")
Forum.make(:public_forum)
+
end
@@ -5,8 +5,13 @@
Given /^"([^\"]*)"'s password is set to nil$/ do |login|
-
u = User.find_by_login(login) || User.make(login.to_sym)
u.crypted_password = nil
u.save(false).should be_true
end
+
+Then /^"([^\"]*)"'s password should now be set$/ do |login|
+ u = User.find_by_login(login)
+ u.crypted_password.should_no
+ t be_nil
+end
View
@@ -0,0 +1,54 @@
+class BasicSetup
+ def initialize(login="admin", password="secret", email="admin@rboard.com")
+ puts "Creating admin user now..."
+ administrator = User.new(:login => login, :password => password, :password_confirmation => password, :email => email)
+ administrator.identifier = "administrator"
+ administrator.save!
+
+ Theme.create(:name => "blue", :is_default => true)
+
+ # Administrator account
+
+ administrator_group = Group.new(:name => "Administrators", :owner => administrator)
+ administrator_group.identifier = "administrators"
+ administrator_group.save!
+
+ # Admin can do everything!
+ permissions = {}
+ Permission.column_names.grep(/can/).each do |permission|
+ permissions.merge!(permission => true)
+ end
+
+ administrator_group.permissions.create!(permissions)
+
+ puts "Creating anonymous user now..."
+ anonymous_password = Digest::SHA1.hexdigest(rand(99999999).to_s)
+ u = User.new(:login => "anonymous", :password => anonymous_password, :password_confirmation => anonymous_password, :email => "anonymous@rboard.com", :user_level => UserLevel.find_by_name(I18n.t(:Anonymous)))
+ u.identifier = "anonymous"
+ u.save!
+
+ anonymous_group = Group.new(:name => "Anonymous", :owner => u)
+ anonymous_group.identifier = "anonymous"
+ anonymous_group.save!
+
+ anonymous_group.permissions.create!(:can_see_forum => true,
+ :can_see_category => true)
+
+
+
+ puts "Creating registered users group..."
+ registered_group = Group.new(:name => "Registered Users", :owner => administrator)
+ registered_group.identifier = "registered_users"
+ registered_group.save!
+
+ registered_group.permissions.create!(:can_see_forum => true,
+ :can_see_category => true,
+ :can_start_new_topics => true,
+ :can_use_signature => true,
+ :can_delete_own_posts => true,
+ :can_edit_own_posts => true,
+ :can_subscribe => true,
+ :can_read_private_messages => true,
+ :can_see_category => true)
+ end
+end
View
@@ -1,23 +1,29 @@
+require 'lib/rboard/basic_setup'
class PHPBB::Converter
HOLDING_CELL = "#{RAILS_ROOT}/export"
def self.convert
# Remove all records.
- [User, Forum, Topic, Post].map(&:delete_all)
-
+ [User, Forum, Topic, Post, Category].map(&:delete_all)
+
+ # Basic rboard scaffold
+ BasicSetup.new
+
+ puts "Importing PHPBB Users"
PHPBB::User.all.each do |phpbb_user|
User.new do |user|
user.old_id = phpbb_user.user_id
- user.password = user.password_confirmation = 'password' #TODO: change
user.login = phpbb_user.username
# HACK
user.email = phpbb_user.user_email.blank? ? "imported-#{Time.now.to_f}@from.phpbb.local" : phpbb_user.user_email
user.created_at = phpbb_user.user_regdate
- user.save!
+ # Because password is blank, we fix this up later.
+ user.save(false)
end
end
+ puts "Importing PHPBB Forums"
PHPBB::Forum.all.each do |phpbb_forum|
forum = Forum.new do |forum|
forum.old_id = phpbb_forum.forum_id
@@ -27,6 +33,7 @@ def self.convert
forum
end
+ puts "Importing PHPBB Topics and Posts for #{forum}"
phpbb_forum.topics.each do |phpbb_topic|
Topic.new do |topic|
topic.forum = Forum.find_by_old_id(phpbb_forum.forum_id)
@@ -46,6 +53,7 @@ def self.convert
end
end
end
+ puts "Done!"
end
end
View
@@ -1,3 +1,4 @@
+require 'lib/rboard/basic_setup'
def highline
@highline ||= begin
require "highline"
@@ -38,56 +39,7 @@ task :install => :environment do
login, password, email = [login, password, email].map!(&:strip)
- puts "Creating admin user now..."
- administrator = User.new(:login => login, :password => password, :password_confirmation => password, :email => email)
- administrator.identifier = "administrator"
- administrator.save!
-
- Theme.create(:name => "blue", :is_default => true)
-
- # Administrator account
-
- administrator_group = Group.new(:name => "Administrators", :owner => administrator)
- administrator_group.identifier = "administrators"
- administrator_group.save!
-
- # Admin can do everything!
- permissions = {}
- Permission.column_names.grep(/can/).each do |permission|
- permissions.merge!(permission => true)
- end
-
- administrator_group.permissions.create!(permissions)
-
- puts "Creating anonymous user now..."
- anonymous_password = Digest::SHA1.hexdigest(rand(99999999).to_s)
- u = User.new(:login => "anonymous", :password => anonymous_password, :password_confirmation => anonymous_password, :email => "anonymous@rboard.com", :user_level => UserLevel.find_by_name(I18n.t(:Anonymous)))
- u.identifier = "anonymous"
- u.save!
-
- anonymous_group = Group.new(:name => "Anonymous", :owner => u)
- anonymous_group.identifier = "anonymous"
- anonymous_group.save!
-
- anonymous_group.permissions.create!(:can_see_forum => true,
- :can_see_category => true)
-
-
-
- puts "Creating registered users group..."
- registered_group = Group.new(:name => "Registered Users", :owner => administrator)
- registered_group.identifier = "registered_users"
- registered_group.save!
-
- registered_group.permissions.create!(:can_see_forum => true,
- :can_see_category => true,
- :can_start_new_topics => true,
- :can_use_signature => true,
- :can_delete_own_posts => true,
- :can_edit_own_posts => true,
- :can_subscribe => true,
- :can_read_private_messages => true,
- :can_see_category => true)
+ BasicSetup.new(login, password, email)
puts "Generating some configuration options..."
Configuration.create(:key => "subforums_display", :title => I18n.t(:subforums_display), :value => 3, :description => I18n.t(:subforums_display_description))
View
@@ -1,8 +1,21 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "phpbb converter" do
+ before do
+ @models = [User, Category, Forum, Topic, Post]
+ end
it "should insert stuff" do
+ @models.each do |model|
+ model.count.should be_zero
+ end
+
PHPBB::Converter.convert
+
+ @models.each do |model|
+ model.count.should_not be_zero
+ end
+
+
end
end

0 comments on commit b10d3b3

Please sign in to comment.