Skip to content

Commit

Permalink
Add default random password on user create.
Browse files Browse the repository at this point in the history
  Allows validation to pass for creating user by email.
Append @umich.edu to uniquename passed in from cosign.
  • Loading branch information
grosscol committed Feb 29, 2016
1 parent b432c80 commit 348b440
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class User < ActiveRecord::Base
include Sufia::User
include Sufia::UserUsageStats

before_validation :generate_password, :on => :create

def generate_password
self.password = SecureRandom.urlsafe_base64(12)
end

# Use the http header as auth. This app will be behind a reverse proxy
# that will take care of the authentication.
Devise.add_module(:http_header_authenticatable,
Expand Down
5 changes: 3 additions & 2 deletions lib/devise/behaviors/http_header_authenticatable_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ def valid_user?(headers)

protected

# Remote user is coming back from cosign as uniquename.
# Append @umich.edu to this value to satisfy user model validations
def remote_user(headers)
return headers['HTTP_X_REMOTE_USER'] if headers['HTTP_X_REMOTE_USER']
return headers['HTTP_REMOTE_USER'] if headers['HTTP_REMOTE_USER'] && Rails.env.development?
return "#{headers['HTTP_X_REMOTE_USER']}@umich.edu" if headers['HTTP_X_REMOTE_USER']
return nil
end

Expand Down

0 comments on commit 348b440

Please sign in to comment.