From 04f6cdaacfbb0f889f75386112b03bd929c67c7f Mon Sep 17 00:00:00 2001 From: maxwell <maxwell@joindiaspora.com> Date: Wed, 13 Oct 2010 18:42:24 -0700 Subject: [PATCH] MS DG; basic view support; it works, but it is ugly --- app/controllers/registrations_controller.rb | 2 +- app/controllers/users_controller.rb | 25 ++++++++++++++++++++- app/views/registrations/new.html.haml | 24 ++++++++++++++++++++ config/routes.rb | 1 + spec/lib/importer_spec.rb | 3 --- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index b29887112d..8a784dcfbc 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -22,7 +22,7 @@ class RegistrationsController < Devise::RegistrationsController end end - def update + def update super end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 030cfe56d0..6a12c1842f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,10 +5,11 @@ class UsersController < ApplicationController require File.join(Rails.root, 'lib/diaspora/ostatus_builder') require File.join(Rails.root, 'lib/diaspora/exporter') + require File.join(Rails.root, 'lib/diaspora/importer') require File.join(Rails.root, 'lib/collect_user_photos') - before_filter :authenticate_user!, :except => [:new, :create, :public] + before_filter :authenticate_user!, :except => [:new, :create, :public, :import] respond_to :html @@ -81,6 +82,28 @@ class UsersController < ApplicationController def invite User.invite!(:email => params[:email]) end + + + def import + xml = params[:upload][:file].read + + params[:user][:diaspora_handle] = 'asodij@asodij.asd' + + + begin + importer = Diaspora::Importer.new(Diaspora::Parsers::XML) + importer.execute(xml, params[:user]) + flash[:notice] = "hang on a sec, try logging in!" + + rescue Exception => e + flash[:error] = "Derp, something went wrong: #{e.message}" + end + + redirect_to new_user_registration_path + #redirect_to user_session_path + end + + private def prep_image_url(params) diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index 7e74a21570..cea31ff78e 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -24,3 +24,27 @@ = pr.text_field :last_name = f.submit t('.sign_up') = render :partial => "devise/shared/links" + + +%br +%br + +%h2 or, upload yourself + + += form_tag '/users/import', :multipart => true do + + %p + = label_tag 'user[email]' + = text_field_tag 'user[email]' + %p + = label_tag 'user[password]' + = password_field_tag 'user[password]' + %p + = label_tag 'user[password_confirmation]' + = password_field_tag 'user[password_confirmation]' + + %label Select File + = file_field 'upload', 'file' + = submit_tag "Upload" + diff --git a/config/routes.rb b/config/routes.rb index 8fbd132a87..47e73807ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,7 @@ Diaspora::Application.routes.draw do # added public route to user match 'public/:username', :to => 'users#public' match 'users/export', :to => 'users#export' + match 'users/import', :to => 'users#import' match 'users/export_photos', :to => 'users#export_photos' resources :users, :except => [:create, :new, :show] diff --git a/spec/lib/importer_spec.rb b/spec/lib/importer_spec.rb index d243ae345d..7f5469cc10 100644 --- a/spec/lib/importer_spec.rb +++ b/spec/lib/importer_spec.rb @@ -131,9 +131,6 @@ describe Diaspora::Importer do @user.serialized_private_key.should == @old_user.serialized_private_key end - it 'should ensure a match between persons public and private keys' do - pending - end end describe '#parse_aspects' do -- GitLab