diff --git a/Gemfile b/Gemfile index bf629fa..61ea1c7 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,13 @@ gem 'rails', '~> 5.2.2' gem 'pg', '>= 0.18', '< 2.0' # Use Puma as the app server gem 'puma', '~> 3.11' +gem 'devise', '~> 4.6', '>= 4.6.1' + +gem 'carrierwave', '~> 0.10.0' +gem 'mini_magick', '~> 4.3' + +gem 'bootstrap' +gem 'jquery-rails' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets diff --git a/Gemfile.lock b/Gemfile.lock index adbb6d4..d77806d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,9 +47,16 @@ GEM archive-zip (0.12.0) io-like (~> 0.3.0) arel (9.0.0) + autoprefixer-rails (9.4.10.2) + execjs + bcrypt (3.1.12) bindex (0.5.0) bootsnap (1.4.1) msgpack (~> 1.0) + bootstrap (4.3.1) + autoprefixer-rails (>= 9.1.0) + popper_js (>= 1.14.3, < 2) + sassc-rails (>= 2.0.0) builder (3.2.3) byebug (11.0.0) capybara (3.14.0) @@ -60,6 +67,11 @@ GEM rack-test (>= 0.6.3) regexp_parser (~> 1.2) xpath (~> 3.2) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) chromedriver-helper (2.1.0) @@ -67,6 +79,12 @@ GEM nokogiri (~> 1.8) concurrent-ruby (1.1.4) crass (1.0.4) + devise (4.6.1) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 6.0) + responders + warden (~> 1.2.3) erubi (1.8.0) execjs (2.7.0) ffi (1.10.0) @@ -78,6 +96,11 @@ GEM jbuilder (2.8.0) activesupport (>= 4.2.0) multi_json (>= 1.2) + jquery-rails (4.3.3) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (2.2.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -90,7 +113,11 @@ GEM marcel (0.3.3) mimemagic (~> 0.3.2) method_source (0.9.2) + mime-types (3.2.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2018.0812) mimemagic (0.3.3) + mini_magick (4.9.3) mini_mime (1.0.1) mini_portile2 (2.4.0) minitest (5.11.3) @@ -99,7 +126,9 @@ GEM nio4r (2.3.1) nokogiri (1.10.1) mini_portile2 (~> 2.4.0) + orm_adapter (0.5.0) pg (1.1.4) + popper_js (1.14.5) public_suffix (3.0.3) puma (3.12.0) rack (2.0.6) @@ -134,6 +163,9 @@ GEM rb-inotify (0.10.0) ffi (~> 1.0) regexp_parser (1.3.0) + responders (2.4.1) + actionpack (>= 4.2.0, < 6.0) + railties (>= 4.2.0, < 6.0) ruby_dep (1.5.0) rubyzip (1.2.2) sass (3.7.3) @@ -147,6 +179,15 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + sassc (2.0.1) + ffi (~> 1.9) + rake + sassc-rails (2.1.0) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt selenium-webdriver (3.141.0) childprocess (~> 0.5) rubyzip (~> 1.2, >= 1.2.2) @@ -169,6 +210,8 @@ GEM thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) + warden (1.2.8) + rack (>= 2.0.6) web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) @@ -185,11 +228,16 @@ PLATFORMS DEPENDENCIES bootsnap (>= 1.1.0) + bootstrap byebug capybara (>= 2.15) + carrierwave (~> 0.10.0) chromedriver-helper + devise (~> 4.6, >= 4.6.1) jbuilder (~> 2.5) + jquery-rails listen (>= 3.0.5, < 3.2) + mini_magick (~> 4.3) pg (>= 0.18, < 2.0) puma (~> 3.11) rails (~> 5.2.2) diff --git a/app/assets/javascripts/books.js b/app/assets/javascripts/books.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/books.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/comments.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/home.js b/app/assets/javascripts/home.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/home.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 91% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index d05ea0f..3ff9152 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -13,3 +13,7 @@ *= require_tree . *= require_self */ + + @import 'bootstrap'; + @import 'books.scss'; + @import 'home.scss'; diff --git a/app/assets/stylesheets/books.scss b/app/assets/stylesheets/books.scss new file mode 100644 index 0000000..42c3615 --- /dev/null +++ b/app/assets/stylesheets/books.scss @@ -0,0 +1,36 @@ +// Place all the styles related to the Books controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +.header_table{ + background-color: rgb(192, 226, 245); + color: black; + font-size: 19px; + font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; +} + +.cell_table{ + background-color: rgba(241, 246, 248, 0.651); + font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; + font-size: 20px; + color: black; +} + +.My_book{ + font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; + color: black; + font-size: 45px; + text-decoration: underline; +} +.operation_icon{ + background-color: rgb(109, 189, 236); +} +.operation{ + background-color: rgba(225, 240, 248, 0.74); + +} +.header{ + width: 180px; +} +.des{ + width: 730px; +} \ No newline at end of file diff --git a/app/assets/stylesheets/comments.scss b/app/assets/stylesheets/comments.scss new file mode 100644 index 0000000..e730912 --- /dev/null +++ b/app/assets/stylesheets/comments.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Comments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 0000000..7131aac --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..6045188 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,84 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + + &:visited { + color: #666; + } + + &:hover { + color: #fff; + background-color: #000; + } +} + +th { + padding-bottom: 5px; +} + +td { + padding: 0 5px 7px; +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} + +label { + display: block; +} diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000..7803a79 --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,90 @@ +class BooksController < ApplicationController + before_action :authenticate_user!,except: [:index, :show] + before_action :set_book, only: [:show, :edit, :update, :destroy] + # + + # GET /books + # GET /books.json + def index + if current_user + @books = current_user.books + else + redirect_to books_path(@book) + end + end + + # GET /books/1 + # GET /books/1.json + def show + user_edit + end + + # GET /books/new + def new + @book = Book.new + end + + # GET /books/1/edit + def edit + user_edit + end + + # POST /books + # POST /books.json + def create + @book = current_user.books.build(book_params) + respond_to do |format| + if @book.save + format.html { redirect_to @book, notice: 'Book was successfully created.' } + format.json { render :show, status: :created, location: @book } + else + format.html { render :new } + format.json { render json: @book.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /books/1 + # PATCH/PUT /books/1.json + def update + respond_to do |format| + if @book.update(book_params) + format.html { redirect_to @book, notice: 'Book was successfully updated.' } + format.json { render :show, status: :ok, location: @book } + else + format.html { render :edit } + format.json { render json: @book.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /books/1 + # DELETE /books/1.json + def destroy + @book.destroy + respond_to do |format| + format.html { redirect_to books_url, notice: 'Book was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_book + @book = Book.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def book_params + params.require(:book).permit(:title, :author, :description, :image, :category) + end + + def user_edit + if (user_signed_in? && (current_user.id == @book.user_id)) + @can_edit = true + else + @can_edit = false + end + end + +end \ No newline at end of file diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..5e2b169 --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,16 @@ +class CommentsController < ApplicationController + def create + @book = Book.find(params[:book_id]) + @comment = @book.comments.create(comment_params) + redirect_to books_id_path(@book) + end + + def index + end + + private + def comment_params + params.require(:comment).permit(:comment, :commenter) + end + +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..0524087 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,13 @@ +class HomeController < ApplicationController + def index + @books = Book.all + my_book + end + def my_book + if (user_signed_in?) + @has_books = true + else + @has_books = false + end + end +end \ No newline at end of file diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000..4b9311e --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000..0ec9ca5 --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000..879aa7d --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,5 @@ +class Book < ApplicationRecord + has_many :comments , dependent: :destroy + belongs_to :user + mount_uploader :image, ImageUploader +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..7b1cda1 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,3 @@ +class Comment < ApplicationRecord + belongs_to :book +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..532194d --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,9 @@ +class User < ApplicationRecord + has_many :books, dependent: :destroy + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + validates :email, presence: true, format: /\w+@\w+\.{1}[a-zA-Z]{2,}/ + + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable +end diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb new file mode 100644 index 0000000..4861131 --- /dev/null +++ b/app/uploaders/image_uploader.rb @@ -0,0 +1,51 @@ +# encoding: utf-8 + +class ImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + # include CarrierWave::RMagick + include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # 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 + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + 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 :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process :resize_to_fit => [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_white_list + %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 + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/books/_book.json.jbuilder b/app/views/books/_book.json.jbuilder new file mode 100644 index 0000000..b12aab1 --- /dev/null +++ b/app/views/books/_book.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! book, :id, :title, :author, :description, :image, :category, :created_at, :updated_at +json.url book_url(book, format: :json) diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb new file mode 100644 index 0000000..9843950 --- /dev/null +++ b/app/views/books/_form.html.erb @@ -0,0 +1,45 @@ +<%= form_with(model: book, local: true) do |form| %> + <% if book.errors.any? %> +
+

<%= pluralize(book.errors.count, "error") %> prohibited this book from being saved:

+ + +
+ <% end %> + + +
+ <%= form.label :title %> + <%= form.text_field :title %> +
+ +
+ <%= form.label :author %> + <%= form.text_field :author %> +
+ +
+ <%= form.label :description %> + <%= form.text_field :description %> +
+ +
+ <%= form.label :image %> + <%= form.file_field :image %> +
+ +
+ <%= form.label :category %> + <%= form.select :category, ['Arts & Music', 'Business', 'Kids' , 'Computers & Tech' , 'Cooking' , 'Medical' , 'Religion' , 'Sports' , 'Travel' , 'Entertainment' , 'History' , 'Edictation']%> +
+ + + +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb new file mode 100644 index 0000000..8578ffc --- /dev/null +++ b/app/views/books/edit.html.erb @@ -0,0 +1,11 @@ +<% if @can_edit %> +

Editing Book

+ + +<%= render 'form', book: @book %> + +<%= link_to 'Show', @book %> | +<%= link_to 'Back', books_path %> +<% else %> +

forbiden

+<% end %> \ No newline at end of file diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000..36a18f1 --- /dev/null +++ b/app/views/books/index.html.erb @@ -0,0 +1,47 @@ +

<%= notice %>

+ + +


+
+
+ + +

My Books📖

+
+ + + + + + + + + + + + + + <% @books.each do |book| %> + + + + + + + + + + + <% end %> + +
TitleAuthorDescription ImageCategory 👓 🖊🗑
<%= book.title %> <%= book.author %><%= book.description %> + + <% if book.image.url != nil %> + <%= image_tag book.image.url , class:"img-responsive", style: "width: 14rem; height: 200px;"%> + <%else%> + <%= image_tag 'https://png.pngtree.com/element_pic/17/07/27/bd157c7c747dc708790aa64b43c3da35.jpg', class:"img-responsive", style: "width: 14rem; height: 200px;" %> + <%end%> + <%= book.category %><%= link_to 'Show', book %><%= link_to 'Edit', edit_book_path(book) %><%= link_to 'Destroy', book, method: :delete, data: { confirm: 'Are you sure?' } %>
+
+
+ \ No newline at end of file diff --git a/app/views/books/index.json.jbuilder b/app/views/books/index.json.jbuilder new file mode 100644 index 0000000..7ee9cfe --- /dev/null +++ b/app/views/books/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @books, partial: 'books/book', as: :book diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000..9607d41 --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1,5 @@ +

New Book

+ +<%= render 'form', book: @book %> + +<%= link_to 'Back', books_path %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb new file mode 100644 index 0000000..9ffc7b8 --- /dev/null +++ b/app/views/books/show.html.erb @@ -0,0 +1,44 @@ +

<%= notice %>

+ +

+ Title: + <%= @book.title %> +

+ +

+ Author: + <%= @book.author %> +

+ +

+ Description: + <%= @book.description %> +

+ +

+Image: +<% if @book.image.url != nil %> + <%= image_tag @book.image.url %> +<%else%> +<%= image_tag 'http://insignia.sd23.bc.ca/Library/images/cover/book.png' %> +<%end%> +

+ +

+ Category: + <%= @book.category %> +

+ + +

Comments

+<%= render @book.comments %> + +

Add a comment:

+<%= render 'comments/form' %> + + +<%= link_to 'Back', books_path %> + +<% if @can_edit %> +<%= link_to "Edit", edit_book_path(@book)%> +<% end %> diff --git a/app/views/books/show.json.jbuilder b/app/views/books/show.json.jbuilder new file mode 100644 index 0000000..c1e5174 --- /dev/null +++ b/app/views/books/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "books/book", book: @book diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb new file mode 100644 index 0000000..69c21bf --- /dev/null +++ b/app/views/comments/_comment.html.erb @@ -0,0 +1,9 @@ +

+Commenter: +<%= comment.commenter %> +

+ +

+Comment: +<%= comment.comment %> +

\ No newline at end of file diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb new file mode 100644 index 0000000..cc47475 --- /dev/null +++ b/app/views/comments/_form.html.erb @@ -0,0 +1,15 @@ +<%= form_with(model: [ @book, @book.comments.build ], local: true) do |form| %> +

+ <%= form.label :commenter %>
+ <%= form.text_field :commenter %> +

+ +

+ <%= form.label :comment %>
+ <%= form.text_area :comment %> +

+ +

+ <%= form.submit %> +

+ <% end %> \ No newline at end of file diff --git a/app/views/comments/create.html.erb b/app/views/comments/create.html.erb new file mode 100644 index 0000000..7990995 --- /dev/null +++ b/app/views/comments/create.html.erb @@ -0,0 +1,2 @@ +

Comments#create

+

Find me in app/views/comments/create.html.erb

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

Comments#index

+

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

diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb new file mode 100644 index 0000000..03d8c5a --- /dev/null +++ b/app/views/devise/confirmations/new.html.erb @@ -0,0 +1,17 @@ +

Resend confirmation instructions

+ +

hell

+<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+ +
+ <%= f.submit "Resend confirmation instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 0000000..dc55f64 --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/devise/mailer/email_changed.html.erb b/app/views/devise/mailer/email_changed.html.erb new file mode 100644 index 0000000..32f4ba8 --- /dev/null +++ b/app/views/devise/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @email %>!

+ +<% if @resource.try(:unconfirmed_email?) %> +

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

+<% else %> +

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

+<% end %> diff --git a/app/views/devise/mailer/password_change.html.erb b/app/views/devise/mailer/password_change.html.erb new file mode 100644 index 0000000..b41daf4 --- /dev/null +++ b/app/views/devise/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..f667dc1 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..41e148b --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 0000000..cf3d281 --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,25 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + <%= f.hidden_field :reset_password_token %> + +
+ <%= f.label :password, "New password" %>
+ <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum)
+ <% end %> + <%= f.password_field :password, autofocus: true, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %> +
+ +
+ <%= f.submit "Change my password" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb new file mode 100644 index 0000000..115452c --- /dev/null +++ b/app/views/devise/passwords/new.html.erb @@ -0,0 +1,28 @@ +
+
+
+ +

Forgot your password?

+

+ <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+
+ + + +
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control' , placeholder:'Email address' %> +
+ +
+ <%= f.submit "Send me reset password instructions" , class: 'btn btn-primary col-md-12' %> +
+ <% end %> +
+ + <%= render "devise/shared/links" %> +
+
+
\ No newline at end of file diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb new file mode 100644 index 0000000..38d95b8 --- /dev/null +++ b/app/views/devise/registrations/edit.html.erb @@ -0,0 +1,43 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "new-password" %> + <% if @minimum_password_length %> +
+ <%= @minimum_password_length %> characters minimum + <% end %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "current-password" %> +
+ +
+ <%= f.submit "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 0000000..d655b66 --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,29 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %> + <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
+ <%= f.password_field :password, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Sign up" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb new file mode 100644 index 0000000..efcbcd3 --- /dev/null +++ b/app/views/devise/sessions/new.html.erb @@ -0,0 +1,50 @@ + +
+
+
+ +

Please sign in

+

+ + <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+
+ + + +
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" , class: 'form-control' , placeholder:'Email address' %> +
+ +
+
+ + + +
+ <%= f.password_field :password, autocomplete: "current-password", class: 'form-control' , placeholder:'password'%> +
+ + <% if devise_mapping.rememberable? %> + + <% end %> +
+
+ <%= f.submit "Log in" , class: 'btn btn-primary col-md-12' %> +
+
+ <% end %> + + <%= render "devise/shared/links" %> + +
+
+
+ + + + + diff --git a/app/views/devise/shared/_error_messages.html.erb b/app/views/devise/shared/_error_messages.html.erb new file mode 100644 index 0000000..ba7ab88 --- /dev/null +++ b/app/views/devise/shared/_error_messages.html.erb @@ -0,0 +1,15 @@ +<% if resource.errors.any? %> +
+

+ <%= I18n.t("errors.messages.not_saved", + count: resource.errors.count, + resource: resource.class.model_name.human.downcase) + %> +

+ +
+<% end %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb new file mode 100644 index 0000000..084af70 --- /dev/null +++ b/app/views/devise/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
+ <% end %> +<% end %> diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb new file mode 100644 index 0000000..ffc34de --- /dev/null +++ b/app/views/devise/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Resend unlock instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..948a2c9 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,26 @@ + + +
+
+ +<% @books.each do |book| %> +
+ +
+<% if book.image.url != nil %> + + <%= image_tag book.image.url , class: "card-img-top", style: "width: 14rem; height: 200px;" %> + <%else%> + <%= image_tag 'https://png.pngtree.com/element_pic/17/07/27/bd157c7c747dc708790aa64b43c3da35.jpg' , class: "card-img-top", style: "width: 14rem; height: 200px;"%> + <%end%> + +
+
<%= link_to book.title, book %>
+ +

<%= link_to book.description, book %>

+
+ +
+
+<% end %> +
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index aac73db..a93c20e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,11 +5,45 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= stylesheet_link_tag 'application', media: 'all' %> + <%= stylesheet_link_tag 'application', media: 'all' %> <%= javascript_include_tag 'application' %> - <%= yield %> + + <%= yield %> - + \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 1311e3e..7e6af8d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -58,4 +58,6 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } end diff --git a/config/initializers/carrier_wave.rb b/config/initializers/carrier_wave.rb new file mode 100644 index 0000000..5780787 --- /dev/null +++ b/config/initializers/carrier_wave.rb @@ -0,0 +1 @@ +require 'carrierwave/orm/activerecord' \ No newline at end of file diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 0000000..88816e4 --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,299 @@ +# frozen_string_literal: true + +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. + # config.secret_key = '6290491d8e5ae3026ed769d494d2a668bf0b62feb63a07e70b8c0a372edd93c969f1192a6f67e5016973acf9d1f264dd7649a49d44f8ca97b4868746fb458987' + + # ==> Controller configuration + # Configure the parent class to the devise controllers. + # config.parent_controller = 'DeviseController' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + + # Configure the class responsible to send e-mails. + # config.mailer = 'Devise::Mailer' + + # Configure the parent class responsible to send e-mails. + # config.parent_mailer = 'ActionMailer::Base' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [:email] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [:email] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [:email] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If 401 status code should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # When false, Devise will not attempt to reload routes on eager load. + # This can reduce the time taken to boot the app but if your application + # requires the Devise mappings to be loaded during boot time the application + # won't boot properly. + # config.reload_routes = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 11. If + # using other algorithms, it sets how many times you want the password to be hashed. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # algorithm), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 11 + + # Set up a pepper to generate the hashed password. + # config.pepper = '84bf63af88fc20fa976e86d7356571f6be421a633150b68f94e23b68d5a5d3e789ffd6508979dfa533f9e2d925d05076080490a78f697b784f18c945aa5b50be' + + # Send a notification to the original email when the user's email is changed. + # config.send_email_changed_notification = false + + # Send a notification email when the user's password is changed. + # config.send_password_change_notification = false + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. + # You can also set it to nil, which will allow the user to access the website + # without confirming their account. + # Default is 0.days, meaning the user cannot access the website without + # confirming their account. + # config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [:email] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # Invalidates all the remember me tokens when the user signs out. + config.expire_all_remember_me_on_sign_out = true + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 6..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [:email] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = true + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [:email] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + + # ==> Configuration for :encryptable + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + # config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' + + # ==> Turbolinks configuration + # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: + # + # ActiveSupport.on_load(:devise_failure_app) do + # include Turbolinks::Controller + # end + + # ==> Configuration for :registerable + + # When set to false, does not sign a user in automatically after their password is + # changed. Defaults to true, so a user is signed in automatically after changing a password. + # config.sign_in_after_change_password = true +end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 0000000..55617bd --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,65 @@ +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n + +en: + devise: + confirmations: + confirmed: "Your email address has been successfully confirmed." + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." + failure: + already_authenticated: "You are already signed in." + inactive: "Your account is not activated yet." + invalid: "Invalid %{authentication_keys} or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account is locked." + not_found_in_database: "Invalid %{authentication_keys} or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your email address before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock instructions" + email_changed: + subject: "Email Changed" + password_change: + subject: "Password Changed" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password has been changed successfully. You are now signed in." + updated_not_active: "Your password has been changed successfully." + registrations: + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." + updated: "Your account has been updated successfully." + updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again" + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + already_signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/routes.rb b/config/routes.rb index 787824f..e02cbe2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,15 @@ Rails.application.routes.draw do + get 'comments/create' + get 'comments/index' + devise_for :users + resources :books + # root 'books#index' + root 'home#index' + get 'home/index', as:'home' + resources :books do + resources :comments + end + get 'books/:id' => 'books#show', as:'books_id' + get 'books/new' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20190307143038_create_books.rb b/db/migrate/20190307143038_create_books.rb new file mode 100644 index 0000000..8c88bc4 --- /dev/null +++ b/db/migrate/20190307143038_create_books.rb @@ -0,0 +1,13 @@ +class CreateBooks < ActiveRecord::Migration[5.2] + def change + create_table :books do |t| + t.string :title + t.string :author + t.string :description + t.string :image + t.string :category + + t.timestamps + end + end +end diff --git a/db/migrate/20190307144300_devise_create_users.rb b/db/migrate/20190307144300_devise_create_users.rb new file mode 100644 index 0000000..e4fe133 --- /dev/null +++ b/db/migrate/20190307144300_devise_create_users.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class DeviseCreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + # t.integer :sign_in_count, default: 0, null: false + # t.datetime :current_sign_in_at + # t.datetime :last_sign_in_at + # t.inet :current_sign_in_ip + # t.inet :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps null: false + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + # add_index :users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20190310114924_add_user_to_books.rb b/db/migrate/20190310114924_add_user_to_books.rb new file mode 100644 index 0000000..3dcf7e6 --- /dev/null +++ b/db/migrate/20190310114924_add_user_to_books.rb @@ -0,0 +1,5 @@ +class AddUserToBooks < ActiveRecord::Migration[5.2] + def change + add_reference :books, :user, foreign_key: true + end +end diff --git a/db/migrate/20190311122655_change_image_to_be_binary_in_books.rb b/db/migrate/20190311122655_change_image_to_be_binary_in_books.rb new file mode 100644 index 0000000..504b2c5 --- /dev/null +++ b/db/migrate/20190311122655_change_image_to_be_binary_in_books.rb @@ -0,0 +1,5 @@ +class ChangeImageToBeBinaryInBooks < ActiveRecord::Migration[5.2] + def change + change_column :books, :image, 'bytea USING CAST(image AS bytea)' + end +end diff --git a/db/migrate/20190312081959_create_comments.rb b/db/migrate/20190312081959_create_comments.rb new file mode 100644 index 0000000..90275d6 --- /dev/null +++ b/db/migrate/20190312081959_create_comments.rb @@ -0,0 +1,11 @@ +class CreateComments < ActiveRecord::Migration[5.2] + def change + create_table :comments do |t| + t.string :comment + t.string :commenter + t.references :book, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..261ae10 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,53 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 2019_03_12_081959) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "books", force: :cascade do |t| + t.string "title" + t.string "author" + t.string "description" + t.binary "image" + t.string "category" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id" + t.index ["user_id"], name: "index_books_on_user_id" + end + + create_table "comments", force: :cascade do |t| + t.string "comment" + t.string "commenter" + t.bigint "book_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["book_id"], name: "index_comments_on_book_id" + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + 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 + + add_foreign_key "books", "users" + add_foreign_key "comments", "books" +end diff --git a/public/uploads/book/image/14/iconfinder_list_296566__1_.png b/public/uploads/book/image/14/iconfinder_list_296566__1_.png new file mode 100644 index 0000000..9b2f521 Binary files /dev/null and b/public/uploads/book/image/14/iconfinder_list_296566__1_.png differ diff --git a/public/uploads/book/image/15/iconfinder_list_296566__1_.png b/public/uploads/book/image/15/iconfinder_list_296566__1_.png new file mode 100644 index 0000000..9b2f521 Binary files /dev/null and b/public/uploads/book/image/15/iconfinder_list_296566__1_.png differ diff --git a/public/uploads/book/image/18/iconfinder_list_296566__1_.png b/public/uploads/book/image/18/iconfinder_list_296566__1_.png new file mode 100644 index 0000000..9b2f521 Binary files /dev/null and b/public/uploads/book/image/18/iconfinder_list_296566__1_.png differ diff --git a/test/controllers/books_controller_test.rb b/test/controllers/books_controller_test.rb new file mode 100644 index 0000000..bb21800 --- /dev/null +++ b/test/controllers/books_controller_test.rb @@ -0,0 +1,48 @@ +require 'test_helper' + +class BooksControllerTest < ActionDispatch::IntegrationTest + setup do + @book = books(:one) + end + + test "should get index" do + get books_url + assert_response :success + end + + test "should get new" do + get new_book_url + assert_response :success + end + + test "should create book" do + assert_difference('Book.count') do + post books_url, params: { book: { author: @book.author, category: @book.category, description: @book.description, image: @book.image, title: @book.title } } + end + + assert_redirected_to book_url(Book.last) + end + + test "should show book" do + get book_url(@book) + assert_response :success + end + + test "should get edit" do + get edit_book_url(@book) + assert_response :success + end + + test "should update book" do + patch book_url(@book), params: { book: { author: @book.author, category: @book.category, description: @book.description, image: @book.image, title: @book.title } } + assert_redirected_to book_url(@book) + end + + test "should destroy book" do + assert_difference('Book.count', -1) do + delete book_url(@book) + end + + assert_redirected_to books_url + end +end diff --git a/test/controllers/comments_controller_test.rb b/test/controllers/comments_controller_test.rb new file mode 100644 index 0000000..cc1bc5d --- /dev/null +++ b/test/controllers/comments_controller_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class CommentsControllerTest < ActionDispatch::IntegrationTest + test "should get create" do + get comments_create_url + assert_response :success + end + + test "should get index" do + get comments_index_url + assert_response :success + end + +end diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 0000000..6013b68 --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class HomeControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get home_index_url + assert_response :success + end + +end diff --git a/test/fixtures/books.yml b/test/fixtures/books.yml new file mode 100644 index 0000000..09a4162 --- /dev/null +++ b/test/fixtures/books.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + author: MyString + description: MyString + image: MyString + category: MyString + +two: + title: MyString + author: MyString + description: MyString + image: MyString + category: MyString diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml new file mode 100644 index 0000000..3a9698e --- /dev/null +++ b/test/fixtures/comments.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + comment: MyString + commenter: MyString + book: one + +two: + comment: MyString + commenter: MyString + book: two diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..80aed36 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/book_test.rb b/test/models/book_test.rb new file mode 100644 index 0000000..e48079d --- /dev/null +++ b/test/models/book_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BookTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/comment_test.rb b/test/models/comment_test.rb new file mode 100644 index 0000000..b6d6131 --- /dev/null +++ b/test/models/comment_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CommentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/books_test.rb b/test/system/books_test.rb new file mode 100644 index 0000000..fae9142 --- /dev/null +++ b/test/system/books_test.rb @@ -0,0 +1,51 @@ +require "application_system_test_case" + +class BooksTest < ApplicationSystemTestCase + setup do + @book = books(:one) + end + + test "visiting the index" do + visit books_url + assert_selector "h1", text: "Books" + end + + test "creating a Book" do + visit books_url + click_on "New Book" + + fill_in "Author", with: @book.author + fill_in "Category", with: @book.category + fill_in "Description", with: @book.description + fill_in "Image", with: @book.image + fill_in "Title", with: @book.title + click_on "Create Book" + + assert_text "Book was successfully created" + click_on "Back" + end + + test "updating a Book" do + visit books_url + click_on "Edit", match: :first + + fill_in "Author", with: @book.author + fill_in "Category", with: @book.category + fill_in "Description", with: @book.description + fill_in "Image", with: @book.image + fill_in "Title", with: @book.title + click_on "Update Book" + + assert_text "Book was successfully updated" + click_on "Back" + end + + test "destroying a Book" do + visit books_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "Book was successfully destroyed" + end +end