diff --git a/.gitignore b/.gitignore index 7e636d4..2a08fef 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ node_modules yarn-error.log .byebug_history .env* +.env* diff --git a/Gemfile b/Gemfile index 6287adb..8551c21 100644 --- a/Gemfile +++ b/Gemfile @@ -28,4 +28,5 @@ group :development, :test do gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' gem 'dotenv-rails' + gem 'dotenv-rails', groups: [:development, :test] end diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index c325189..69a430a 100755 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -19,3 +19,4 @@ body { background-color: $background; } @import "devise/index"; +@import "users/index"; diff --git a/app/assets/stylesheets/users/_edit.scss b/app/assets/stylesheets/users/_edit.scss new file mode 100644 index 0000000..48c2d94 --- /dev/null +++ b/app/assets/stylesheets/users/_edit.scss @@ -0,0 +1,33 @@ +.profile-container { + margin: 0 1in; + display: flex; + justify-content: space-between; + align-items: center; + height: calc(100vh - 4.5em); // 4.5em is height of navbar + + form { + flex-grow: 1; + + .description { + width: 100%; + height: 5em; + } + } + + .profile-pic { + display: flex; + flex-direction: column; + align-items: center; + margin-left: 3em; + + img { + max-width: 50vw; + } + } +} + +.profile-form { + display: grid; + grid-template-columns: 1fr 1fr; + color: white; +} diff --git a/app/assets/stylesheets/users/_index.scss b/app/assets/stylesheets/users/_index.scss new file mode 100644 index 0000000..7147706 --- /dev/null +++ b/app/assets/stylesheets/users/_index.scss @@ -0,0 +1,2 @@ +@import "show"; +@import "edit"; diff --git a/app/assets/stylesheets/users/_show.scss b/app/assets/stylesheets/users/_show.scss new file mode 100644 index 0000000..b978a08 --- /dev/null +++ b/app/assets/stylesheets/users/_show.scss @@ -0,0 +1,51 @@ +.user-container { + margin: 0 1in; + height: calc(100vh - 4.5em); //4.5em is height of navbar. + display:flex; + flex-direction: column; + justify-content: center; + + h2 { + font-size: 1.5em; + } + .profile { + background: #33333D; + display: flex; + + .flex-end { + margin-left: auto; + display:flex; + align-items: center; + + a:first-child { + margin-right: .5em; + } + } + .profile-pic { + display: flex; + align-items: center; + margin-right: 3em; + img { + width: 10em; + } + } + + .profile-text { + display: flex; + flex-direction: column; + justify-content: center; + h1 { + margin: 0 0 .5em 0 ; + } + h2 { + margin: 0; + } + .italics { + font-style: italic; + color: white; + } + } + } + + } + diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..3901dc9 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,39 @@ +class UsersController < ApplicationController + before_action :find_user, only: [:edit, :update, :show, :destroy] + + def edit; end + + def update + @user.update(user_params) + redirect_to user_edit_path(@user) + end + + def create + # Untested Code + user = User.new(user_params) + authorize user # I don't know where to put this TODO: Test this method + if user.save + redirect_to user_path(user) + else + raise + end + end + + def show; end + + def destroy + @user.destroy + redirect_to root_path + end + + private + + def find_user + @user = User.find(params[:id]) + #authorize @user + end + + def user_params + params.require(:user).permit(:email, :first_name, :last_name, :description, :photo) + end +end diff --git a/app/models/user.rb b/app/models/user.rb index dfa148e..18122b7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ApplicationRecord + # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index d8081b7..e14295a 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -9,7 +9,24 @@
<%= link_to "Settings", "#" %>
- <%= image_tag "https://avatars2.githubusercontent.com/u/38472180?v=4", class: "img-circle"%> + <% if current_user.nil? %> + <%= link_to "Login", new_user_session_path %> + <% else %> + + <% end %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 0000000..b4310b8 --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,32 @@ +
+ <%= simple_form_for(@user) do |t| %> +
+
+ <%= t.input :email %> + <%= t.input :first_name %> + <%= t.input :last_name %> + <%= t.input :photo %> + <%= t.input :password %> + + <%= t.submit :Save, class: "btn btn-primary save-btn form-control" %> +

+ <%= link_to "View my profile", user_path(@user), class: "btn btn-primary save-btn form-control" %> +
+ + +
+ <% if @user.photo.nil? %> + <%= image_tag "https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png"%> + <% else %> + <%= cl_image_tag current_user.photo%> + <% end %> + + <%= t.input_field :photo, onchange: 'this.form.submit();' %> + <%= t.input_field :photo, as: :hidden %> + +
+ +
+ <% end %> +
+ diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000..51968c8 --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,2 @@ +

Users#index

+

Find me in app/views/users/index.html.erb

diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000..ce96bc4 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,2 @@ +

Users#index

+

Find me in app/views/users/new.html.erb

diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..68f8af0 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,26 @@ + + + +
+
+
+ <% if @user&.photo&.url.nil? %> + <%= image_tag "https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png", class: "img-circle"%> + <% else %> + <%= cl_image_tag @user.photo, class: "img-circle"%> + <% end %> + +
+
+

<%= @user.first_name %> <%= @user.last_name %>

+

<%= @user.email %>

+
+ +
+ <%= link_to "Edit Information", user_edit_path(@user), class: "btn btn-primary" %> + <%= link_to "Delete Account", user_path(@user), class: "btn btn-danger", method: :delete, data: { + confirm: "Are you sure?" + } %> +
+ +
diff --git a/config/routes.rb b/config/routes.rb index 31cada0..84772b8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,4 +21,10 @@ Rails.application.routes.draw do mount ActionCable.server, at: '/cable' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html get '/home', to: 'pages#home' + + + get '/users/:id', to: 'users#show', as: :user + get '/users/:id/edit', to: 'users#edit', as: :user_edit + patch '/users/:id', to: 'users#update' + delete '/users/:id', to: 'users#destroy' end diff --git a/db/migrate/20180829105638_add_first_name_to_users.rb b/db/migrate/20180829105638_add_first_name_to_users.rb new file mode 100644 index 0000000..7233f31 --- /dev/null +++ b/db/migrate/20180829105638_add_first_name_to_users.rb @@ -0,0 +1,7 @@ +class AddFirstNameToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :first_name, :string + add_column :users, :last_name, :string + add_column :users, :photo, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index cc819c1..3502be3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_27_151325) do +ActiveRecord::Schema.define(version: 2018_08_29_105638) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -30,6 +30,9 @@ ActiveRecord::Schema.define(version: 2018_08_27_151325) do t.datetime "remember_created_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "first_name" + t.string "last_name" + t.string "photo" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb new file mode 100644 index 0000000..314cd5a --- /dev/null +++ b/test/controllers/user_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000..6c3da77 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UsersControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end