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

Add support for GitHub and ORCID identifiers, plus enhancements to user account management #321

Merged
merged 24 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ff680ba
Refactor the account creation page
jvendetti May 13, 2024
9ea90ed
Remove superfluous comments
jvendetti May 13, 2024
a11aa39
Fix some RuboCop warnings
jvendetti May 13, 2024
74d4bd1
Display GitHub and ORCID identifiers
jvendetti Jun 14, 2024
881fb0d
Create users_helper.rb
jvendetti Jun 19, 2024
3cc788f
Refactor account show and edit pages
jvendetti Jul 1, 2024
2736b4d
Merge branch 'master' into feature/add-signup-fields/315
jvendetti Jul 3, 2024
2d21892
Render the new password edit page for resets
jvendetti Jul 3, 2024
2f0f39d
Fix some RuboCop warnings
jvendetti Jul 3, 2024
2faa257
Use newer style syntax for render
jvendetti Jul 4, 2024
9605a9c
Rename login index with HAML extension
jvendetti Jul 4, 2024
43ba3c5
Convert file content from ERB to HAML
jvendetti Jul 4, 2024
ef8c0b3
Replace form_for with form_with
jvendetti Jul 4, 2024
b46d485
Refactor the login page
jvendetti Jul 10, 2024
377bcb8
Rename lost_password with HAML extension
jvendetti Jul 10, 2024
00d83aa
Convert file content from ERB to HAML
jvendetti Jul 10, 2024
6e6d166
Replace form_for with form_with
jvendetti Jul 10, 2024
a06d0d1
Refactor lost password page
jvendetti Jul 11, 2024
4330abf
Remove commented out code
jvendetti Jul 11, 2024
a377417
Add Stimulus clipboard controller
jvendetti Jul 12, 2024
94b091b
Add copy to clipboard for user API keys
jvendetti Jul 12, 2024
b67e485
Remove logic and form for password updates
jvendetti Jul 13, 2024
10acc0e
Delete _form.html.haml
jvendetti Jul 13, 2024
466e8fc
Merge branch 'master' into feature/add-signup-fields/315
jvendetti Jul 22, 2024
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
53 changes: 53 additions & 0 deletions app/assets/stylesheets/account.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.signup {
display: flex;
align-items: center;
justify-content: center;
padding-top: 40px;
padding-bottom: 40px;
}

.form-signup {
width: 100%;
max-width: 400px;
padding: 15px;
margin: 0 auto;

a {
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

h4, p {
text-align: center;
}
}

.form-signup .enable-lists {
color: red;
}

.edit-user-info {
display: flex;
align-items: center;
justify-content: center;

form {
width: 100%;
max-width: 640px;
padding: 15px;
margin: 0 auto;
}
}

.account-info {
a {
text-decoration: none;
}

a:hover {
text-decoration: underline;
}
}
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

/* BioPortal */
@import "admin";
@import "account";
@import "annotator";
@import "bioportal";
@import "concepts";
@import "footer";
@import "home";
@import "login";
@import "mappings";
@import "notes";
@import "notice";
Expand Down
41 changes: 41 additions & 0 deletions app/assets/stylesheets/login.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.signin {
display: flex;
align-items: center;
justify-content: center;
padding-top: 40px;
padding-bottom: 40px;
}

.form-signin {
width: 100%;
max-width: 400px;
padding: 15px;
margin: 0 auto;

a {
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

h4, p {
text-align: center;
}
}

.form-signin .enable-lists {
color: red;
}

.password-reset {
display: flex;
justify-content: center;
padding-top: 40px;
padding-bottom: 40px;

form {
max-width: 640px;
}
}
12 changes: 8 additions & 4 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ def account
@user_ontologies = @user.customOntology
@user_ontologies ||= []

onts = LinkedData::Client::Models::Ontology.all
@admin_ontologies = onts.select { |o| o.administeredBy.include? @user.id }
@admin_ontologies = LinkedData::Client::Models::Ontology.where do |o|
o.administeredBy.include? @user.id
end
@admin_ontologies.sort! { |a, b| a.name.downcase <=> b.name.downcase }

projects = LinkedData::Client::Models::Project.all
@user_projects = projects.select { |p| p.creator.include? @user.id }
@user_projects = LinkedData::Client::Models::Project.where do |p|
p.creator.include? @user.id
end
@user_projects.sort! { |a, b| a.name.downcase <=> b.name.downcase }

render 'users/show'
end
Expand Down
61 changes: 29 additions & 32 deletions app/controllers/login_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
class LoginController < ApplicationController
# frozen_string_literal: true

class LoginController < ApplicationController
layout :determine_layout

def index
# Sets the redirect properties
if params[:redirect]
# Get the original, encoded redirect
uri = URI.parse(request.url)
orig_params = Hash[uri.query.split("&").map {|e| e.split("=",2)}].symbolize_keys
orig_params = Hash[uri.query.split("&").map { |e| e.split("=", 2) }].symbolize_keys
session[:redirect] = orig_params[:redirect]
else
session[:redirect] = request.referer
Expand All @@ -17,31 +18,30 @@ def index
# logs in a user
def create
@errors = validate(params[:user])
if @errors.size < 1
if @errors.empty?
logged_in_user = LinkedData::Client::Models::User.authenticate(params[:user][:username], params[:user][:password])
if logged_in_user && !logged_in_user.errors
login(logged_in_user)
redirect = "/"
redirect = '/'

if session[:redirect]
redirect = CGI.unescape(session[:redirect])
end


redirect_to redirect
else
@errors << "Invalid account name/password combination"
render :action => 'index'
@errors << 'Invalid account name/password combination'
render 'index'
end
else
render :action => 'index'
render 'index'
end
end

# Login as the provided username (only for admin users)
def login_as
unless session[:user] && session[:user].admin?
redirect_to "/"
redirect_to '/'
return
end

Expand All @@ -54,8 +54,8 @@ def login_as
session[:user].apikey = session[:admin_user].apikey
end

#redirect_to request.referer rescue redirect_to "/"
redirect_to "/"
# redirect_to request.referer rescue redirect_to "/"
redirect_to '/'
end

# logs out a user
Expand All @@ -67,65 +67,62 @@ def destroy
flash[:success] = "Logged out <b>#{old_user.username}</b>, returned to <b>#{session[:user].username}</b>".html_safe
else
session[:user] = nil
flash[:success] = "You have successfully logged out"
flash[:success] = 'You have successfully logged out'
end
redirect_to request.referer || "/"
redirect_to request.referer || '/'
end

def lost_password
end
def lost_password; end

# Sends a new password to the user
def send_pass
username = params[:user][:account_name]
email = params[:user][:email]
resp = LinkedData::Client::HTTP.post("/users/create_reset_password_token", {username: username, email: email})
resp = LinkedData::Client::HTTP.post('/users/create_reset_password_token', { username: username, email: email })

if resp.nil?
redirect_to login_index_path, notice: "Please check your email for a message with reset instructions"
redirect_to login_index_path, notice: 'Please check your email for a message with reset instructions'
else
flash[:notice] = resp.errors.first + ". Please try again."
redirect_to "/lost_pass"
flash[:notice] = "#{resp.errors.first}. Please try again."
redirect_to '/lost_pass'
end
end

def reset_password
username = params[:un]
email = params[:em]
token = params[:tk]
@user = LinkedData::Client::HTTP.post("/users/reset_password", {username: username, email: email, token: token})
@user = LinkedData::Client::HTTP.post('/users/reset_password', { username: username, email: email, token: token })
if @user.is_a?(LinkedData::Client::Models::User)
@user.validate_password = true
login(@user)
render "users/edit"
render 'passwords/edit'
else
flash[:notice] = @user.errors.first + ". Please reset your password again."
redirect_to "/lost_pass"
flash[:notice] = "#{@user.errors.first}. Please reset your password again."
redirect_to '/lost_pass'
end
end

private

def login(user)
return unless user

session[:user] = user
custom_ontologies_text = session[:user].customOntology && !session[:user].customOntology.empty? ? "The display is now based on your <a href='/account#custom_ontology_set'>Custom Ontology Set</a>." : ""
notice = "Welcome <b>" + user.username.to_s + "</b>! " + custom_ontologies_text
flash[:success] = notice.html_safe
end

def validate(params)
errors=[]
errors = []

if params[:username].nil? || params[:username].length <1
errors << "Please enter an account name"
if params[:username].empty?
errors << 'Please enter an account name'
end
if params[:password].nil? || params[:password].length <1
errors << "Please enter a password"
if params[:password].empty?
errors << 'Please enter a password'
end

return errors
errors
end


end
45 changes: 45 additions & 0 deletions app/controllers/passwords_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

class PasswordsController < ApplicationController
before_action :require_logged_in_user
before_action :set_user

layout :determine_layout

def edit; end

def update
if params[:password] != params[:password_confirmation]
flash.now[:warning] = 'New password and password confirmation do not match. Please try again.'
render 'edit'
return
end

response = @user.update(values: { password: params[:password] })
if response_error?(response)
@errors = response_errors(response)
render 'edit'
else
flash[:success] = 'Password successfully updated!'
redirect_to user_path(@user.username)
end
end

private

def password_params
p = params.permit(:password, :password_confirmation)
p.to_h
end

def require_logged_in_user
if session[:user].blank?
flash[:warning] = 'You must be logged in to access that page'
redirect_to login_index_path
end
end

def set_user
@user = session[:user]
end
end
Loading
Loading