From 6170007875a76cf6bba977f7abde5eeecccb96f3 Mon Sep 17 00:00:00 2001 From: KateGL Date: Sat, 10 Jan 2015 12:33:20 +0200 Subject: [PATCH 01/14] =?UTF-8?q?=D0=A2=D0=B8=D0=BF=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 10 ++++++++++ app/controllers/users_controller.rb | 1 + app/models/user.rb | 10 ++++++++++ app/views/devise/registrations/new.html.erb | 8 ++++++++ app/views/users/profile.html.erb | 6 ++++-- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..eb92e3b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,14 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + before_filter :configure_permitted_parameters, if: :devise_controller? + + protected + + def configure_permitted_parameters + devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:email, :password, :kind)} + devise_parameter_sanitizer.for(:account_update){|u| u.permit(:email, :password)} + + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 59e9eab..665f873 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController def profile end + end diff --git a/app/models/user.rb b/app/models/user.rb index b5e8f87..cf4be34 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,4 +15,14 @@ class User < ActiveRecord::Base has_many :user_owner_relations, :class_name =>'UserRelation', :foreign_key =>"owner_id", :inverse_of => :user_owner, dependent: :destroy has_many :user_rel_relations, :class_name => 'UserRelation', :foreign_key =>"user_rel_id", :inverse_of => :user_rel, dependent: :destroy has_many :posts, dependent: :destroy + + def kind_name + if self.kind == 1 + 'User' + elsif self.kind == 10 + 'Community' + else + 'Unknown kind' + end + end end diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 343b265..befd479 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -8,6 +8,12 @@ <%= f.email_field :email, autofocus: true %> +
+ <%= f.label :kind %>
+ <%= f.radio_button :kind, '1', :checked => true %><%= f.label :kind, "User" %> + <%= f.radio_button :kind, '10' %><%= f.label :kind, "Community" %> +
+
<%= f.label :password %> <% if @validatable %> @@ -21,6 +27,8 @@ <%= f.password_field :password_confirmation, autocomplete: "off" %>
+ +
<%= f.submit "Sign up" %>
diff --git a/app/views/users/profile.html.erb b/app/views/users/profile.html.erb index ee16858..626423a 100644 --- a/app/views/users/profile.html.erb +++ b/app/views/users/profile.html.erb @@ -1,6 +1,8 @@ <% if user_signed_in? %> - Здравствуйте, <%= current_user.email %> - <%= link_to 'Выйти', destroy_user_session_path, :method => :delete %> + Здравствуйте, <%= current_user.email %>
+ Тип учетной записи: <%= current_user.kind_name %> + +
<%= link_to 'Выйти', destroy_user_session_path, :method => :delete %> <% else %> <%= link_to 'Войти', new_user_session_path %> или <%= link_to 'Зарегистрироваться', new_user_registration_path %> <% end %> \ No newline at end of file From 77b5777ca32c2aa94cc2cfa56f86d2f2a32ff8f6 Mon Sep 17 00:00:00 2001 From: KateGL Date: Sat, 10 Jan 2015 16:32:39 +0200 Subject: [PATCH 02/14] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D1=81=D0=BE=D0=BE?= =?UTF-8?q?=D0=B1=D1=89=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D0=B8=20=D0=BB?= =?UTF-8?q?=D1=8E=D0=B4=D0=B5=D0=B9=20:=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/controllers/application_controller.rb | 6 +++--- app/controllers/users_controller.rb | 2 ++ app/models/user.rb | 11 ++++++++++- app/views/devise/registrations/edit.html.erb | 5 +++++ app/views/devise/registrations/new.html.erb | 6 ++++++ app/views/layouts/application.html.erb | 1 + app/views/users/profile.html.erb | 20 +++++++++++++++++--- 9 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 09643ba..ee26e84 100644 --- a/Gemfile +++ b/Gemfile @@ -31,6 +31,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc #auth gem 'devise' gem 'cancancan', '~> 1.7' +gem 'will_paginate','~>3.0.5' + # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index e36077a..00c2f4b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -214,6 +214,7 @@ GEM webmock (1.20.4) addressable (>= 2.3.6) crack (>= 0.3.2) + will_paginate (3.0.7) PLATFORMS ruby @@ -243,3 +244,4 @@ DEPENDENCIES unicorn web-console (~> 2.0) webmock + will_paginate (~> 3.0.5) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eb92e3b..e848a2d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,14 +2,14 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - + #before_action :authenticate_user! before_filter :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters - devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:email, :password, :kind)} - devise_parameter_sanitizer.for(:account_update){|u| u.permit(:email, :password)} + devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:email, :password, :kind, :name)} + devise_parameter_sanitizer.for(:account_update){|u| u.permit(:email, :password, :current_password, :name)} end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 665f873..349544c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,6 @@ class UsersController < ApplicationController + #before_action :authenticate_user! + def profile end diff --git a/app/models/user.rb b/app/models/user.rb index cf4be34..0e9ea95 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,11 +18,20 @@ class User < ActiveRecord::Base def kind_name if self.kind == 1 - 'User' + 'Person' elsif self.kind == 10 'Community' else 'Unknown kind' end end + + def person? + self.kind == 1 + end + + def community? + self.kind == 10 + end + end diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 3ea40f0..d7aea1a 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -8,6 +8,11 @@ <%= f.email_field :email, autofocus: true %> +
+ <%= f.label :name %>
+ <%= f.text_field :name, autocomplete: "on" %> +
+ <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
<% end %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index befd479..20e4b6f 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -8,6 +8,12 @@ <%= f.email_field :email, autofocus: true %> +
+ <%= f.label :name %>
+ <%= f.text_field :name, autocomplete: "on" %> +
+ +
<%= f.label :kind %>
<%= f.radio_button :kind, '1', :checked => true %><%= f.label :kind, "User" %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c2d3b91..f6f65a0 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -53,6 +53,7 @@ <%if user_signed_in? %>
  • <%= link_to "My profile", user_root_path %>
  • <%= link_to "News", "/" %>
  • +
  • <%= link_to "Search", "/" %>
  • <%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
  • <%else%>
  • <%= link_to "Log in", new_user_session_path %>
  • diff --git a/app/views/users/profile.html.erb b/app/views/users/profile.html.erb index 626423a..7208b88 100644 --- a/app/views/users/profile.html.erb +++ b/app/views/users/profile.html.erb @@ -1,8 +1,22 @@ +<% content_for :title do %> + Social: My profile +<% end %> + <% if user_signed_in? %> - Здравствуйте, <%= current_user.email %>
    - Тип учетной записи: <%= current_user.kind_name %> + Здравствуйте, <%= current_user.name %>
    + Тип учетной записи: <%= current_user.kind_name %>
    + <%= link_to 'Изменить данные учетной записи', edit_user_registration_path %>
    + + <% if current_user.person? %> + <%= render "person" %> + <% end %> + + <% if current_user.community? %> + <%= render "community" %> + <% end %> -
    <%= link_to 'Выйти', destroy_user_session_path, :method => :delete %> + +
    <% else %> <%= link_to 'Войти', new_user_session_path %> или <%= link_to 'Зарегистрироваться', new_user_registration_path %> <% end %> \ No newline at end of file From e3f5fa304c0c0f63256f6f03590a228824a9f538 Mon Sep 17 00:00:00 2001 From: KateGL Date: Sat, 10 Jan 2015 16:37:06 +0200 Subject: [PATCH 03/14] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D1=81=D0=BE=D0=BE?= =?UTF-8?q?=D0=B1=D1=89=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D0=B8=20=D0=BB?= =?UTF-8?q?=D1=8E=D0=B4=D0=B5=D0=B9=20:=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/people_controller.rb | 7 +++++++ app/views/users/_community.html.erb | 1 + app/views/users/_person.html.erb | 1 + spec/controllers/people_controller_spec.rb | 5 +++++ 4 files changed, 14 insertions(+) create mode 100644 app/controllers/people_controller.rb create mode 100644 app/views/users/_community.html.erb create mode 100644 app/views/users/_person.html.erb create mode 100644 spec/controllers/people_controller_spec.rb diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb new file mode 100644 index 0000000..6e2c61f --- /dev/null +++ b/app/controllers/people_controller.rb @@ -0,0 +1,7 @@ +class PeopleController < ApplicationController + + def index + @people = Person.all + end + +end diff --git a/app/views/users/_community.html.erb b/app/views/users/_community.html.erb new file mode 100644 index 0000000..c0afad8 --- /dev/null +++ b/app/views/users/_community.html.erb @@ -0,0 +1 @@ +Community \ No newline at end of file diff --git a/app/views/users/_person.html.erb b/app/views/users/_person.html.erb new file mode 100644 index 0000000..579bc25 --- /dev/null +++ b/app/views/users/_person.html.erb @@ -0,0 +1 @@ +Person data \ No newline at end of file diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb new file mode 100644 index 0000000..318c688 --- /dev/null +++ b/spec/controllers/people_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe PeopleController, :type => :controller do + +end From 324375e22a9a83fa8e5760b30189ade91ae5ce69 Mon Sep 17 00:00:00 2001 From: KateGL Date: Sun, 11 Jan 2015 01:59:35 +0200 Subject: [PATCH 04/14] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BE=20=D1=81=D0=B2=D1=8F=D0=B7=D1=8C=D1=8E=20?= =?UTF-8?q?community=5Fmembership=20=D0=BF=D1=80=D0=B8=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8=20User?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 1 + app/models/community.rb | 3 ++- app/models/user.rb | 5 +++-- app/views/layouts/application.html.erb | 12 +++++++++++- app/views/users/profile.html.erb | 2 +- config/routes.rb | 2 ++ 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 349544c..ef8836f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,4 +4,5 @@ class UsersController < ApplicationController def profile end + end diff --git a/app/models/community.rb b/app/models/community.rb index 454db8b..c0ca09e 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -1,4 +1,5 @@ class Community < ActiveRecord::Base has_one :user, :foreign_key => "id" - has_many :users, through: :community_memberships, dependent: :destroy + has_many :users, through: :community_memberships#, dependent: :destroy + has_many :community_memberships, dependent: :destroy end diff --git a/app/models/user.rb b/app/models/user.rb index 0e9ea95..85e4b0e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,8 +11,9 @@ class User < ActiveRecord::Base #has_many :posts belongs_to :person, dependent: :destroy belongs_to :community, dependent: :destroy - has_many :community, through: :community_memberships, dependent: :destroy - has_many :user_owner_relations, :class_name =>'UserRelation', :foreign_key =>"owner_id", :inverse_of => :user_owner, dependent: :destroy + has_many :community, through: :community_memberships#, dependent: :delete_all + has_many :community_memberships, dependent: :destroy + has_many :user_owner_relations, :class_name =>'UserRelation', :foreign_key =>"user_owner_id", :inverse_of => :user_owner, dependent: :destroy has_many :user_rel_relations, :class_name => 'UserRelation', :foreign_key =>"user_rel_id", :inverse_of => :user_rel, dependent: :destroy has_many :posts, dependent: :destroy diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f6f65a0..ac23897 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -51,7 +51,17 @@