Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rake task to create users #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile.d/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
gem 'user-agent'

gem 'safe_yaml'
gem 'highline', :require => false
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -255,6 +256,7 @@ DEPENDENCIES
font-awesome-rails (< 4.0)
git!
has_metadata_column!
highline
jquery-rails
json
json-schema (< 2.0.0)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------------------

Expand Down
50 changes: 50 additions & 0 deletions lib/tasks/users.rb
Original file line number Diff line number Diff line change
@@ -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