diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index fe93333..4e7f117 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -8,3 +8,8 @@ * * Consider organizing styles into separate files for maintainability. */ + + +.avatar { + border-radius: 50%; +} diff --git a/app/models/user.rb b/app/models/user.rb index 48f53e5..e987cf2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,7 @@ class User < ApplicationRecord validates :email, presence: true, uniqueness: true validates :slack_uid, presence: true, uniqueness: true + validates :username, presence: true def self.authorize_url(redirect_uri) params = { @@ -8,7 +9,7 @@ class User < ApplicationRecord # scope: "identity.basic,identity.email", redirect_uri: redirect_uri, state: SecureRandom.hex(24), - user_scope: "identity.basic,identity.email" + user_scope: "identity.basic,identity.email,identity.avatar" } r = "https://slack.com/oauth/v2/authorize?#{params.to_query}" @@ -39,6 +40,8 @@ class User < ApplicationRecord user = find_or_initialize_by(slack_uid: user_data["user"]["id"]) user.email = user_data["user"]["email"] + user.username = user_data["user"]["name"] + user.avatar_url = user_data["user"]["image_192"] || user_data["user"]["image_72"] user.save! user rescue => e diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 89946a0..c16fae7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -26,8 +26,8 @@
<% if current_user %>
- <%# image_tag current_user.image if current_user.image %> - <%# current_user.name %> + <%= image_tag current_user.avatar_url, size: "32x32", class: "avatar" if current_user.avatar_url %> + <%= current_user.username if current_user.username %> <%= link_to "Sign Out", signout_path, method: :delete, data: { "turbo-method": :delete } %>
<% else %> diff --git a/db/migrate/20240320000000_add_profile_fields_to_users.rb b/db/migrate/20240320000000_add_profile_fields_to_users.rb new file mode 100644 index 0000000..422cc30 --- /dev/null +++ b/db/migrate/20240320000000_add_profile_fields_to_users.rb @@ -0,0 +1,6 @@ +class AddProfileFieldsToUsers < ActiveRecord::Migration[8.0] + def change + add_column :users, :username, :string + add_column :users, :avatar_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 243a477..afc1dd1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,12 +10,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2024_01_01_000000) do +ActiveRecord::Schema[8.0].define(version: 2024_03_20_000000) do create_table "users", force: :cascade do |t| t.string "slack_uid", null: false t.string "email", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "username" + t.string "avatar_url" t.index ["slack_uid"], name: "index_users_on_slack_uid", unique: true end end