-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Users can now edit their profile and account settings
- Loading branch information
1 parent
66fd893
commit d4adcae
Showing
27 changed files
with
543 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
packages: | ||
yum: | ||
ImageMagick: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
# Displays user profile pictures. | ||
class ProfilesController < ApplicationController | ||
before_action :find_user, only: [:picture] | ||
|
||
def picture | ||
profile_picture = if params[:thumb] == "1" | ||
@user&.profile_picture&.thumb | ||
else | ||
@user&.profile_picture | ||
end | ||
|
||
if Rails.env.production? | ||
if profile_picture&.url.present? | ||
redirect_to profile_picture.url(query: { "response-content-disposition" => "inline" }) | ||
else | ||
head :ok | ||
end | ||
else | ||
send_file_if_present profile_picture, disposition: "inline" | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_user | ||
@user = User.current.find_by("LOWER(username) = ?", params[:id].to_s.downcase) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# frozen_string_literal: true | ||
|
||
class SettingsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
layout "layouts/full_page_sidebar" | ||
|
||
# # GET /settings/profile | ||
# def profile | ||
# end | ||
|
||
# PATCH /settings/profile | ||
def update_profile | ||
if current_user.update(profile_params) | ||
redirect_to settings_profile_path, notice: "Profile successfully updated." | ||
else | ||
render :profile | ||
end | ||
end | ||
|
||
# PATCH /settings/complete-profile | ||
def complete_profile | ||
if current_user.update(complete_profile_params) | ||
redirect_to dashboard_path, notice: "Profile successfully updated." | ||
else | ||
redirect_to dashboard_path | ||
end | ||
end | ||
|
||
# PATCH /settings/profile/picture | ||
def update_profile_picture | ||
if current_user.update(profile_picture_params) | ||
redirect_to settings_profile_path, notice: "Profile picture successfully updated." | ||
else | ||
render :profile | ||
end | ||
end | ||
|
||
# # GET /settings/account | ||
# def account | ||
# end | ||
|
||
# PATCH /settings/account | ||
def update_account | ||
if current_user.update(account_params) | ||
redirect_to settings_account_path, notice: "Account successfully updated." | ||
else | ||
render :account | ||
end | ||
end | ||
|
||
# PATCH /settings/password | ||
def update_password | ||
if current_user.valid_password?(params[:user][:current_password]) | ||
if current_user.reset_password(params[:user][:password], params[:user][:password_confirmation]) | ||
bypass_sign_in current_user | ||
redirect_to settings_account_path, notice: "Your password has been changed." | ||
else | ||
render :account | ||
end | ||
else | ||
current_user.errors.add(:current_password, "is invalid") | ||
render :account | ||
end | ||
end | ||
|
||
# # GET /settings/email | ||
# def email | ||
# end | ||
|
||
# PATCH /settings/email | ||
def update_email | ||
if current_user.update(email_params) | ||
redirect_to settings_email_path, notice: I18n.t("devise.confirmations.send_instructions") | ||
else | ||
render :email | ||
end | ||
end | ||
|
||
private | ||
|
||
def complete_profile_params | ||
params.require(:user).permit(:phone, :role, :profile_picture) | ||
end | ||
|
||
def profile_params | ||
params.require(:user).permit(:username, :phone, :role) | ||
end | ||
|
||
def profile_picture_params | ||
params.require(:user).permit(:profile_picture, :remove_profile_picture) | ||
end | ||
|
||
def account_params | ||
params.require(:user).permit(:full_name) | ||
end | ||
|
||
def email_params | ||
params.require(:user).permit(:email, :emails_enabled) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
# Helps generate URLs for user profile pictures. | ||
module ProfilesHelper | ||
def profile_picture_tag(user, size: 128, style: nil) | ||
image_tag( | ||
picture_profile_path(user.username, thumb: size <= 64 ? "1" : nil), | ||
alt: "", | ||
class: "rounded img-ignore-selection", | ||
style: "max-height: #{size}px; max-width: #{size}px;" | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
# Resizes uploaded images to preset dimensions | ||
class ResizableImageUploader < CarrierWave::Uploader::Base | ||
include CarrierWave::MiniMagick | ||
|
||
# Choose what kind of storage to use for this uploader: | ||
storage Rails.env.production? ? :fog : :file | ||
|
||
# Override the directory where uploaded files will be stored. | ||
# This is a sensible default for uploaders that are meant to be mounted: | ||
def store_dir | ||
File.join(model.class.to_s.underscore.pluralize, model.id.to_s, mounted_as.to_s) | ||
end | ||
|
||
# Provide a default URL as a default if there hasn't been a file uploaded: | ||
# def default_url | ||
# # For Rails 3.1+ asset pipeline compatibility: | ||
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) | ||
# | ||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_') | ||
# end | ||
|
||
# Process files as they are uploaded: | ||
process resize_to_limit: [256, 256] | ||
|
||
# Create different versions of your uploaded files: | ||
version :thumb do | ||
process resize_to_fill: [64, 64] | ||
end | ||
|
||
# Add a white list of extensions which are allowed to be uploaded. | ||
def extension_whitelist | ||
%w(jpg jpeg gif png) | ||
end | ||
|
||
# Override the filename of the uploaded files: | ||
# Avoid using model.id or version_name here, see uploader/store.rb for details. | ||
def filename | ||
"image#{File.extname(original_filename)}" if original_filename | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.key-contact | ||
.key-contact-icon | ||
- if user[:profile_picture] | ||
= profile_picture_tag(user, size: 64) | ||
- else | ||
.px-2= icon("far", "user", class: "fa-3x") | ||
.key-contact-info | ||
.key-contact-name | ||
= user.full_name | ||
.key-contact-role= user.role | ||
.key-contact-email= user.email | ||
.key-contact-phone= user.phone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
= form_with model: user, url: settings_complete_profile_path, method: :patch, local: true do |form| | ||
= render "forms/vertical/text_field", form: form, object: user, key: :role, key_name: "Project role", help_text: "Ex: Project Manager, DSMB Member, Co-Investigator, Study Coordinator, etc." if user.role.blank? | ||
= render "forms/vertical/text_field", form: form, object: user, key: :phone, help_text: "Format: 555-555-5555" if user.phone.blank? | ||
= render "forms/vertical/file_field", form: form, object: user, key: :profile_picture, help_text: "Square pictures work best. Supported file formats JPG, PNG, and GIF." | ||
= render "forms/vertical/submit", form: form, object: user, submit_text: "Update profile", cancel: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.