From dc5b31243e554a733a78a8aa8f836cdfd42c1279 Mon Sep 17 00:00:00 2001 From: David Schuster Date: Mon, 20 Jan 2020 20:16:36 -0500 Subject: [PATCH 1/3] no longer overwrite first name if user already has one set --- app/controllers/users/omniauth_callbacks_controller.rb | 4 +++- app/views/users/edit.html.erb | 2 +- app/views/users/show.html.erb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 342bbd098..dbea567c9 100755 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -84,7 +84,9 @@ def shibboleth end if @user.email.include? "@buffalo.edu" - @user.first_name = data["info"]["name"] + if @user.first_name.nil? || @user.first_name.empty? + @user.first_name = data["info"]["name"] + end @user.last_name = data["info"]["last_name"] @user.person_number = data["info"]["person_number"] end diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 37d5e0dba..5dda1b9ea 100755 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -28,7 +28,7 @@ - <%= f.submit 'Save Changes', { :class=>"waves-effect waves-light btn primary"} %> + <%= f.submit 'Save Changes', { :class=>"btn primary"} %> <% end %> <% if current_user.administrator? %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 538c38c47..4e8464866 100755 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -22,7 +22,7 @@ -<%= link_to raw('Edit Information'), edit_user_path(@user) %>
+<%= link_to raw('Edit Information'), edit_user_path(@user) %>
<% if @user == current_user %> <%= link_to "Change your password", edit_user_registration_path %> -<% end %> +<% end %> \ No newline at end of file From c496d6918f909434bc98902df128215d77a55280 Mon Sep 17 00:00:00 2001 From: David Dobmeier Date: Tue, 21 Jan 2020 12:49:43 -0500 Subject: [PATCH 2/3] Update login logic to prevent overwriting of name on login --- .../users/omniauth_callbacks_controller.rb | 26 +++++++------------ app/views/users/show.html.erb | 2 +- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index dbea567c9..9658623a0 100755 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -6,7 +6,7 @@ def google_oauth2 if current_user.authentications.where(provider: data["provider"], uid: data["uid"]).empty? current_user.authentications.create(provider: data["provider"], - uid: data["uid"]+"@buffalo.edu") + uid: data["uid"]) end end redirect_to root_path @@ -31,7 +31,7 @@ def shibboleth uid: data["uid"]).empty? current_user.authentications.create(provider: "CMU-Shibboleth", uid: data["uid"]) - end + end end redirect_to root_path else @@ -39,7 +39,7 @@ def shibboleth if @user data = request.env["omniauth.auth"] - @user.first_name = data["info"]["name"] + # @user.first_name = data["info"]["name"] @user.last_name = data["info"]["last_name"] @user.person_number = data["info"]["person_number"] @user.save! @@ -55,13 +55,13 @@ def shibboleth @user.email = data["uid"]+"@buffalo.edu" # Set user info based on LDAP lookup - if @user.email.include? "@buffalo.edu" - @user.first_name = data["info"]["name"] - @user.last_name = data["info"]["last_name"] + if @user.email.include? "@buffalo.edu" + @user.first_name = data["info"]["name"] + @user.last_name = data["info"]["last_name"] @user.person_number = data["info"]["person_number"] - end - - if @user.email.include? "@andrew.cmu.edu" + end + + if @user.email.include? "@andrew.cmu.edu" ldapResult = User.ldap_lookup(@user.email.split("@")[0]) if ldapResult @user.first_name = ldapResult[:first_name] @@ -83,14 +83,6 @@ def shibboleth end - if @user.email.include? "@buffalo.edu" - if @user.first_name.nil? || @user.first_name.empty? - @user.first_name = data["info"]["name"] - end - @user.last_name = data["info"]["last_name"] - @user.person_number = data["info"]["person_number"] - end - @user.authentications.new(provider: "CMU-Shibboleth", uid: data["uid"]) @user.save! diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 4e8464866..094bceeb6 100755 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -25,4 +25,4 @@ <%= link_to raw('Edit Information'), edit_user_path(@user) %>
<% if @user == current_user %> <%= link_to "Change your password", edit_user_registration_path %> -<% end %> \ No newline at end of file +<% end %> From 37169f4f5bff664cf4cfca5a49218d71f8f5f6c5 Mon Sep 17 00:00:00 2001 From: David Dobmeier Date: Wed, 22 Jan 2020 13:46:44 -0500 Subject: [PATCH 3/3] Patch remaining locations where user names could have been overridden --- app/controllers/courses_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ed7e575ad..b1763cc77 100755 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -503,8 +503,8 @@ def save_uploaded_roster fail "New user cannot be created in uploadRoster." if user.nil? else # Override current user - user.first_name = first_name - user.last_name = last_name + # user.first_name = first_name + # user.last_name = last_name user.school = school user.major = major user.year = year @@ -554,8 +554,8 @@ def save_uploaded_roster end # Update user data - user.first_name = newCUD[:first_name] - user.last_name = newCUD[:last_name] + # user.first_name = newCUD[:first_name] + # user.last_name = newCUD[:last_name] user.school = newCUD[:school] user.major = newCUD[:major] user.year = newCUD[:year]