diff --git a/Gemfile b/Gemfile index c32421d..0a705df 100644 --- a/Gemfile +++ b/Gemfile @@ -9,17 +9,19 @@ gem "bcrypt", "3.1.11" gem "bootstrap-sass", "3.3.7" gem "bootstrap-will_paginate" gem "capistrano-rails", group: :development +gem "carrierwave" gem "coffee-rails", "~> 4.2" gem "config" gem "ffaker" +gem "fog" gem "jbuilder", "~> 2.5" gem "jquery-rails" +gem "jquery-ui-rails" +gem "mini_magick" gem "puma", "~> 3.7" gem "rails", "~> 5.1.1" gem "rails-controller-testing" gem "sass-rails", "~> 5.0" -gem "sqlite3" -gem "turbolinks", "~> 5" gem "uglifier", ">= 1.3.0" gem "will_paginate" @@ -27,6 +29,7 @@ group :development, :test do gem "byebug", platforms: [:mri, :mingw, :x64_mingw] gem "capybara", "~> 2.13" gem "selenium-webdriver" + gem "sqlite3" end group :development do @@ -34,6 +37,14 @@ group :development do gem "spring" gem "spring-watcher-listen", "~> 2.0.0" gem "web-console", ">= 3.3.0" + gem "sqlite3" +end + +group :production do + gem 'pg' + gem 'rails_12factor' + gem 'taps' + gem 'rvm' end gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock index b0b975d..2e2d3ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,49 +1,50 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.1.1) - actionpack (= 5.1.1) + CFPropertyList (2.3.5) + actioncable (5.1.2) + actionpack (= 5.1.2) nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.1.1) - actionpack (= 5.1.1) - actionview (= 5.1.1) - activejob (= 5.1.1) + actionmailer (5.1.2) + actionpack (= 5.1.2) + actionview (= 5.1.2) + activejob (= 5.1.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.1) - actionview (= 5.1.1) - activesupport (= 5.1.1) + actionpack (5.1.2) + actionview (= 5.1.2) + activesupport (= 5.1.2) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.1) - activesupport (= 5.1.1) + actionview (5.1.2) + activesupport (= 5.1.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.1) - activesupport (= 5.1.1) + activejob (5.1.2) + activesupport (= 5.1.2) globalid (>= 0.3.6) - activemodel (5.1.1) - activesupport (= 5.1.1) - activerecord (5.1.1) - activemodel (= 5.1.1) - activesupport (= 5.1.1) + activemodel (5.1.2) + activesupport (= 5.1.2) + activerecord (5.1.2) + activemodel (= 5.1.2) + activesupport (= 5.1.2) arel (~> 8.0) - activesupport (5.1.1) + activesupport (5.1.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) - airbrussh (1.2.0) + airbrussh (1.3.0) sshkit (>= 1.6.1, != 1.7.0) arel (8.0.0) - autoprefixer-rails (7.1.1.2) + autoprefixer-rails (7.1.2.1) execjs bcrypt (3.1.11) bindex (0.5.0) @@ -54,7 +55,7 @@ GEM will_paginate builder (3.2.3) byebug (9.0.6) - capistrano (3.8.1) + capistrano (3.8.2) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -65,14 +66,18 @@ GEM capistrano-rails (1.3.0) capistrano (~> 3.1) capistrano-bundler (~> 1.1) - capybara (2.14.3) + capybara (2.14.4) addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - childprocess (0.7.0) + carrierwave (1.1.0) + activemodel (>= 4.0.0) + activesupport (>= 4.0.0) + mime-types (>= 1.16) + childprocess (0.7.1) ffi (~> 1.0, >= 1.0.11) coffee-rails (4.2.2) coffee-script (>= 2.2.0) @@ -86,13 +91,155 @@ GEM activesupport (>= 3.0) deep_merge (~> 1.1.1) deep_merge (1.1.1) - erubi (1.6.0) + erubi (1.6.1) + excon (0.57.1) execjs (2.7.0) ffaker (2.6.0) ffi (1.9.18) + fission (0.5.0) + CFPropertyList (~> 2.2) + fog (1.40.0) + fog-aliyun (>= 0.1.0) + fog-atmos + fog-aws (>= 0.6.0) + fog-brightbox (~> 0.4) + fog-cloudatcost (~> 0.1.0) + fog-core (~> 1.43) + fog-digitalocean (>= 0.3.0) + fog-dnsimple (~> 1.0) + fog-dynect (~> 0.0.2) + fog-ecloud (~> 0.1) + fog-google (<= 0.1.0) + fog-json + fog-local + fog-openstack + fog-powerdns (>= 0.1.1) + fog-profitbricks + fog-rackspace + fog-radosgw (>= 0.0.2) + fog-riakcs + fog-sakuracloud (>= 0.0.4) + fog-serverlove + fog-softlayer + fog-storm_on_demand + fog-terremark + fog-vmfusion + fog-voxel + fog-vsphere (>= 0.4.0) + fog-xenserver + fog-xml (~> 0.1.1) + ipaddress (~> 0.5) + json (>= 1.8, < 2.0) + fog-aliyun (0.1.0) + fog-core (~> 1.27) + fog-json (~> 1.0) + ipaddress (~> 0.8) + xml-simple (~> 1.1) + fog-atmos (0.1.0) + fog-core + fog-xml + fog-aws (1.4.0) + fog-core (~> 1.38) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-brightbox (0.11.0) + fog-core (~> 1.22) + fog-json + inflecto (~> 0.0.2) + fog-cloudatcost (0.1.2) + fog-core (~> 1.36) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-core (1.44.3) + builder + excon (~> 0.49) + formatador (~> 0.2) + fog-digitalocean (0.3.0) + fog-core (~> 1.42) + fog-json (>= 1.0) + fog-xml (>= 0.1) + ipaddress (>= 0.5) + fog-dnsimple (1.0.0) + fog-core (~> 1.38) + fog-json (~> 1.0) + fog-dynect (0.0.3) + fog-core + fog-json + fog-xml + fog-ecloud (0.3.0) + fog-core + fog-xml + fog-google (0.1.0) + fog-core + fog-json + fog-xml + fog-json (1.0.2) + fog-core (~> 1.0) + multi_json (~> 1.10) + fog-local (0.3.1) + fog-core (~> 1.27) + fog-openstack (0.1.21) + fog-core (>= 1.40) + fog-json (>= 1.0) + ipaddress (>= 0.8) + fog-powerdns (0.1.1) + fog-core (~> 1.27) + fog-json (~> 1.0) + fog-xml (~> 0.1) + fog-profitbricks (3.0.0) + fog-core (~> 1.42) + fog-json (~> 1.0) + fog-rackspace (0.1.5) + fog-core (>= 1.35) + fog-json (>= 1.0) + fog-xml (>= 0.1) + ipaddress (>= 0.8) + fog-radosgw (0.0.5) + fog-core (>= 1.21.0) + fog-json + fog-xml (>= 0.0.1) + fog-riakcs (0.1.0) + fog-core + fog-json + fog-xml + fog-sakuracloud (1.7.5) + fog-core + fog-json + fog-serverlove (0.1.2) + fog-core + fog-json + fog-softlayer (1.1.4) + fog-core + fog-json + fog-storm_on_demand (0.1.1) + fog-core + fog-json + fog-terremark (0.1.0) + fog-core + fog-xml + fog-vmfusion (0.1.0) + fission + fog-core + fog-voxel (0.1.0) + fog-core + fog-xml + fog-vsphere (1.11.1) + fog-core + rbvmomi (~> 1.9) + fog-xenserver (0.3.0) + fog-core + fog-xml + fog-xml (0.1.3) + fog-core + nokogiri (>= 1.5.11, < 2.0.0) + formatador (0.2.5) globalid (0.4.0) activesupport (>= 4.2.0) - i18n (0.8.4) + i18n (0.8.5) + inflecto (0.0.2) + ipaddress (0.8.3) jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) @@ -100,6 +247,9 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + jquery-ui-rails (6.0.1) + railties (>= 3.2.16) + json (1.8.6) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -109,9 +259,8 @@ GEM mail (2.6.6) mime-types (>= 1.16, < 4) method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) + mime-types (1.25.1) + mini_magick (4.8.0) mini_portile2 (2.2.0) minitest (5.10.2) multi_json (1.12.1) @@ -121,22 +270,23 @@ GEM nio4r (2.1.0) nokogiri (1.8.0) mini_portile2 (~> 2.2.0) + pg (0.21.0) public_suffix (2.0.5) puma (3.9.1) rack (2.0.3) rack-test (0.6.3) rack (>= 1.0) - rails (5.1.1) - actioncable (= 5.1.1) - actionmailer (= 5.1.1) - actionpack (= 5.1.1) - actionview (= 5.1.1) - activejob (= 5.1.1) - activemodel (= 5.1.1) - activerecord (= 5.1.1) - activesupport (= 5.1.1) + rails (5.1.2) + actioncable (= 5.1.2) + actionmailer (= 5.1.2) + actionpack (= 5.1.2) + actionview (= 5.1.2) + activejob (= 5.1.2) + activemodel (= 5.1.2) + activerecord (= 5.1.2) + activesupport (= 5.1.2) bundler (>= 1.3.0, < 2.0) - railties (= 5.1.1) + railties (= 5.1.2) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.2) actionpack (~> 5.x, >= 5.0.1) @@ -147,19 +297,32 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (5.1.1) - actionpack (= 5.1.1) - activesupport (= 5.1.1) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) + railties (5.1.2) + actionpack (= 5.1.2) + activesupport (= 5.1.2) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (12.0.0) - rb-fsevent (0.9.8) + rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) + rbvmomi (1.11.3) + builder (~> 3.0) + json (>= 1.8) + nokogiri (~> 1.5) + trollop (~> 2.1) + rest-client (1.6.9) + mime-types (~> 1.16) ruby_dep (1.5.0) rubyzip (1.2.1) - sass (3.4.24) + rvm (1.11.3.9) + sass (3.4.25) sass-rails (5.0.6) railties (>= 4.0.0, < 6) sass (~> 3.1) @@ -169,6 +332,9 @@ GEM selenium-webdriver (3.4.3) childprocess (~> 0.5) rubyzip (~> 1.0) + sequel (3.20.0) + sinatra (1.0) + rack (>= 1.0) spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -182,15 +348,18 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - sshkit (1.13.1) + sshkit (1.14.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) + taps (0.3.24) + rack (>= 1.0.1) + rest-client (>= 1.4.0, < 1.7.0) + sequel (~> 3.20.0) + sinatra (~> 1.0.0) thor (0.19.4) thread_safe (0.3.6) tilt (2.0.7) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.3) + trollop (2.1.2) tzinfo (1.2.3) thread_safe (~> 0.1) uglifier (3.2.0) @@ -204,6 +373,7 @@ GEM websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) will_paginate (3.1.6) + xml-simple (1.1.5) xpath (2.1.0) nokogiri (~> 1.3) @@ -217,21 +387,28 @@ DEPENDENCIES byebug capistrano-rails capybara (~> 2.13) + carrierwave coffee-rails (~> 4.2) config ffaker + fog jbuilder (~> 2.5) jquery-rails + jquery-ui-rails listen (>= 3.0.5, < 3.2) + mini_magick + pg puma (~> 3.7) rails (~> 5.1.1) rails-controller-testing + rails_12factor + rvm sass-rails (~> 5.0) selenium-webdriver spring spring-watcher-listen (~> 2.0.0) sqlite3 - turbolinks (~> 5) + taps tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) diff --git a/app/assets/images/ruby.ico b/app/assets/images/ruby.ico new file mode 100644 index 0000000..fb9f16f Binary files /dev/null and b/app/assets/images/ruby.ico differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index cd31f9c..c8cd2e8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,8 +10,8 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // +//= require rails-ujs //= require jquery //= require jquery_ujs //= require bootstrap -//= require turbolinks //= require_tree . diff --git a/app/assets/javascripts/comment.js b/app/assets/javascripts/comment.js new file mode 100644 index 0000000..bd1279d --- /dev/null +++ b/app/assets/javascripts/comment.js @@ -0,0 +1,59 @@ +$(document).ready(function() { + $('body').on('submit', '.newcomment', function(e){ + e.preventDefault(); + var params = $(this).serialize(); + var self = $(this); + $.ajax({ + url: self.attr('action'), + type: 'POST', + data: params, + dataType: 'json', + success: function(response){ + if(response.status == 'success'){ + self.prev().prev().append(response.html); + } + $('.text_area').val(''); + $('.newcomment2rd').hide(); + } + }); + return false; + }); + + $('body').on('submit','.newcomment2rd', function(e){ + e.preventDefault(); + var params = $(this).serialize(); + var selfcmt = $(this); + $.ajax({ + url: selfcmt.attr('action'), + type: 'POST', + data: params, + dataType: 'json', + success: function(response){ + if(response.status == 'success'){ + selfcmt.prev().append(response.html); + } + $('.text_area').val(''); + $('.newcomment2rd').hide(); + } + }); + return false; + }); + + $('body').on('click', '.delete', function(event) { + event.preventDefault(); + var self = $(this); + $.ajax({ + type: self.attr('data-method'), + url: self.attr('href'), + dataType: 'json', + data: {}, + success: function(response) { + if(response.status == 'success'){ + self.parent().parent().hide('slow'); + } + } + }); + return false; + }); + +}); diff --git a/app/assets/javascripts/comment2rd.coffee b/app/assets/javascripts/comment2rd.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/comment2rd.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/comments.coffee b/app/assets/javascripts/comments.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/comments.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js new file mode 100644 index 0000000..3589a1d --- /dev/null +++ b/app/assets/javascripts/custom.js @@ -0,0 +1,22 @@ +$(document).ready(function(){ + $('.newcomment2rd').hide(); + $('label.comments').on('click', function() { + $(this).next().toggle(); + return false; + }); + + $('body').on('click', 'label.reply', function(event) { + $(this).next().next().toggle(); + return false; + }); + + (function() { + var video = document.getElementById("my-video"); + if(video){ + video.addEventListener( "canplay", function() { + video.play(); + }); + } + })(); + +}); diff --git a/app/assets/stylesheets/comment2rd.scss b/app/assets/stylesheets/comment2rd.scss new file mode 100644 index 0000000..02a74dd --- /dev/null +++ b/app/assets/stylesheets/comment2rd.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Comment2rd 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/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/custom.scss b/app/assets/stylesheets/custom.scss index 4888a24..37d7693 100644 --- a/app/assets/stylesheets/custom.scss +++ b/app/assets/stylesheets/custom.scss @@ -7,7 +7,11 @@ $blue-dark: #fff; $gray-medium-light: #eaeaea; $light-gray: #777; $gray: #bbb; - +$dark-red: #e8e8e8; +$blue: #e6ffff; +$blues: #88C6ED; +$yellow: #ffff00; +$bl: #333333; @mixin box_sizing { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -18,17 +22,19 @@ $gray: #bbb; body { padding-top: 60px; + background-color: $blue; } section { overflow: auto; } -textarea { - resize: vertical; +textarea.form-control { + height: 34px; } .center { + margin-top: 30px; text-align: center; h1 { margin-bottom: 10px; @@ -63,7 +69,7 @@ p { /* header */ #logo { - color: $light-gray; + color: $yellow; float: left; font-size: 1.7em; font-weight: bold; @@ -80,8 +86,8 @@ p { /* footer */ footer { - border-top: 1px solid #eaeaea; - color: $light-gray; + border-top: 1px solid #blue; + color: #ffff00; margin-top: 45px; padding-top: 5px; a { @@ -153,6 +159,44 @@ aside { margin-top: 15px; } +.stats { + overflow: auto; + margin-top: 0; + padding: 0; + a { + border-left: 1px solid $gray-lighter; + color: gray; + float: left; + padding: 0 10px; + &:first-child { + border: 0; + padding-left: 0; + } + &:hover { + color: blue; + text-decoration: none; + } + } + strong { + display: block; + } +} + +.user_avatars { + margin-top: 10px; + overflow: auto; + .gravatar { + margin: 1px 1px; + } + a { + padding: 0; + } +} + +.users.follow { + padding: 0; +} + /* forms */ input, textarea, select, .uneditable-input { @@ -208,3 +252,115 @@ input { padding: 10px 0; } } + +/* posts */ + +.posts { + list-style: none; + padding: 0; + li { + padding: 10px 0; + border-top: 1px solid $dark-red; + } + .user { + margin-top: 5em; + padding-top: 0; + } + .content { + display: block; + margin-left: 60px; + img { + display: block; + padding: 5px 0; + margin-top: 15px; + } + } + .timestamp { + color: $gray-light; + display: block; + margin-left: 60px; + label { + color: $bl; + } + } + .gravatar { + float: left; + margin: 5px 10px; + } +} + +aside { + textarea { + height: 100px; + margin-bottom: 5px; + } +} + +span.picture { + margin-top: 10px; + input { + border: 0; + } +} + +label { + cursor: pointer; +} + +ol > li{ + margin-bottom: 15px; + margin-top: 15px; +} +ul > li { + margin-bottom: 10px; +} +/* button */ + +.comment { + float: right; + width: 50px; + text-align: center; + height: 5px; + margin-top: 0px; + border-radius: 12px; + background-color: #00b3b3; +} + +.text_area { + margin-bottom: 0px; +} + +.navbar-inverse { + + border-color: $blues; + .navbar-nav > li > a { + color: $yellow; + } +} + +.video { + position: fixed; + top: 50%; + left: 50%; + z-index: 1; + min-width: 100%; + min-height: 100%; + width: auto; + height: auto; + -webkit-transform: translate(-50%, -50%); + -ms-transform: translate(-50%, -50%); + transform: translate(-50%, -50%); +} + +.content { + position: relative; + top: 30%; + z-index: 2; + margin: 0 auto; + max-width: 720px; + text-align: center; +} + +.comment_list { + margin-top: 20px; +} diff --git a/app/assets/videos/background.mp4 b/app/assets/videos/background.mp4 new file mode 100644 index 0000000..3b785e6 Binary files /dev/null and b/app/assets/videos/background.mp4 differ diff --git a/app/assets/videos/demo.mp4 b/app/assets/videos/demo.mp4 new file mode 100644 index 0000000..7f35418 Binary files /dev/null and b/app/assets/videos/demo.mp4 differ diff --git a/app/controllers/account_activations_controller.rb b/app/controllers/account_activations_controller.rb index b018fba..32c2241 100644 --- a/app/controllers/account_activations_controller.rb +++ b/app/controllers/account_activations_controller.rb @@ -6,6 +6,7 @@ def edit user.activate log_in user flash[:success] = t ".account_activated" + redirect_to user else flash[:danger] = t ".invalid_activation_link" redirect_to root_url diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7193857..ad3a246 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,13 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception include SessionsHelper + + private + + def logged_in_user + return if logged_in? + store_location + flash[:danger] = t ".please_login" + redirect_to login_url + end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..0b4d2fc --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,45 @@ +class CommentsController < ApplicationController + + def create + @post = Post.find_by id: params[:comment][:post_id] + @comment = Comment.find_by id: params[:comment][:comment1st_id] + + if @comment.nil? + @comment1st = Comment.new comment_params + @comment1st.user_id = current_user.id + if @comment1st.save + render json: {status: :success, level: 0, + html: render_to_string(@comment1st)} + else + render json: {status: :fail} + end + else + @comment2rd = Comment.new comment_params + @comment2rd.user_id = current_user.id + if @comment2rd.save + render json: {status: :success, level: 1, + html: render_to_string(@comment2rd)} + end + end + end + + def show + + end + + def destroy + @comment = Comment.find_by id: params[:id] + + if @comment.destroy + render json: {status: :success} + else + render json: {status: :error} + end + end + + private + + def comment_params + params.require(:comment).permit :body, :comment1st_id, :post_id + end +end diff --git a/app/controllers/password_resets_controller.rb b/app/controllers/password_resets_controller.rb index 7cce5ad..62d671c 100644 --- a/app/controllers/password_resets_controller.rb +++ b/app/controllers/password_resets_controller.rb @@ -22,6 +22,7 @@ def edit end def update + byebug if params[:user][:password].empty? @user.errors.add :password, t(".cant_be_empty") render :edit @@ -56,7 +57,7 @@ def valid_user def check_expiration return unless @user.password_reset_expired? - flash[:danger] = t ".password_reset_has_expired." + flash[:danger] = t ".password_reset_has_expired" redirect_to new_password_reset_url end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000..8204fe8 --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,32 @@ +class PostsController < ApplicationController + before_action :logged_in_user, only: [:create, :destroy] + before_action :correct_user, only: :destroy + + def create + @post = current_user.posts.build post_params + if @post.save + flash[:success] = t ".post_created!" + redirect_to root_url + else + @feed_items = [] + render "static_pages/home" + end + end + + def destroy + @post.destroy + flash[:success] = t ".post_deleted" + redirect_to request.referrer || root_url + end + + private + + def post_params + params.require(:post).permit :content, :picture + end + + def correct_user + @post = current_user.posts.find_by id: params[:id] + redirect_to root_url if @post.nil? + end +end diff --git a/app/controllers/relationships_controller.rb b/app/controllers/relationships_controller.rb new file mode 100644 index 0000000..8a9690c --- /dev/null +++ b/app/controllers/relationships_controller.rb @@ -0,0 +1,22 @@ +class RelationshipsController < ApplicationController + before_action :logged_in_user + + def create + @user = User.find_by id: params[:followed_id] + current_user.follow @user + respond_to do |format| + format.html {redirect_to @user} + format.js + end + end + + def destroy + @user = Relationship.find_by(id: params[:id]).followed + current_user.unfollow @user + respond_to do |format| + format.html {redirect_to @user} + format.js + end + end + +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 37821b1..2d390a8 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -6,15 +6,21 @@ def create user = User.find_by email: params[:session][:email].downcase if user && user.authenticate(params[:session][:password]) - log_in user - "1" == params[:session][:remember_me] ? remember(user) : forget(user) - redirect_back_or user + if user.activated? + log_in user + "1" == params[:session][:remember_me] ? remember(user) : forget(user) + redirect_back_or user + else + message = t ".account_not_activated" + message += t ".check_email" + flash[:warning] = message + redirect_to login_path + end else - message = t ".account_not_activated" - message += t ".check_email" - flash[:warning] = message - redirect_to root_url + flash[:warning] = t ".found" + redirect_to login_path end + end def destroy diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index bff6ab8..fceef8c 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -1,5 +1,10 @@ class StaticPagesController < ApplicationController def home + if logged_in? + @post = current_user.posts.build + @feed_items = current_user.feed.paginate page: params[:page], + per_page: Settings.controller.user_controller.size_page + end end def help diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a3f5871..6de7112 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -19,7 +19,7 @@ def create if @user.save @user.send_activation_email - flash[:info] = t ".check_email" + flash.now[:info] = t ".check_email" redirect_to root_url else render :new @@ -27,6 +27,7 @@ def create end def show + @posts = @user.posts.paginate page: params[:page] end def edit @@ -50,6 +51,18 @@ def destroy redirect_to users_url end + def following + @title = "Following" + @users = @user.following.paginate page: params[:page] + render "show_follow" + end + + def followers + @title = "Followers" + @users = @user.followers.paginate page: params[:page] + render "show_follow" + end + private def user_params 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/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..57ca168 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,10 @@ +class Comment < ApplicationRecord + has_many :comment2rd, class_name: Comment.name, foreign_key: "comment1st_id",dependent: :destroy + belongs_to :post + belongs_to :user + belongs_to :comment1st, class_name: Comment.name, optional: true + + validates :body, presence: true + + scope :check_2rd, ->{where comment1st_id: nil} +end diff --git a/app/models/post.rb b/app/models/post.rb new file mode 100644 index 0000000..9ed6802 --- /dev/null +++ b/app/models/post.rb @@ -0,0 +1,22 @@ +class Post < ApplicationRecord + belongs_to :user + + has_many:comments, dependent: :destroy + + default_scope -> {order created_at: :desc} + + mount_uploader :picture, PictureUploader + + validates :user_id, presence: true + validates :content, presence: true, + length: {maximum: Settings.model.posts.size_post} + validate :picture_size + + private + + def picture_size + if picture.size > Settings.model.posts.size_bit.megabytes + errors.add :picture, t(".should_be_5MB") + end + end +end diff --git a/app/models/relationship.rb b/app/models/relationship.rb new file mode 100644 index 0000000..edeea3f --- /dev/null +++ b/app/models/relationship.rb @@ -0,0 +1,7 @@ +class Relationship < ApplicationRecord + belongs_to :follower, class_name: "User" + belongs_to :followed, class_name: "User" + + validates :follower_id, presence: true + validates :followed_id, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb index c21b72d..8a7ffe2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,13 @@ class User < ApplicationRecord + has_many :posts, dependent: :destroy + has_many :comments + has_many :active_relationships, class_name: "Relationship", + foreign_key: "follower_id", dependent: :destroy + has_many :passive_relationships, class_name: "Relationship", + foreign_key: "followed_id", dependent: :destroy + has_many :following, through: :active_relationships, source: :followed + has_many :followers, through: :passive_relationships, source: :follower + attr_accessor :remember_token, :activation_token, :reset_token before_save :downcase_email @@ -40,7 +49,8 @@ def send_activation_email end def create_reset_digest - update_columns reset_digest: User.digest(User.new_token), + self.reset_token = User.new_token + update_columns reset_digest: User.digest(reset_token), reset_sent_at: Time.zone.now end @@ -67,6 +77,24 @@ def forget update_attributes remember_digest: nil end + def feed + following_ids = "SELECT followed_id FROM relationships WHERE follower_id = :user_id" + Post.where("user_id IN (#{following_ids}) OR user_id = :user_id", + user_id: id) + end + + def follow other_user + active_relationships.create(followed_id: other_user.id) + end + + def unfollow other_user + following.delete other_user + end + + def following? other_user + following.include? other_user + end + private def downcase_email diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb new file mode 100644 index 0000000..faf52af --- /dev/null +++ b/app/uploaders/picture_uploader.rb @@ -0,0 +1,19 @@ +class PictureUploader < CarrierWave::Uploader::Base + include CarrierWave::MiniMagick + + process resize_to_limit: [400, 400] + + if Rails.env.production? + storage :fog + else + storage :file + end + + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + def extension_white_list + %w(jpg jpeg gif png) + end +end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb new file mode 100644 index 0000000..c2a6add --- /dev/null +++ b/app/views/comments/_comment.html.erb @@ -0,0 +1,31 @@ +<% user = comment.user %> +
  • + <%= link_to gravatar_for(user, size: Settings.comments.size_avatar), user %> + <%= user.name %> : <%= comment.body %> + + + + + <%= time_ago_in_words comment.created_at %> + <%= t ".ago" %> + <% if current_user.is_user? comment.user %> + <%= link_to t(".delete"), comment, method: :delete, class: "delete" %> + <% end %> + + + + + <%= form_for(Comment.new, html: {class: "newcomment2rd"}) do |f| %> + +
    + <%= f.hidden_field :post_id, value: comment.post.id %> + <%= f.hidden_field :comment1st_id, value: comment.id %> + <%= f.text_area :body, class: "form-control" %> + <%= f.submit t(".post"), class: "comment" %> +
    + <% end %> +
  • + + diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb new file mode 100644 index 0000000..acced68 --- /dev/null +++ b/app/views/comments/_form.html.erb @@ -0,0 +1,7 @@ +<%= form_for(Comment.new, html: {class: "newcomment"}) do |f| %> +
    + <%= f.hidden_field :post_id, value: post.id %> + <%= f.text_area :body, class: "form-control" %> + <%= f.submit t(".post"), class: "comment" %> +
    +<% end %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index c547f59..6e75682 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -1,6 +1,6 @@