Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ yarn-debug.log*
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
config/application.yml
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "bootstrap-sass", "3.4.1"
gem "bootstrap-will_paginate", "1.0.0"
gem "config"
gem "faker", "2.1.2"
gem "figaro"
gem "jbuilder", "~> 2.7"
gem "puma", "~> 4.1"
gem "rails", "~> 6.0.3", ">= 6.0.3.3"
Expand All @@ -18,6 +19,9 @@ gem "sqlite3", "~> 1.4"
gem "turbolinks", "~> 5"
gem "webpacker", "~> 4.0"
gem "will_paginate", "3.1.8"
gem "image_processing", "1.9.3"
gem "mini_magick", "4.9.5"
gem "active_storage_validations", "0.8.2"

group :development, :test do
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
Expand Down
18 changes: 16 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_storage_validations (0.8.2)
rails (>= 5.2.0)
activejob (6.0.3.3)
activesupport (= 6.0.3.3)
globalid (>= 0.3.6)
Expand All @@ -59,7 +61,7 @@ GEM
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.1)
autoprefixer-rails (10.0.0.2)
autoprefixer-rails (10.0.1.0)
execjs
bcrypt (3.1.13)
bindex (0.8.1)
Expand Down Expand Up @@ -98,7 +100,7 @@ GEM
concurrent-ruby (~> 1.0)
dry-equalizer (0.3.0)
dry-inflector (0.2.0)
dry-initializer (3.0.3)
dry-initializer (3.0.4)
dry-logic (1.0.8)
concurrent-ruby (~> 1.0)
dry-core (~> 0.2)
Expand Down Expand Up @@ -130,10 +132,15 @@ GEM
faker (2.1.2)
i18n (>= 0.8)
ffi (1.13.1)
figaro (1.2.0)
thor (>= 0.14.0, < 2)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
image_processing (1.9.3)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.13, < 3)
jaro_winkler (1.5.4)
jbuilder (2.10.1)
activesupport (>= 5.0.0)
Expand All @@ -149,6 +156,7 @@ GEM
mimemagic (~> 0.3.2)
method_source (1.0.0)
mimemagic (0.3.5)
mini_magick (4.9.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.2)
Expand Down Expand Up @@ -215,6 +223,8 @@ GEM
rack (>= 1.1)
rubocop (>= 0.72.0)
ruby-progressbar (1.10.1)
ruby-vips (2.0.17)
ffi (~> 1.9)
rubyzip (2.3.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
Expand Down Expand Up @@ -283,6 +293,7 @@ PLATFORMS
web-unknown

DEPENDENCIES
active_storage_validations (= 0.8.2)
bcrypt (= 3.1.13)
bootsnap (>= 1.4.2)
bootstrap-sass (= 3.4.1)
Expand All @@ -291,8 +302,11 @@ DEPENDENCIES
capybara (>= 2.15)
config
faker (= 2.1.2)
figaro
image_processing (= 1.9.3)
jbuilder (~> 2.7)
listen (~> 3.2)
mini_magick (= 4.9.5)
puma (~> 4.1)
rails (~> 6.0.3, >= 6.0.3.3)
rails-i18n
Expand Down
98 changes: 98 additions & 0 deletions app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,101 @@ input {
border-bottom: 1px solid $gray-lighter;
}
}

.microposts {
list-style: none;
padding: 0;
li {
padding: 10px 0;
border-top: 1px solid #e8e8e8;
}
.user {
margin-top: 5em;
padding-top: 0;
}
.content {
display: block;
margin-left: 60px;
img {
display: block;
padding: 5px 0;
}
}

.timestamp {
color: $gray-light;
display: block;
margin-left: 60px;
}
.gravatar {
float: left;
margin-right: 10px;
width: 8%;
}
}
aside {
textarea {
height: 100px;
margin-bottom: 5px;
}
}
span.image {
margin-top: 10px;
width: 20px;
input {
border: 0;
}
}

input[type="file"] {
display: block;
position: absolute;
}

.gravatar {
float: left;
margin-right: 10px;
}

.gravatar_edit {
margin-top: 15px;
}

.stats {
overflow: auto;
margin-top: 0;
padding: 0;
a {
float: left;
padding: 0 10px;
border-left: 1px solid $gray-lighter;
color: gray;
&:first-child {
padding-left: 0;
border: 0;
}
&:hover {
text-decoration: none;
color: blue;

}
strong {
display: block;
}
}

.user_avatars {
overflow: auto;
margin-top: 10px;
.gravatar {
margin: 1px 1px;
}
a {
padding: 0;
}
}

.users.follow {
padding: 0;
}
}
14 changes: 14 additions & 0 deletions app/controllers/account_activations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class AccountActivationsController < ApplicationController
def edit
user = User.find_by email: params[:email]
if user && !user.activated? && user.authenticated?(:activation, params[:id])
user.activate
log_in user
flash[:success] = "Account activated!"
redirect_to user
else
flash[:danger] = "Invalid activation link"
redirect_to root_url
end
end
end
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ def set_locale
def default_url_options
{locale: I18n.locale}
end

def logged_in_user
unless logged_in?
store_location
flash[:danger] = t("login_in.messages")
redirect_to login_url
end
end
end
33 changes: 33 additions & 0 deletions app/controllers/microposts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class MicropostsController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
before_action :correct_user, only: :destroy

def create
@micropost = current_user.microposts.build micropost_params
@micropost.image.attach(params[:micropost][:image])
if @micropost.save
flash[:success] = t("micropost.messages1")
redirect_to root_url
else
@feed_items = current_user.feed.paginate(page: params[:page])
render "static_pages/home"
end
end

def destroy
@micropost.destroy
flash[:success] = t("micropost.messages2")
redirect_to request.referrer || root_url
end

private

def micropost_params
params.require(:micropost).permit :content, :picture
end

def correct_user
@micropost = current_user.microposts.find_by id: params[:id]
redirect_to root_url unless @micropost
end
end
49 changes: 49 additions & 0 deletions app/controllers/password_resets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class PasswordResetsController < ApplicationController
before_action :get_user, only: [:edit, :update]
before_action :valid_user, only: [:edit, :update]

def new; end

def create
@user = User.find_by email: params[:password_reset][:email].downcase
if @user
@user.create_reset_digest
@user.send_password_reset_email
flash[:info] = "Email sent with password reset instructions"
redirect_to root_url
else
flash.now[:danger] = "Email address not found"
render :new
end
end

def update
if params[:user][:password].empty?
@user.errors.add(:password, "can't be empty")
render 'edit'
elsif @user.update(user_params)
log_in @user
@user.update_attribute(:reset_digest, nil)
flash[:success] = "Password has been reset."
redirect_to @user
else
render :edit
end
end

def edit; end

private

def get_user
@user = User.find_by email: params[:email]
end
def valid_user
return if (@user && @user.activated? && @user.authenticated?(:reset, params[:id]))
redirect_to root_url
end

def user_params
params.require(:user).permit :password, :password_confirmation
end
end
21 changes: 21 additions & 0 deletions app/controllers/relationships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
14 changes: 10 additions & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ def new; end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user&.authenticate(params[:session][:password])
log_in user
params[:session][:remember_me] == "1" ? remember(user) : forget(user)
remember user
redirect_back_or user
if user.activated?
log_in user
params[:session][:remember_me] == "1" ? remember(user) : forget(user)
remember user
redirect_back_or user
else
message = "Account not activated. Check your email for the activation link."
flash[:warning] = message
redirect_to root_url
end
else
flash.now[:danger] = t("session.flash")
render :new
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
class StaticPagesController < ApplicationController
def home; end
def home
if logged_in?
@micropost = current_user.microposts.build
@feed_items = current_user.feed.paginate(page: params[:page])
end
end

def help; end
end
Loading