From 348b440c1e585dcc29ab556533c5815506b9c685 Mon Sep 17 00:00:00 2001 From: Colin Gross Date: Mon, 29 Feb 2016 15:53:02 -0500 Subject: [PATCH] Add default random password on user create. Allows validation to pass for creating user by email. Append @umich.edu to uniquename passed in from cosign. --- app/models/user.rb | 6 ++++++ .../behaviors/http_header_authenticatable_behavior.rb | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 79eeb1f5..66bd7893 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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, diff --git a/lib/devise/behaviors/http_header_authenticatable_behavior.rb b/lib/devise/behaviors/http_header_authenticatable_behavior.rb index 3b3addc8..616a501a 100644 --- a/lib/devise/behaviors/http_header_authenticatable_behavior.rb +++ b/lib/devise/behaviors/http_header_authenticatable_behavior.rb @@ -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