From 607fea672277490d5fd98774f1adcd639e8dac3b Mon Sep 17 00:00:00 2001 From: Philip Champon Date: Mon, 27 Dec 2010 22:59:16 -0500 Subject: [PATCH] Handling bug http://bugs.joindiaspora.com/issues/767 Added email argument to task, warn and replace if address resolves to an invalid user@domain one. --- db/seeds/add_user.rb | 12 ++++++++++-- lib/tasks/db.rake | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/db/seeds/add_user.rb b/db/seeds/add_user.rb index af592fa3c..bb185aace 100644 --- a/db/seeds/add_user.rb +++ b/db/seeds/add_user.rb @@ -26,8 +26,16 @@ def read_password end username = (ARGS[:username] || 'admin').dup -email = ARGS[:email] || "#{username}@#{AppConfig[:pod_uri].host}" password = ARGS[:password] || read_password +email = ARGS[:email] || "#{username}@#{AppConfig[:pod_uri].host}" +if email =~ /localhost$/ + puts "WARNING: localhost will not validate as an email domain" + puts "\tupdate your email address, if you require email notifications for this account" + puts "\trake db:first_user[username,password,email]" + puts "\trake db:add_user[username,password]" + puts "\tor modify your data store" + email = 'username@example.com' +end user = User.build(:email => email, :username => username, @@ -46,7 +54,7 @@ user.valid? errors = user.errors errors.delete :person if errors.size > 0 - raise "Error(s) creating user #{username}: #{errors.full_messages.to_s}" + raise "Error(s) creating user #{username} / #{email}: #{errors.full_messages.to_s}" end user.save diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index bc2518292..50c97e167 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -21,7 +21,7 @@ namespace :db do create end - task :first_user, :username, :password do |t, args| + task :first_user, :username, :password, :email do |t, args| puts "Setting up first user in #{Rails.env} database" ARGS = args require File.dirname(__FILE__) + '/../../db/seeds/add_user' @@ -60,9 +60,9 @@ namespace :db do end desc "Purge database and then add the first user" - task :first_user, :username, :password do |t, args| + task :first_user, :username, :password, :email do |t, args| Rake::Task['db:purge'].invoke - Rake::Task['db:seed:first_user'].invoke(args[:username], args[:password]) + Rake::Task['db:seed:first_user'].invoke(args[:username], args[:password], args[:email]) end task :first_user => :environment