Skip to content

Commit

Permalink
Fixes #63 user profile (#71)
Browse files Browse the repository at this point in the history
* added user profile

* added user profile

* cursor-pointer fix

* added aws s3 for active storage production

* added aws s3 fix

* Delete avatar feature added

* profile path on save added

* avtar changed to avatar fix

Co-authored-by: Aniket Kaushik <aniket@saeloun.com>
Co-authored-by: Akhil G Krishnan <akhilgkrishnan4u@gmail.com>
  • Loading branch information
3 people authored Jan 13, 2022
1 parent d5aa55b commit 23a8504
Show file tree
Hide file tree
Showing 22 changed files with 383 additions and 69 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ SENDGRID_USERNAME='apikey'
SENDGRID_PASSWORD=
SMTP_DOMAIN='saeloun.com'
SMTP_PORT=587

# AWS S3 Credentials
AWS_ACCESS_KEY_ID: "<Replace with aws S3 access key id>"
AWS_SECRET_ACCESS_ID: "<Replace with aws S3 secret access key>"
AWS_S3_BUCKET_NAME: "<Replace with AWS S3 bucket name>"
AWS_REGION: "<Replace with AWS S3 Region>"
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ gem "letter_opener_web"
# currency list and conversion
gem "money"

# aws storage account
gem "aws-sdk-s3", require: false

group :development, :test do
# See https://edgeguides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", ">= 1.0.0", platforms: %i[mri mingw x64_mingw]
Expand Down
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ GEM
activerecord (>= 2.3.0)
rake (>= 0.8.7)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.547.0)
aws-sdk-core (3.125.2)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.53.0)
aws-sdk-core (~> 3, >= 3.125.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.111.1)
aws-sdk-core (~> 3, >= 3.125.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
aws-sigv4 (1.4.0)
aws-eventstream (~> 1, >= 1.0.2)
babel-source (5.8.35)
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
Expand Down Expand Up @@ -143,6 +159,7 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jmespath (1.5.0)
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.7.0)
Expand Down Expand Up @@ -355,6 +372,7 @@ PLATFORMS

DEPENDENCIES
annotate
aws-sdk-s3
bootsnap (>= 1.4.4)
capybara (>= 3.26)
countries
Expand Down
File renamed without changes
4 changes: 4 additions & 0 deletions app/assets/images/cancel_button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/assets/images/delete_image_button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/assets/images/edit_image_button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/assets/images/logout_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/assets/images/plus_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/assets/images/save_button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/assets/images/setting_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@
class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_permitted_parameters

def purge_avatar
user = User.find(params[:id])
user.avatar.destroy
redirect_to profile_path
end

protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :email, :password, :password_confirmation])
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :email, :password, :password_confirmation, :avatar])
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :email, :password, :password_confirmation, :avatar])
end

def update_resource(resource, params)
if params[:current_password].blank?
resource.update_without_password(params.except(:current_password))
else
resource.update_with_password(params)
end
end

def after_update_path_for(resource)
profile_path
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# frozen_string_literal: true

module ApplicationHelper
def user_avatar(user)
if user.avatar.attached?
user.avatar
else
image_url "avatar.svg"
end
end
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class User < ApplicationRecord

after_create :assign_default_role

has_one_attached :avatar

private
def assign_default_role
self.add_role(:owner) if self.roles.blank?
Expand Down
Loading

0 comments on commit 23a8504

Please sign in to comment.