From 8c040a908b43ea8d401c8c6f81a89eb84df775a5 Mon Sep 17 00:00:00 2001 From: marcosbeirigo Date: Wed, 12 Feb 2014 11:46:11 -0300 Subject: [PATCH 1/2] added rake task to create users --- Gemfile.d/utilities.rb | 1 + Gemfile.lock | 2 ++ lib/tasks/users.rb | 50 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 lib/tasks/users.rb diff --git a/Gemfile.d/utilities.rb b/Gemfile.d/utilities.rb index 83a3020d..517f431f 100644 --- a/Gemfile.d/utilities.rb +++ b/Gemfile.d/utilities.rb @@ -17,3 +17,4 @@ gem 'user-agent' gem 'safe_yaml' +gem 'highline', :require => false diff --git a/Gemfile.lock b/Gemfile.lock index 1422ad47..a512508b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,6 +96,7 @@ GEM activerecord (>= 3.1) font-awesome-rails (3.2.1.3) railties (>= 3.2, < 5.0) + highline (1.6.20) hike (1.2.3) httpi (2.1.0) rack @@ -255,6 +256,7 @@ DEPENDENCIES font-awesome-rails (< 4.0) git! has_metadata_column! + highline jquery-rails json json-schema (< 2.0.0) diff --git a/lib/tasks/users.rb b/lib/tasks/users.rb new file mode 100644 index 00000000..7e61fd6d --- /dev/null +++ b/lib/tasks/users.rb @@ -0,0 +1,50 @@ +# Copyright 2014 Square Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'highline/import' + +namespace :users do + + task create: :environment do |t, args| + + user = get_user_data + + until user.valid? + say("Unable to create user:") + user.errors.full_messages.each do |err| + say("<%= color('#{err}', :red) %>") + user = get_user_data(user) + end + end + + user.create + end + + def get_user_data(user_data = User.new) + User.new do |user| + user.username = ask("username: ") { |q| q.default = user_data.username } + user.email_address = ask("email: ") { |q| q.default = user_data.email_address } + user.first_name = ask("first name: ") { |q| q.default = user_data.first_name } + user.last_name = ask("last name: ") { |q| q.default = user_data.last_name } + + until user.password == user.password_confirmation && user.password.present? + say("<%= color(\"Passwords don't match. Try Again\", :red) %>") if user.password.present? + user.password = ask("password: ") { |q| q.echo = false } + user.password_confirmation = ask("password confirmation: ") { |q| q.echo = false } + end + + end + end + +end From b44b5e8d4cc75fcf7a14d80e39113a02b423b5ae Mon Sep 17 00:00:00 2001 From: marcosbeirigo Date: Wed, 12 Feb 2014 11:55:19 -0300 Subject: [PATCH 2/2] updating README with info on how to create users using the rake task --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4fb8049f..4a679238 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,9 @@ members to administrator status, and modify/delete others' Comments. **Owners** (each Project has only one) can do everything administrators can do, and can also delete the Project and reassign ownership. +If you disable user registration on ```authentication.yml```, you can add new users +using the ```rake users:create``` task. It will prompt for user data and perform validations. + Recording and Categorizing Occurrences --------------------------------------