diff --git a/.rvmrc b/.rvmrc
new file mode 100644
index 0000000..1399176
--- /dev/null
+++ b/.rvmrc
@@ -0,0 +1 @@
+rvm use ruby 2.6.0@rails_app
diff --git a/Gemfile b/Gemfile
index ee00549..2e37d66 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,6 +3,11 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.0'
+gem 'omniauth-google-oauth2'
+
+gem 'kaminari'
+gem 'bootstrap-kaminari-views'
+
gem 'jquery-rails'
gem 'font-awesome-rails'
diff --git a/Gemfile.lock b/Gemfile.lock
index 71b02de..86b3fe5 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -57,6 +57,9 @@ GEM
autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2)
sassc-rails (>= 2.0.0)
+ bootstrap-kaminari-views (0.0.5)
+ kaminari (>= 0.13)
+ rails (>= 3.1)
builder (3.2.3)
byebug (11.0.0)
capybara (3.14.0)
@@ -89,11 +92,14 @@ GEM
warden (~> 1.2.3)
erubi (1.8.0)
execjs (2.7.0)
+ faraday (0.15.4)
+ multipart-post (>= 1.2, < 3)
ffi (1.10.0)
font-awesome-rails (4.7.0.4)
railties (>= 3.2, < 6.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
+ hashie (3.6.0)
i18n (1.5.3)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
@@ -104,6 +110,19 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
+ jwt (2.1.0)
+ kaminari (1.1.1)
+ activesupport (>= 4.1.0)
+ kaminari-actionview (= 1.1.1)
+ kaminari-activerecord (= 1.1.1)
+ kaminari-core (= 1.1.1)
+ kaminari-actionview (1.1.1)
+ actionview
+ kaminari-core (= 1.1.1)
+ kaminari-activerecord (1.1.1)
+ activerecord
+ kaminari-core (= 1.1.1)
+ kaminari-core (1.1.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
@@ -122,9 +141,27 @@ GEM
minitest (5.11.3)
msgpack (1.2.6)
multi_json (1.13.1)
+ multi_xml (0.6.0)
+ multipart-post (2.0.0)
nio4r (2.3.1)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
+ oauth2 (1.4.1)
+ faraday (>= 0.8, < 0.16.0)
+ jwt (>= 1.0, < 3.0)
+ multi_json (~> 1.3)
+ multi_xml (~> 0.5)
+ rack (>= 1.2, < 3)
+ omniauth (1.9.0)
+ hashie (>= 3.4.6, < 3.7.0)
+ rack (>= 1.6.2, < 3)
+ omniauth-google-oauth2 (0.6.1)
+ jwt (>= 2.0)
+ omniauth (>= 1.1.1)
+ omniauth-oauth2 (>= 1.5)
+ omniauth-oauth2 (1.6.0)
+ oauth2 (~> 1.1)
+ omniauth (~> 1.9)
orm_adapter (0.5.0)
pg (1.1.4)
popper_js (1.14.5)
@@ -231,6 +268,7 @@ PLATFORMS
DEPENDENCIES
bootsnap (>= 1.1.0)
bootstrap (~> 4.3.1)
+ bootstrap-kaminari-views
byebug
capybara (>= 2.15)
chromedriver-helper
@@ -239,7 +277,9 @@ DEPENDENCIES
font-awesome-rails
jbuilder (~> 2.5)
jquery-rails
+ kaminari
listen (>= 3.0.5, < 3.2)
+ omniauth-google-oauth2
pg (>= 0.18, < 2.0)
puma (~> 3.11)
rails (~> 5.2.2)
diff --git a/app/assets/images/logo.jpg b/app/assets/images/logo.jpg
new file mode 100644
index 0000000..b35ab84
Binary files /dev/null and b/app/assets/images/logo.jpg differ
diff --git a/app/assets/images/profile_pics/profile_pic.png b/app/assets/images/profile_pics/profile_pic.png
new file mode 100644
index 0000000..e7f3638
Binary files /dev/null and b/app/assets/images/profile_pics/profile_pic.png differ
diff --git a/app/assets/images/profile_pics/user1.jpg b/app/assets/images/profile_pics/user1.jpg
new file mode 100644
index 0000000..53223c5
Binary files /dev/null and b/app/assets/images/profile_pics/user1.jpg differ
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 7b6be67..6e02acd 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -12,8 +12,11 @@
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
+//= require rails-ujs
//= require jquery3
//= require jquery_ujs
+//= require popper
+//= require bootstrap
//= require activestorage
//= require turbolinks
//= require_tree .
diff --git a/app/assets/javascripts/home.coffee b/app/assets/javascripts/friendships.coffee
similarity index 100%
rename from app/assets/javascripts/home.coffee
rename to app/assets/javascripts/friendships.coffee
diff --git a/app/assets/javascripts/my_profiles.coffee b/app/assets/javascripts/my_profiles.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/my_profiles.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/users.coffee b/app/assets/javascripts/users.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/users.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/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index 3817a5f..5ccca71 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -12,6 +12,4 @@
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
- *= require_tree .
- *= require_self
*/
diff --git a/app/assets/stylesheets/friendships.scss b/app/assets/stylesheets/friendships.scss
new file mode 100644
index 0000000..8c5a6c8
--- /dev/null
+++ b/app/assets/stylesheets/friendships.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the friendships 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/my_profiles.scss b/app/assets/stylesheets/my_profiles.scss
new file mode 100644
index 0000000..9f0a6f3
--- /dev/null
+++ b/app/assets/stylesheets/my_profiles.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the my_profiles 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/users.scss
similarity index 64%
rename from app/assets/stylesheets/home.scss
rename to app/assets/stylesheets/users.scss
index f0ddc68..1efc835 100644
--- a/app/assets/stylesheets/home.scss
+++ b/app/assets/stylesheets/users.scss
@@ -1,3 +1,3 @@
-// Place all the styles related to the home controller here.
+// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 5ccac54..864a103 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -4,9 +4,8 @@ class ApplicationController < ActionController::Base
protected
- def configure_permitted_parameters
- devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:first_name, :last_name, :email, :password, :sex)}
- devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(:first_name, :last_name, :email, :password, :sex, :current_password)}
- end
-
+ def configure_permitted_parameters
+ devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:first_name, :last_name, :email, :password, :sex) }
+ devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(:first_name, :last_name, :email, :password, :sex, :current_password) }
+ end
end
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 4e683c4..2ea0103 100644
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -3,11 +3,9 @@ class CommentsController < ApplicationController
def create
@comment = @post.comments.build(comment_params.merge(user_id: current_user.id))
- @comment.save
respond_to do |format|
- format.js
+ @comment.save ? format.js : format.js { render :create_alert }
end
-
end
def index
@@ -20,19 +18,21 @@ def index
def destroy
@comments = @post.comments
@comment = @comments.find(params[:id])
- @comment.destroy
respond_to do |format|
- format.js
+ @comment.destroy ? format.js : format.js { render :destroy_alert }
end
end
private
- def comment_params
- params.require(:comment).permit(:content)
- end
- def find_post
- @post = Post.find_by_id(params[:post_id])
- end
+ def comment_params
+ params.require(:comment).permit(:content)
+ end
+ def find_post
+ unless @post = Post.find_by_id(params[:post_id])
+ flash[:notice] = 'Post not found'
+ render layout: false
+ end
+ end
end
diff --git a/app/controllers/friendships_controller.rb b/app/controllers/friendships_controller.rb
new file mode 100644
index 0000000..56f1ed5
--- /dev/null
+++ b/app/controllers/friendships_controller.rb
@@ -0,0 +1,34 @@
+class FriendshipsController < ApplicationController
+ before_action :authenticate_user!, :find_friendship, only: [:destroy, :update]
+
+ def create
+ @friendship = current_user.friendships.create(friend_id: params[:friend_id], status: 0)
+ if @friendship.save
+ redirect_back(fallback_location: root_path)
+ end
+ end
+
+ def destroy
+ if (@friendship.user_id == current_user.id) || (@friendship.friend_id == current_user.id)
+ if @friendship.destroy
+ redirect_back(fallback_location: root_path)
+ end
+ end
+ end
+
+ def update
+ if @friendship.friend_id == current_user.id
+ if @friendship.update_attribute(:status, 1)
+ redirect_back(fallback_location: root_path)
+ end
+ end
+ end
+
+ private
+
+ def find_friendship
+ unless @friendship = Friendship.find_by(id: params[:id])
+ render layout: false
+ end
+ end
+end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
deleted file mode 100644
index 89b351c..0000000
--- a/app/controllers/home_controller.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-class HomeController < ApplicationController
-
- def index
- if user_signed_in?
- @posts = current_user.posts
- else
- redirect_to welcome_sign_in_path
- end
- end
-
- def search
- if params[:friend]
- @users = User.where('first_name LIKE ?', "%#{params[:friend]}%")
- else
- @users = User.all
- end
- end
-
-end
diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb
index 82257af..124231f 100644
--- a/app/controllers/likes_controller.rb
+++ b/app/controllers/likes_controller.rb
@@ -1,31 +1,31 @@
class LikesController < ApplicationController
before_action :authenticate_user!, :set_up_likable
-
+
def create
- @like = @likable.likes.new
- @like.user_id = current_user.id
- @like.save
+ @like = @likable.likes.build(user_id: current_user.id)
respond_to do |format|
- format.js
+ @like.save ? format.js : format.js { render :create_alert }
end
end
-
+
def destroy
@like = @likable.likes.find(params[:id])
- @like.destroy
respond_to do |format|
- format.js
+ @like.destroy ? format.js : format.js { render :destroy_alert }
end
end
-
+
private
-
+
def set_up_likable
- if params[:post_id]
- @likable = Post.find(params[:post_id])
- else
- @likable = Comment.find(params[:comment_id])
+ unless (@likable =
+ if params[:post_id]
+ Post.find(params[:post_id])
+ else
+ Comment.find(params[:comment_id])
+ end)
+ flash[:notice] = 'Not found'
+ render layout: false
end
end
-
end
diff --git a/app/controllers/my_profiles_controller.rb b/app/controllers/my_profiles_controller.rb
new file mode 100644
index 0000000..b13dbe0
--- /dev/null
+++ b/app/controllers/my_profiles_controller.rb
@@ -0,0 +1,38 @@
+class MyProfilesController < ApplicationController
+ def show
+ end
+
+ def edit
+ end
+
+ def requests
+ @requests = current_user.inverse_friends.where('friendships.status = ?', 0)
+ end
+
+ def timeline
+ if user_signed_in?
+ @posts = Post.order('created_at DESC').where("user_id != #{current_user.id}").page(params[:page]).per(5)
+ else
+ redirect_to welcome_sign_in_path
+ end
+ end
+
+ def about
+ end
+
+ def friends
+ friends = current_user.friends.where('friendships.status = ?', 1)
+ @friends = friends + current_user.inverse_friends.where('friendships.status = ?', 1)
+ end
+
+ def photos
+ end
+
+ def avatar_info
+ end
+
+ def change_avatar
+ current_user.avatar.attach(params[:user][:avatar])
+ redirect_back(fallback_location: root_path)
+ end
+end
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index e286728..e86b73d 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -9,22 +9,26 @@ def create
# respond_with Post.create(post_params.merge(user_id: current_user.id))
@post = current_user.posts.build(post_params)
@post.image.attach(params[:post][:image])
- @post.save
respond_to do |format|
- format.js
- format.html {redirect_to root_path}
- end
+ if @post.save
+ format.js
+ format.html { redirect_to root_path }
+ else
+ format.js { render 'create_alert' }
+ end
+ end
end
def destroy
@post = current_user.posts.find(params[:id])
- @post.destroy
- redirect_to root_path
+ if @post.destroy
+ redirect_back(fallback_location: root_path)
+ end
end
private
- def post_params
- params.require(:post).permit(:content)
- end
+ def post_params
+ params.require(:post).permit(:content)
+ end
end
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 036bce1..40d30f7 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -1,8 +1,29 @@
class RegistrationsController < Devise::RegistrationsController
- protected
+ def update
+ account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
+ @user = User.find(current_user.id)
- def after_sign_up_path_for(resource)
- 'welcome/sign_in' # Or :prefix_to_your_route
+ if needs_password?
+ successfully_updated = @user.update_with_password(account_update_params)
+ else
+ account_update_params.delete('password')
+ account_update_params.delete('password_confirmation')
+ account_update_params.delete('current_password')
+ successfully_updated = @user.update_attributes(account_update_params)
+ end
+
+ if successfully_updated
+ set_flash_message :notice, :updated
+ sign_in @user, :bypass => true
+ redirect_to edit_user_registration_path
+ else
+ render 'edit'
+ end
end
-end
+ private
+
+ def needs_password?
+ @user.email != params[:user][:email] || params[:user][:password].present?
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb
new file mode 100644
index 0000000..fa535c0
--- /dev/null
+++ b/app/controllers/users/confirmations_controller.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class Users::ConfirmationsController < Devise::ConfirmationsController
+ # GET /resource/confirmation/new
+ # def new
+ # super
+ # end
+
+ # POST /resource/confirmation
+ # def create
+ # super
+ # end
+
+ # GET /resource/confirmation?confirmation_token=abcdef
+ # def show
+ # super
+ # end
+
+ # protected
+
+ # The path used after resending confirmation instructions.
+ # def after_resending_confirmation_instructions_path_for(resource_name)
+ # super(resource_name)
+ # end
+
+ # The path used after confirmation.
+ # def after_confirmation_path_for(resource_name, resource)
+ # super(resource_name, resource)
+ # end
+end
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb
new file mode 100644
index 0000000..565c6ed
--- /dev/null
+++ b/app/controllers/users/omniauth_callbacks_controller.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
+ # You should configure your model like this:
+ # devise :omniauthable, omniauth_providers: [:twitter]
+
+ # You should also create an action method in this controller like this:
+ # def twitter
+ # end
+
+ # More info at:
+ # https://github.com/plataformatec/devise#omniauth
+
+ # GET|POST /resource/auth/twitter
+ # def passthru
+ # super
+ # end
+
+ # GET|POST /users/auth/twitter/callback
+ # def failure
+ # super
+ # end
+
+ # protected
+
+ # The path used when OmniAuth fails
+ # def after_omniauth_failure_path_for(scope)
+ # super(scope)
+ # end
+end
diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb
new file mode 100644
index 0000000..259dbb0
--- /dev/null
+++ b/app/controllers/users/passwords_controller.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class Users::PasswordsController < Devise::PasswordsController
+ # GET /resource/password/new
+ # def new
+ # super
+ # end
+
+ # POST /resource/password
+ # def create
+ # super
+ # end
+
+ # GET /resource/password/edit?reset_password_token=abcdef
+ # def edit
+ # super
+ # end
+
+ # PUT /resource/password
+ # def update
+ # super
+ # end
+
+ # protected
+
+ # def after_resetting_password_path_for(resource)
+ # super(resource)
+ # end
+
+ # The path used after sending reset password instructions
+ # def after_sending_reset_password_instructions_path_for(resource_name)
+ # super(resource_name)
+ # end
+end
diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb
new file mode 100644
index 0000000..b9e664f
--- /dev/null
+++ b/app/controllers/users/registrations_controller.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+class Users::RegistrationsController < Devise::RegistrationsController
+ # before_action :configure_sign_up_params, only: [:create]
+ # before_action :configure_account_update_params, only: [:update]
+
+ # GET /resource/sign_up
+ # def new
+ # super
+ # end
+
+ # POST /resource
+ # def create
+ # super
+ # end
+
+ # GET /resource/edit
+ # def edit
+ # super
+ # end
+
+ # PUT /resource
+ # def update
+ # super
+ # end
+
+ # DELETE /resource
+ # def destroy
+ # super
+ # end
+
+ # GET /resource/cancel
+ # Forces the session data which is usually expired after sign
+ # in to be expired now. This is useful if the user wants to
+ # cancel oauth signing in/up in the middle of the process,
+ # removing all OAuth session data.
+ # def cancel
+ # super
+ # end
+
+ # protected
+
+ # If you have extra params to permit, append them to the sanitizer.
+ # def configure_sign_up_params
+ # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
+ # end
+
+ # If you have extra params to permit, append them to the sanitizer.
+ # def configure_account_update_params
+ # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
+ # end
+
+ # The path used after sign up.
+ # def after_sign_up_path_for(resource)
+ # super(resource)
+ # end
+
+ # The path used after sign up for inactive accounts.
+ # def after_inactive_sign_up_path_for(resource)
+ # super(resource)
+ # end
+end
diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb
new file mode 100644
index 0000000..a0f9b48
--- /dev/null
+++ b/app/controllers/users/sessions_controller.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class Users::SessionsController < Devise::SessionsController
+ # before_action :configure_sign_in_params, only: [:create]
+
+ # GET /resource/sign_in
+ # def new
+ # super
+ # end
+
+ # POST /resource/sign_in
+ # def create
+ # super
+ # end
+
+ # DELETE /resource/sign_out
+ # def destroy
+ # super
+ # end
+
+ # protected
+
+ # If you have extra params to permit, append them to the sanitizer.
+ # def configure_sign_in_params
+ # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
+ # end
+end
diff --git a/app/controllers/users/unlocks_controller.rb b/app/controllers/users/unlocks_controller.rb
new file mode 100644
index 0000000..2c410dc
--- /dev/null
+++ b/app/controllers/users/unlocks_controller.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class Users::UnlocksController < Devise::UnlocksController
+ # GET /resource/unlock/new
+ # def new
+ # super
+ # end
+
+ # POST /resource/unlock
+ # def create
+ # super
+ # end
+
+ # GET /resource/unlock?unlock_token=abcdef
+ # def show
+ # super
+ # end
+
+ # protected
+
+ # The path used after sending unlock password instructions
+ # def after_sending_unlock_instructions_path_for(resource)
+ # super(resource)
+ # end
+
+ # The path used after unlocking the resource
+ # def after_unlock_path_for(resource)
+ # super(resource)
+ # end
+end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
new file mode 100644
index 0000000..133ca7e
--- /dev/null
+++ b/app/controllers/users_controller.rb
@@ -0,0 +1,35 @@
+class UsersController < ApplicationController
+ before_action :find_user, only: [:about, :friends, :photos, :show]
+
+ def search
+ @users =
+ if params[:friend]
+ User.search_by_first_name(params[:friend])
+ else
+ User.all
+ end
+ end
+
+ def about
+ end
+
+ def friends
+ friends = @user.friends.where('friendships.status = ?', 1)
+ @friends = friends + @user.inverse_friends.where('friendships.status = ?', 1)
+ end
+
+ def photos
+ end
+
+ def show
+ end
+
+ private
+
+ def find_user
+ unless @user = User.find_by_id(params[:user_id])
+ flash[:notice] = 'User not found'
+ render layout: false
+ end
+ end
+end
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
index f933d89..c3cbd65 100644
--- a/app/controllers/welcome_controller.rb
+++ b/app/controllers/welcome_controller.rb
@@ -1,5 +1,4 @@
class WelcomeController < ApplicationController
-
def sign_in
end
diff --git a/app/helpers/friendships_helper.rb b/app/helpers/friendships_helper.rb
new file mode 100644
index 0000000..64f89ba
--- /dev/null
+++ b/app/helpers/friendships_helper.rb
@@ -0,0 +1,2 @@
+module FriendshipsHelper
+end
diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb
deleted file mode 100644
index 23de56a..0000000
--- a/app/helpers/home_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-module HomeHelper
-end
diff --git a/app/helpers/my_profiles_helper.rb b/app/helpers/my_profiles_helper.rb
new file mode 100644
index 0000000..069d271
--- /dev/null
+++ b/app/helpers/my_profiles_helper.rb
@@ -0,0 +1,2 @@
+module MyProfilesHelper
+end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
new file mode 100644
index 0000000..2310a24
--- /dev/null
+++ b/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index 286b223..ec5c7af 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
- default from: 'from@example.com'
+ default from: 'shubham14595@gmail.com'
layout 'mailer'
end
diff --git a/app/mailers/my_mailer.rb b/app/mailers/my_mailer.rb
new file mode 100644
index 0000000..1c74bd3
--- /dev/null
+++ b/app/mailers/my_mailer.rb
@@ -0,0 +1,11 @@
+class MyMailer < Devise::Mailer
+
+ helper :application
+ default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views
+
+ def default_url_options
+ {
+ host: "localhost:3000"
+ }
+ end
+end
diff --git a/app/models/friendship.rb b/app/models/friendship.rb
new file mode 100644
index 0000000..beb516b
--- /dev/null
+++ b/app/models/friendship.rb
@@ -0,0 +1,4 @@
+class Friendship < ApplicationRecord
+ belongs_to :user
+ belongs_to :friend, class_name: :User
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 427d432..64fe349 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -2,13 +2,34 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :validatable
- has_many :posts
- has_many :comments
- has_many :likes
+ :recoverable, :rememberable, :validatable, :confirmable
+ has_many :posts, dependent: :destroy
+ has_many :comments, dependent: :destroy
+ has_many :likes, dependent: :destroy
- def liked?(likable)
- self.likes.find_by(likable_id: likable.id, likable_type: likable.class.name)
+ has_many :friendships
+ has_many :friends, through: :friendships
+
+ has_many :inverse_friendships, class_name: 'Friendship', foreign_key: 'friend_id'
+ has_many :inverse_friends, through: :inverse_friendships, source: :user
+
+ has_one_attached :avatar
+
+ scope :search_by_first_name, ->(first_name) { where('first_name LIKE ?', "%#{first_name}%") }
+
+ def find_like(likable)
+ likes.find_by(likable_id: likable.id, likable_type: likable.class.name)
end
+ def find_friendship(friend)
+ friendships.find_by(friend_id: friend.id)
+ end
+
+ def get_avatar
+ if self.avatar.attached?
+ image_tag self.avatar
+ else
+ image_tag 'profile_pics/profile_pic.png'
+ end
+ end
end
diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb
index d95403d..bc9e23c 100644
--- a/app/views/comments/_comment.html.erb
+++ b/app/views/comments/_comment.html.erb
@@ -1,9 +1,15 @@
- <%= comment.user.email %>
-<%= comment.content %>
-
-<%= link_to "Delete", post_comment_path(post_id: comment.post_id, id: comment.id), method: :delete, remote: true %>
-<%= time_ago_in_words(comment.created_at) %>
+
+
+ <%= "#{comment.user.first_name} #{comment.user.last_name}" %>
+
+
+ <%= comment.content %>
+
+ <% if (comment.user == current_user) || (comment.post == current_user) %>
+ <%= link_to "Delete", post_comment_path(post_id: comment.post_id, id: comment.id), method: :delete, remote: true %>
+ <% end %>
+ <%= time_ago_in_words(comment.created_at) %>
\ No newline at end of file
diff --git a/app/views/comments/_comment_like.html.erb b/app/views/comments/_comment_like.html.erb
index b603ff7..31f04ab 100644
--- a/app/views/comments/_comment_like.html.erb
+++ b/app/views/comments/_comment_like.html.erb
@@ -1,5 +1,5 @@
-<% if current_user.liked?(comment) %>
- <%= link_to 'Like', comment_like_path(comment_id: comment.id, id: current_user.liked?(comment).id), method: :delete, remote: true %>
+<% if current_user.find_like(comment) %>
+ <%= link_to 'Like', comment_like_path(comment_id: comment.id, id: current_user.find_like(comment).id), method: :delete, remote: true %>
<% else %>
<%= link_to 'Like', comment_likes_path(comment_id: comment.id), method: :post, remote: true %>
<% end %>
\ No newline at end of file
diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb
index 090ef2b..8389afb 100644
--- a/app/views/comments/create.js.erb
+++ b/app/views/comments/create.js.erb
@@ -1,2 +1,4 @@
-$("#comments<%= @post.id %>").append(" <%= j render(:partial => "comment", :locals => {:comment => @comment}) %> ");
+var com_box = $("#comments<%= @post.id %>");
+com_box[0].style.display = "block";
+com_box.append(" <%= j render(:partial => "comment", :locals => {:comment => @comment}) %> ");
diff --git a/app/views/comments/create_alert.js.erb b/app/views/comments/create_alert.js.erb
new file mode 100644
index 0000000..b416446
--- /dev/null
+++ b/app/views/comments/create_alert.js.erb
@@ -0,0 +1 @@
+alert( 'comment cannot be created' )
\ No newline at end of file
diff --git a/app/views/comments/destroy_alert.js.erb b/app/views/comments/destroy_alert.js.erb
new file mode 100644
index 0000000..6526948
--- /dev/null
+++ b/app/views/comments/destroy_alert.js.erb
@@ -0,0 +1 @@
+alert( 'comment cannot be deleted' )
\ No newline at end of file
diff --git a/app/views/comments/index.js.erb b/app/views/comments/index.js.erb
index 2549bdf..d77f452 100644
--- a/app/views/comments/index.js.erb
+++ b/app/views/comments/index.js.erb
@@ -1 +1,5 @@
-$("#comments<%= @post.id %>").html(" <%= j render partial: 'comment', collection: @comments, as: :comment %> ");
\ No newline at end of file
+var com_box = $("#comments<%= @post.id %>");
+if (com_box[0].style.display === "none") {
+ com_box.html(" <%= j render partial: 'comment', collection: @comments, as: :comment %> ");
+}
+com_box.toggle();
\ No newline at end of file
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb
index 5ede964..6423217 100644
--- a/app/views/devise/sessions/new.html.erb
+++ b/app/views/devise/sessions/new.html.erb
@@ -1,4 +1,5 @@
Log in
+<%= resource.errors.messages %>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
diff --git a/app/views/friendships/create.html.erb b/app/views/friendships/create.html.erb
new file mode 100644
index 0000000..ec7cf84
--- /dev/null
+++ b/app/views/friendships/create.html.erb
@@ -0,0 +1,3 @@
+
+ cannot send request
+
\ No newline at end of file
diff --git a/app/views/friendships/destroy.html.erb b/app/views/friendships/destroy.html.erb
new file mode 100644
index 0000000..80c644e
--- /dev/null
+++ b/app/views/friendships/destroy.html.erb
@@ -0,0 +1,3 @@
+
+ cannot delete friendship
+
\ No newline at end of file
diff --git a/app/views/friendships/update.html.erb b/app/views/friendships/update.html.erb
new file mode 100644
index 0000000..86471ae
--- /dev/null
+++ b/app/views/friendships/update.html.erb
@@ -0,0 +1,3 @@
+
+ Unable to accept request
+
\ No newline at end of file
diff --git a/app/views/home/_post.html.erb b/app/views/home/_post.html.erb
deleted file mode 100644
index 026d2b3..0000000
--- a/app/views/home/_post.html.erb
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
- <%= link_to 'Delete', post_path(post), method: :delete %>
- <%= post.timestamp %>
- <%= post.content %>
- <% if post.image.attached? %>
- <%= image_tag post.image, style: "width:20rem;" %>
- <% end %>
-
-
-
>
- <%= render(partial: 'home/like', locals: {post: post}) %>
-
-
<%= link_to ' Comments', post_comments_path(post), remote: true, class: "fa fa-comment btn" %>
-
-
-
>
-
-
-
-
-
\ No newline at end of file
diff --git a/app/views/home/_user.html.erb b/app/views/home/_user.html.erb
deleted file mode 100644
index e9f38f3..0000000
--- a/app/views/home/_user.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
- <%= user.first_name %> <%= user.last_name %>
-
\ No newline at end of file
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
deleted file mode 100644
index 99bb73f..0000000
--- a/app/views/home/index.html.erb
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
<%= current_user.email %>
-
-
-<%= link_to 'Log out', destroy_user_session_path, method: :delete %>
-
-
-
-<%= form_with url: home_search_path, method: :get do |form| %>
- <%= form.text_field :friend %>
- <%= form.submit :search %>
-<% end %>
-
-
-
-
-
-
-
- <%= form_with scope: :post,url: posts_path do |form| %>
-
- <%= form.label :content %>
- <%= form.text_field :content, placeholder: "share your wits.."%>
- <%= form.file_field :image %>
-
-
-
- <%= form.submit :create%>
-
-
- <% end %>
-
-
-
-
- <% @posts.each do |post| %>
-
- <%= render(partial: 'post', :locals => {:post => post}) %>
-
- <% end %>
-
-
-
-
\ No newline at end of file
diff --git a/app/views/home/search.js.erb b/app/views/home/search.js.erb
deleted file mode 100644
index 143969a..0000000
--- a/app/views/home/search.js.erb
+++ /dev/null
@@ -1 +0,0 @@
-$("#main").html("<%= j render(partial: 'user', collection: @users, as: :user) %>");
\ No newline at end of file
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index d2496f6..62c75ac 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -1,18 +1,47 @@
-
Fb
+
Science Buzz
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
+
-
<%= notice %>
-
<%= alert %>
-
+ <% flash.each do |key, value| %>
+ <%= content_tag :div, value, class: "flash #{key}" %>
+ <% end %>
+ <% if user_signed_in? %>
+
+
+
Welcome <%= link_to "#{current_user.first_name}", my_profile_path, style: "color: black" %>
+ <%= form_with url: users_search_path, method: :get, local:true do |form| %>
+ <%= form.text_field :friend, placeholder: "Search.." %>
+ <% end %>
+
+ Home
+
+ <%= link_to "", my_profiles_requests_path, class: "fa fa-odnoklassniki", remote: true %>
+
+
+
+
+ <%= link_to 'Logout', destroy_user_session_path, method: :delete, class: "nav-link", style: "display:inline" %>
+
+
+
+
+ <% end %>
<%= yield %>
diff --git a/app/views/likes/create.js.erb b/app/views/likes/create.js.erb
index da0ed64..eb816d1 100644
--- a/app/views/likes/create.js.erb
+++ b/app/views/likes/create.js.erb
@@ -1,5 +1,5 @@
<% if @likable.class.name == "Post" %>
- $("#likes<%= @likable.id %>").html(" <%= j render(partial: 'home/like', :locals => {:post => @likable}) %> ");
+ $("#likes<%= @likable.id %>").html(" <%= j render(partial: 'posts/like', :locals => {:post => @likable}) %> ");
<% else %>
$("#like<%= @likable.id %>").html(" <%= j render(partial: 'comments/comment_like', :locals => {:comment => @likable}) %> ");
<% end %>
\ No newline at end of file
diff --git a/app/views/likes/create_alert.js.erb b/app/views/likes/create_alert.js.erb
new file mode 100644
index 0000000..3ab29fa
--- /dev/null
+++ b/app/views/likes/create_alert.js.erb
@@ -0,0 +1 @@
+alert( 'cannot like' )
\ No newline at end of file
diff --git a/app/views/likes/destroy.js.erb b/app/views/likes/destroy.js.erb
index deec733..d3263ba 100644
--- a/app/views/likes/destroy.js.erb
+++ b/app/views/likes/destroy.js.erb
@@ -1,5 +1,5 @@
<% if @likable.class.name == "Post" %>
- $("#likes<%= @likable.id %>").html(" <%= j render(partial: 'home/like', locals: {post: @likable}) %> ");
+ $("#likes<%= @likable.id %>").html(" <%= j render(partial: 'posts/like', locals: {post: @likable}) %> ");
<% else %>
$("#like<%= @likable.id %>").html(" <%= j render(partial: 'comments/comment_like', locals: {comment: @likable}) %> ");
<% end %>
\ No newline at end of file
diff --git a/app/views/likes/destroy_alert.js.erb b/app/views/likes/destroy_alert.js.erb
new file mode 100644
index 0000000..80ecfd7
--- /dev/null
+++ b/app/views/likes/destroy_alert.js.erb
@@ -0,0 +1 @@
+alert( 'cannot dislike' )
\ No newline at end of file
diff --git a/app/views/my_profiles/_email_section.html.erb b/app/views/my_profiles/_email_section.html.erb
new file mode 100644
index 0000000..823ce51
--- /dev/null
+++ b/app/views/my_profiles/_email_section.html.erb
@@ -0,0 +1,44 @@
+<%= form_for(current_user, as: :user, url: registration_path(:user), html: { method: :patch }) do |f| %>
+
+
+ <%= f.label 'Name:', class: "col-sm-2" %>
+ <%= f.text_field :first_name %><%= f.text_field :last_name %>
+
+
+
+
+ <%= f.label 'Email: ', class: "col-sm-2" %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %>
+
+
+ <% if Devise.mappings[:user].confirmable? && current_user.pending_reconfirmation? %>
+
Currently waiting confirmation for: <%= current_user.unconfirmed_email %>
+ <% end %>
+
+
+
+
<%= f.label :new_password %> (You can leave it blank)
+ <%= f.password_field :password, autocomplete: "new-password" %>
+ <% if @minimum_password_length %>
+
+
<%= @minimum_password_length %> characters minimum
+ <% end %>
+
+
+
+
+ <%= f.label :password_confirmation, class: "col-sm-6" %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %>
+
+
+
+
+ <%= f.label :current_password, class: "col-sm-6" %>
+ <%= f.password_field :current_password, autocomplete: "current-password" %>
+
+
+
+
+ <%= f.submit "Change", class: "btn-info" %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/my_profiles/_picture.html.erb b/app/views/my_profiles/_picture.html.erb
new file mode 100644
index 0000000..db5ecd5
--- /dev/null
+++ b/app/views/my_profiles/_picture.html.erb
@@ -0,0 +1,14 @@
+<% if current_user.avatar.attached? %>
+<%= image_tag current_user.avatar, style: "width: 100px; height: 100px" %>
+<% else %>
+<%= image_tag 'profile_pics/profile_pic.png', style: "width: 100px; height: 100px" %>
+<% end %>
+<%= form_with scope: :user,url: my_profiles_change_avatar_path do |form| %>
+
+ <%= form.file_field :avatar %>
+
+
+
+ <%= form.submit :Change , class: "btn btn-success" %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/my_profiles/_request.html.erb b/app/views/my_profiles/_request.html.erb
new file mode 100644
index 0000000..7f22c08
--- /dev/null
+++ b/app/views/my_profiles/_request.html.erb
@@ -0,0 +1,7 @@
+
+
+ <%= "#{request.first_name} #{request.last_name}" %>
+ <%= link_to 'Confirm', friendship_path(id: request.find_friendship(current_user).id), method: :patch %>
+
+
+
\ No newline at end of file
diff --git a/app/views/my_profiles/_top.html.erb b/app/views/my_profiles/_top.html.erb
new file mode 100644
index 0000000..6c8bf57
--- /dev/null
+++ b/app/views/my_profiles/_top.html.erb
@@ -0,0 +1,26 @@
+
+
+ <% if current_user.avatar.attached? %>
+ <%= image_tag current_user.avatar, style: "width: 100px; height: 100px; border-radius: 50%" %>
+ <% else %>
+ <%= image_tag 'profile_pics/profile_pic.png', style: "width: 100px; height: 100px" %>
+ <% end %>
+
+ <%= "#{current_user.first_name} #{current_user.last_name}" %>
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/my_profiles/about.html.erb b/app/views/my_profiles/about.html.erb
new file mode 100644
index 0000000..40023fa
--- /dev/null
+++ b/app/views/my_profiles/about.html.erb
@@ -0,0 +1,18 @@
+<%= render 'top' %>
+
+
+
Email and Password:
+ <%= link_to 'Profile Picture:', "/my_profiles/avatar_info", class: "nav-item nav-link", remote: true %>
+
+
+
+
+ <%= render 'email_section' %>
+
+
+
+
+
+
+ <%= button_to "Delete my account", registration_path(:user), data: { confirm: "Are you sure?" }, method: :delete %>
+
\ No newline at end of file
diff --git a/app/views/my_profiles/avatar_info.js.erb b/app/views/my_profiles/avatar_info.js.erb
new file mode 100644
index 0000000..e9c15ea
--- /dev/null
+++ b/app/views/my_profiles/avatar_info.js.erb
@@ -0,0 +1 @@
+$("#my_info").html("<%= j render 'picture' %>");
\ No newline at end of file
diff --git a/app/views/my_profiles/friends.html.erb b/app/views/my_profiles/friends.html.erb
new file mode 100644
index 0000000..75fd55a
--- /dev/null
+++ b/app/views/my_profiles/friends.html.erb
@@ -0,0 +1,25 @@
+<%= render 'top' %>
+
+
+
+
+
+ <% @friends.each do |f| %>
+
+
+
+ <%= link_to "#{f.first_name} #{f.last_name}", users_show_path(user_id: f.id) %>
+
+
+ <% if current_user.find_friendship(f) %>
+ <%= link_to ' Friend', friendship_path(id: current_user.find_friendship(f).id), method: :delete, class: "fa fa-check" %>
+ <% else %>
+ <%= link_to ' Friend', friendship_path(id: f.find_friendship(current_user).id), method: :delete, class: "fa fa-check" %>
+ <% end %>
+
+
+
+ <% end %>
+
+
+
\ No newline at end of file
diff --git a/app/views/my_profiles/photos.html.erb b/app/views/my_profiles/photos.html.erb
new file mode 100644
index 0000000..9065888
--- /dev/null
+++ b/app/views/my_profiles/photos.html.erb
@@ -0,0 +1 @@
+<%= render 'top' %>
diff --git a/app/views/my_profiles/requests.js.erb b/app/views/my_profiles/requests.js.erb
new file mode 100644
index 0000000..fc90800
--- /dev/null
+++ b/app/views/my_profiles/requests.js.erb
@@ -0,0 +1,6 @@
+<% if @requests.empty? %>
+ $('#requests').html("No Friend Requests");
+<% else %>
+ $("#requests").html("<%= j render(partial: 'request', collection: @requests) %>");
+<% end %>
+$('#requests').dropdown('toggle');
\ No newline at end of file
diff --git a/app/views/my_profiles/show.html.erb b/app/views/my_profiles/show.html.erb
new file mode 100644
index 0000000..265be1b
--- /dev/null
+++ b/app/views/my_profiles/show.html.erb
@@ -0,0 +1,31 @@
+<%= render 'top' %>
+
+
+
+
+
+ <%= form_with scope: :post,url: posts_path do |form| %>
+
+ <%= form.text_field :content, placeholder: "share your wits.."%>
+ <%= form.file_field :image %>
+
+
+
+ <%= form.submit :Post , class: "btn btn-success" %>
+
+ <% end %>
+
+
+
+ <% if current_user.posts.empty? %>
+ No Posts to show
+ <% else %>
+ <% current_user.posts.each do |post| %>
+
+ <%= render(partial: 'posts/post', :locals => {:post => post}) %>
+
+ <% end %>
+ <% end %>
+
+
+
diff --git a/app/views/my_profiles/timeline.html.erb b/app/views/my_profiles/timeline.html.erb
new file mode 100644
index 0000000..6da396a
--- /dev/null
+++ b/app/views/my_profiles/timeline.html.erb
@@ -0,0 +1,32 @@
+
+
+
+
+ <%= form_with scope: :post,url: posts_path do |form| %>
+
+ <%= form.text_field :content, placeholder: "share your wits.."%>
+ <%= form.file_field :image %>
+
+
+
+ <%= form.submit :Post , class: "btn btn-success" %>
+
+ <% end %>
+
+
+
+ <% if @posts.empty? %>
+ No Posts to show
+ <% else %>
+ <% @posts.each do |post| %>
+
+ <%= render(partial: 'posts/post', :locals => {:post => post}) %>
+
+ <% end %>
+ <%= paginate @posts, theme: 'twitter-bootstrap-3' %>
+ <%= page_entries_info @posts %>
+ <% end %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/home/_like.html.erb b/app/views/posts/_like.html.erb
similarity index 55%
rename from app/views/home/_like.html.erb
rename to app/views/posts/_like.html.erb
index ea544fd..e5d1412 100644
--- a/app/views/home/_like.html.erb
+++ b/app/views/posts/_like.html.erb
@@ -1,5 +1,5 @@
-<% if current_user.liked?(post) %>
- <%= link_to ' Like', post_like_path(post_id: post.id, id: current_user.liked?(post).id), method: :delete, remote: true, class: "fa fa-thumbs-up btn", style: "color:lightskyblue;" %>
+<% if current_user.find_like(post) %>
+ <%= link_to ' Like', post_like_path(post_id: post.id, id: current_user.find_like(post).id), method: :delete, remote: true, class: "fa fa-thumbs-up btn", style: "color:lightskyblue;" %>
<% else %>
<%= link_to ' Like', post_likes_path(post_id: post.id), method: :post, remote: true, class: "fa fa-thumbs-up btn"%>
<% end %>
\ No newline at end of file
diff --git a/app/views/posts/_post.html.erb b/app/views/posts/_post.html.erb
new file mode 100644
index 0000000..e75a3cd
--- /dev/null
+++ b/app/views/posts/_post.html.erb
@@ -0,0 +1,43 @@
+
+
+
+
+ <%= post.content %>
+ <% if post.image.attached? %>
+ <%= image_tag post.image, style: "width:100%;" %>
+ <% end %>
+
+
+
>
+ <%= render(partial: 'posts/like', locals: {post: post}) %>
+
+
<%= link_to ' Comments', post_comments_path(post), remote: true, class: "fa fa-comment btn" %>
+
+
+
style="display:none" >
+
+
+
+
+
diff --git a/app/views/posts/create_alert.js.erb b/app/views/posts/create_alert.js.erb
new file mode 100644
index 0000000..0b18dcb
--- /dev/null
+++ b/app/views/posts/create_alert.js.erb
@@ -0,0 +1 @@
+alert ( 'cannot create post' );
\ No newline at end of file
diff --git a/app/views/posts/destroy.html.erb b/app/views/posts/destroy.html.erb
new file mode 100644
index 0000000..e70f4a7
--- /dev/null
+++ b/app/views/posts/destroy.html.erb
@@ -0,0 +1,3 @@
+
+ cannot delete post
+
\ No newline at end of file
diff --git a/app/views/users/_friendship.html.erb b/app/views/users/_friendship.html.erb
new file mode 100644
index 0000000..5c91497
--- /dev/null
+++ b/app/views/users/_friendship.html.erb
@@ -0,0 +1,11 @@
+<% if (current_user.find_friendship(user) && (current_user.find_friendship(user).status == 1)) %>
+ <%= link_to ' Friend', friendship_path(id: current_user.find_friendship(user).id), method: :delete, class: "fa fa-check" %>
+<% elsif (user.find_friendship(current_user) && (user.find_friendship(current_user).status == 1)) %>
+ <%= link_to ' Friend', friendship_path(id: user.find_friendship(current_user).id), method: :delete, class: "fa fa-check" %>
+<% elsif current_user.find_friendship(user) %>
+ <%= link_to 'Requested', friendship_path(id: current_user.find_friendship(user).id), method: :delete %>
+<% elsif user.find_friendship(current_user) %>
+ <%= link_to 'Confirm Request', friendship_path(id: user.find_friendship(current_user).id), method: :patch %>
+<% elsif user != current_user %>
+ <%= link_to 'Add Friend', friendships_path(friend_id: user), method: :post %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/users/_top.html.erb b/app/views/users/_top.html.erb
new file mode 100644
index 0000000..3002d4f
--- /dev/null
+++ b/app/views/users/_top.html.erb
@@ -0,0 +1,29 @@
+
+
+
+ <%= "#{user.first_name} #{user.last_name}" %>
+
+
+ <% if current_user==user %>
+ Update Profile
+ <% else %>
+ <%= render(partial: 'friendship', locals:{user: user}) %>
+ Message
+ <% end %>
+
+
+
+
+
+
+
+
diff --git a/app/views/users/about.html.erb b/app/views/users/about.html.erb
new file mode 100644
index 0000000..9edcf74
--- /dev/null
+++ b/app/views/users/about.html.erb
@@ -0,0 +1 @@
+<%= render(partial: 'top', locals: {user: @user}) %>
diff --git a/app/views/users/friends.html.erb b/app/views/users/friends.html.erb
new file mode 100644
index 0000000..331a793
--- /dev/null
+++ b/app/views/users/friends.html.erb
@@ -0,0 +1,20 @@
+<%= render(partial: 'top', locals: {user: @user}) %>
+
+
+
+
+
+ <% @friends.each do |f| %>
+
+
+ <%= link_to "#{f.first_name} #{f.last_name}", users_show_path(user_id: f.id) %>
+
+
+ <%= render(partial: 'friendship', locals:{user: f}) %>
+
+
+
+ <% end %>
+
+
+
\ No newline at end of file
diff --git a/app/views/users/photos.html.erb b/app/views/users/photos.html.erb
new file mode 100644
index 0000000..9edcf74
--- /dev/null
+++ b/app/views/users/photos.html.erb
@@ -0,0 +1 @@
+<%= render(partial: 'top', locals: {user: @user}) %>
diff --git a/app/views/users/search.html.erb b/app/views/users/search.html.erb
new file mode 100644
index 0000000..03c737d
--- /dev/null
+++ b/app/views/users/search.html.erb
@@ -0,0 +1,18 @@
+
+
+
+
+ <% @users.each do |user| %>
+
+
+ <%= link_to "#{user.first_name} #{user.last_name}", users_show_path(user_id: user.id) %>
+
+
+ <%= render(partial: 'friendship', locals:{user: user}) %>
+
+
+
+ <% end %>
+
+
+
\ No newline at end of file
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
new file mode 100644
index 0000000..37f33d8
--- /dev/null
+++ b/app/views/users/show.html.erb
@@ -0,0 +1,18 @@
+<%= render(partial: 'top', locals: {user: @user}) %>
+
+
+
+
+ <% if @user.posts.empty? %>
+ No Posts to show
+ <% else %>
+ <% @user.posts.each do |post| %>
+
+ <%= render(partial: 'posts/post', :locals => {:post => post}) %>
+
+ <% end %>
+ <% end %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/welcome/sign_in.html.erb b/app/views/welcome/sign_in.html.erb
index a1d9665..7bfb2d1 100644
--- a/app/views/welcome/sign_in.html.erb
+++ b/app/views/welcome/sign_in.html.erb
@@ -21,4 +21,6 @@
<%= f.submit "Log in" %>
+
+ <%= link_to 'Sign Up', welcome_sign_up_path %>
<% end %>
\ No newline at end of file
diff --git a/app/views/welcome/sign_up.html.erb b/app/views/welcome/sign_up.html.erb
index f5009f9..7f6a9a7 100644
--- a/app/views/welcome/sign_up.html.erb
+++ b/app/views/welcome/sign_up.html.erb
@@ -2,10 +2,9 @@
Sign up
-<%= form_for(User.new, as: :user, url: registration_path(:user)) do |f| %>
+<%= form_for(User.new, as: :user, url: registration_path(:user), style: "color:#000000") do |f| %>
<%= render "devise/shared/error_messages", resource: User.new %>
-
<%= f.label :first_name %>
<%= f.text_field :first_name %>
diff --git a/config/environments/development.rb b/config/environments/development.rb
index a768308..c550108 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -4,6 +4,22 @@
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
+
+ config.action_mailer.perform_deliveries = true
+ config.action_mailer.raise_delivery_errors = true
+ config.action_mailer.delivery_method = :smtp
+ config.action_mailer.smtp_settings = {
+ address: 'smtp.gmail.com',
+ port: 587,
+ domain: 'gmail.com',
+ user_name: 'shubham14595@gmail.com',
+ password: '00001122',
+ authentication: 'plain',
+ enable_starttls_auto: true
+ }
+
+ config.action_mailer.default_url_options = { host: 'localhost:3000' }
+
config.cache_classes = false
# Do not eager load code on boot.
@@ -31,7 +47,7 @@
config.active_storage.service = :local
# Don't care if the mailer can't send.
- config.action_mailer.raise_delivery_errors = false
+ # config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index b6cc6eb..b36fbd7 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -21,7 +21,7 @@
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
# Configure the class responsible to send e-mails.
- # config.mailer = 'Devise::Mailer'
+ config.mailer = 'MyMailer'
# Configure the parent class responsible to send e-mails.
# config.parent_mailer = 'ActionMailer::Base'
@@ -145,7 +145,7 @@
# 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
+ config.reconfirmable = false
# Defines which key will be used when confirming an account
# config.confirmation_keys = [:email]
diff --git a/config/routes.rb b/config/routes.rb
index 50b0e3a..8545b1b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,8 +1,20 @@
Rails.application.routes.draw do
- get 'home/index'
get 'welcome/sign_in'
get 'welcome/sign_up'
- get 'home/search'
+ get 'users/show'
+ get 'users/search'
+ get 'users/friends'
+ get 'users/about'
+ get 'users/photos'
+ get 'my_profiles/requests'
+ get 'my_profiles/friends'
+ get 'my_profiles/about'
+ get 'my_profiles/photos'
+ get 'my_profiles/timeline'
+ get 'my_profiles/avatar_info'
+ post 'my_profiles/change_avatar'
+
+ resource :my_profile
resources :posts do
resources :comments
@@ -15,7 +27,9 @@
resources :likes
end
+ resources :friendships
devise_for :users
- root 'home#index'
+
+ root 'my_profiles#timeline'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
diff --git a/db/migrate/20190313115322_create_friendships.rb b/db/migrate/20190313115322_create_friendships.rb
new file mode 100644
index 0000000..efd81c8
--- /dev/null
+++ b/db/migrate/20190313115322_create_friendships.rb
@@ -0,0 +1,10 @@
+class CreateFriendships < ActiveRecord::Migration[5.2]
+ def change
+ create_table :friendships do |t|
+ t.integer :user_id
+ t.integer :friend_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20190314142721_add_status_to_friendships.rb b/db/migrate/20190314142721_add_status_to_friendships.rb
new file mode 100644
index 0000000..377fba0
--- /dev/null
+++ b/db/migrate/20190314142721_add_status_to_friendships.rb
@@ -0,0 +1,5 @@
+class AddStatusToFriendships < ActiveRecord::Migration[5.2]
+ def change
+ add_column :friendships, :status, :integer
+ end
+end
diff --git a/db/migrate/20190326123720_add_confirmable_to_devise.rb b/db/migrate/20190326123720_add_confirmable_to_devise.rb
new file mode 100644
index 0000000..316de0d
--- /dev/null
+++ b/db/migrate/20190326123720_add_confirmable_to_devise.rb
@@ -0,0 +1,19 @@
+class AddConfirmableToDevise < ActiveRecord::Migration[5.2]
+ def up
+ add_column :users, :confirmation_token, :string
+ add_column :users, :confirmed_at, :datetime
+ add_column :users, :confirmation_sent_at, :datetime
+ # add_column :users, :unconfirmed_email, :string # Only if using reconfirmable
+ add_index :users, :confirmation_token, unique: true
+ # User.reset_column_information # Need for some types of updates, but not for update_all.
+ # To avoid a short time window between running the migration and updating all existing
+ # users as confirmed, do the following
+ User.update_all confirmed_at: DateTime.now
+ # All existing user accounts should be able to log in after this.
+ end
+
+ def down
+ remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at
+ # remove_columns :users, :unconfirmed_email # Only if using reconfirmable
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ccf9b95..327ede6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,27 +10,11 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_03_12_143225) do
+ActiveRecord::Schema.define(version: 2019_03_26_123720) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
- create_table "account_histories", force: :cascade do |t|
- t.bigint "account_id"
- t.integer "credit_rating"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["account_id"], name: "index_account_histories_on_account_id"
- end
-
- create_table "accounts", force: :cascade do |t|
- t.bigint "supplier_id"
- t.string "account_number"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["supplier_id"], name: "index_accounts_on_supplier_id"
- end
-
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
@@ -62,6 +46,14 @@
t.index ["user_id"], name: "index_comments_on_user_id"
end
+ create_table "friendships", force: :cascade do |t|
+ t.integer "user_id"
+ t.integer "friend_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "status"
+ end
+
create_table "likes", force: :cascade do |t|
t.bigint "user_id"
t.string "likable_type"
@@ -80,12 +72,6 @@
t.integer "user_id"
end
- create_table "suppliers", force: :cascade do |t|
- t.string "name"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- end
-
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
@@ -97,6 +83,10 @@
t.string "first_name"
t.string "last_name"
t.string "sex"
+ t.string "confirmation_token"
+ t.datetime "confirmed_at"
+ t.datetime "confirmation_sent_at"
+ t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
diff --git a/test/controllers/friendships_controller_test.rb b/test/controllers/friendships_controller_test.rb
new file mode 100644
index 0000000..fcf7413
--- /dev/null
+++ b/test/controllers/friendships_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FriendshipsControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/controllers/my_profiles_controller_test.rb b/test/controllers/my_profiles_controller_test.rb
new file mode 100644
index 0000000..49d29bb
--- /dev/null
+++ b/test/controllers/my_profiles_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class MyProfilesControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb
new file mode 100644
index 0000000..6c3da77
--- /dev/null
+++ b/test/controllers/users_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/fixtures/friendships.yml b/test/fixtures/friendships.yml
new file mode 100644
index 0000000..0f22a6e
--- /dev/null
+++ b/test/fixtures/friendships.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ user_id: 1
+ friend_id: 1
+
+two:
+ user_id: 1
+ friend_id: 1
diff --git a/test/controllers/home_controller_test.rb b/test/models/friendship_test.rb
similarity index 56%
rename from test/controllers/home_controller_test.rb
rename to test/models/friendship_test.rb
index 3e06bf0..aa27b3f 100644
--- a/test/controllers/home_controller_test.rb
+++ b/test/models/friendship_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class HomeControllerTest < ActionDispatch::IntegrationTest
+class FriendshipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end