diff --git a/.gitignore b/.gitignore index 5d08725..a4eef28 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,6 @@ /log/*.log /tmp -.idea/ \ No newline at end of file +.idea/ + +/public/assets diff --git a/Gemfile b/Gemfile index 743b6e2..497e95b 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,9 @@ gem 'formtastic-bootstrap' gem 'client_side_validations' gem 'client_side_validations-formtastic' +gem 'devise' +gem 'omniauth' +gem 'omniauth-vkontakte' # Gems used only for assets and not required # in production environments by default. group :assets do @@ -33,7 +36,7 @@ group :assets do end gem 'jquery-rails' - +gem "rb-readline" # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' @@ -51,4 +54,5 @@ gem 'jquery-rails' group :development do gem 'annotate' -end \ No newline at end of file + gem 'localtunnel' +end diff --git a/Gemfile.lock b/Gemfile.lock index c46848b..0ec63fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,10 @@ GEM kaminari (0.14.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) + localtunnel (0.3) + json (>= 1.2.4) + net-ssh (>= 2.0.22) + net-ssh-gateway (>= 1.0.1) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) @@ -118,6 +122,9 @@ GEM mime-types (1.19) multi_json (1.5.0) multipart-post (1.1.5) + net-ssh (2.6.3) + net-ssh-gateway (1.1.0) + net-ssh (>= 1.99.1) oauth2 (0.8.0) faraday (~> 0.8) httpauth (~> 0.1) @@ -125,6 +132,16 @@ GEM multi_json (~> 1.0) rack (~> 1.2) oj (1.4.7) + omniauth (1.1.1) + hashie (~> 1.2) + rack + omniauth-oauth2 (1.1.1) + oauth2 (~> 0.8.0) + omniauth (~> 1.0) + omniauth-vkontakte (1.2.0) + multi_json + omniauth (~> 1.1.0) + omniauth-oauth2 (~> 1.0) orm_adapter (0.4.0) pg (0.14.1) polyamorous (0.5.0) @@ -153,6 +170,7 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.3) + rb-readline (0.4.2) rdoc (3.12) json (~> 1.4) responders (0.9.3) @@ -205,12 +223,17 @@ DEPENDENCIES client_side_validations client_side_validations-formtastic coffee-rails (~> 3.2.1) + devise formtastic formtastic-bootstrap haml-rails jquery-rails + localtunnel + omniauth + omniauth-vkontakte pg rails (= 3.2.11) + rb-readline russian sass-rails (~> 3.2.3) sqlite3 diff --git a/app/assets/images/images.jpg b/app/assets/images/images.jpg new file mode 100644 index 0000000..9aa2579 Binary files /dev/null and b/app/assets/images/images.jpg differ diff --git a/app/assets/images/vk.png b/app/assets/images/vk.png index 26eb72a..52cce79 100644 Binary files a/app/assets/images/vk.png and b/app/assets/images/vk.png differ diff --git a/app/assets/images/vkontakte-logo.png b/app/assets/images/vkontakte-logo.png new file mode 100644 index 0000000..ce7f66f Binary files /dev/null and b/app/assets/images/vkontakte-logo.png differ diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/users.js.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://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/users/omniauth_callbacks.js.coffee b/app/assets/javascripts/users/omniauth_callbacks.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/users/omniauth_callbacks.js.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://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css b/app/assets/stylesheets/bootstrap_and_overrides.css index 08a1ea8..36d2a4d 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css +++ b/app/assets/stylesheets/bootstrap_and_overrides.css @@ -5,9 +5,13 @@ To use Glyphicons sprites instead of Font Awesome, replace with "require twitter-bootstrap-static/sprites" =require twitter-bootstrap-static/fontawesome */ - +body { + padding-top: 60px; + padding-left: 30px; + padding-right: 30px; +} .alert { width: 62%; text-align: center; margin: 10px auto auto; -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/formtastic_fixes.css.sass b/app/assets/stylesheets/formtastic_fixes.css.sass index da8711c..1281d4c 100644 --- a/app/assets/stylesheets/formtastic_fixes.css.sass +++ b/app/assets/stylesheets/formtastic_fixes.css.sass @@ -1,6 +1,6 @@ .formtastic input.btn - + width: 270px display: inline-block //*display: inline //*zoom: 1 diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss new file mode 100644 index 0000000..31a2eac --- /dev/null +++ b/app/assets/stylesheets/users.css.scss @@ -0,0 +1,3 @@ +// 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/assets/stylesheets/users/omniauth_callbacks.css.scss b/app/assets/stylesheets/users/omniauth_callbacks.css.scss new file mode 100644 index 0000000..155643a --- /dev/null +++ b/app/assets/stylesheets/users/omniauth_callbacks.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Users::OmniauthCallbacks 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/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb new file mode 100644 index 0000000..ff47de9 --- /dev/null +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -0,0 +1,11 @@ +class Users::OmniauthCallbacksController < ApplicationController + def vkontakte + user = User.find_for_vkontakte_oauth request.env["omniauth.auth"] + if user + sign_in_and_redirect user, :event => :authentication + else + session["devise.vkontakte_data"] = request.env["omniauth.auth"] + redirect_to new_user_path + end + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..0e15642 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,79 @@ +class UsersController < ApplicationController + before_filter :authenticate_user!, :only => [:edit, :update, :destroy] + # GET /users/new + # GET /users/new.json + def new + if user_signed_in? + redirect_to root_path, notice: 'Already signin' + elsif !session["devise.vkontakte_data"] + redirect_to root_path + else + @user = User.new + respond_to do |format| + format.html + format.json { render json: @user } + end + end + end + + def show + @user = User.find(params[:id]) + respond_to do |format| + format.html # show.html.erb + format.json { render json: @user } + end + end + + # GET /users/1/edit + def edit + @user = User.find(params[:id]) + end + + # POST /users + # POST /users.json + def create + @user = User.new(user_params) + respond_to do |format| + if @user.save + format.html { redirect_to @user, notice: 'User was successfully created.' } + format.json { render json: @user, status: :created, location: @user } + else + format.html { render action: "new" } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /users/1 + # PATCH/PUT /users/1.json + def update + @user = User.find(params[:id]) + + respond_to do |format| + if @user.update_attributes(user_params) + format.html { redirect_to @user, notice: 'User was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /users/1 + # DELETE /users/1.json + def destroy + @user = User.find(params[:id]) + @user.destroy + + respond_to do |format| + format.html { redirect_to users_url } + format.json { head :no_content } + end + end + + private + def user_params + params.require(:user).permit(:email, :gender, :uid, :middlename, :name, :phonenumber, :slogan, :surname, :urlphoto, :url, :username, :password) + end +end diff --git a/app/helpers/users/omniauth_callbacks_helper.rb b/app/helpers/users/omniauth_callbacks_helper.rb new file mode 100644 index 0000000..7c6e5e0 --- /dev/null +++ b/app/helpers/users/omniauth_callbacks_helper.rb @@ -0,0 +1,2 @@ +module Users::OmniauthCallbacksHelper +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/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..ab27d4c --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,15 @@ +class User < ActiveRecord::Base + # Include default devise modules. Others available are: + # :token_authenticatable, :confirmable, + # :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable, :omniauthable + + # Setup accessible (or protected) attributes for your model + attr_accessible :email, :password, :password_confirmation, :remember_me + attr_accessible :email, :url, :uid, :gender, :middlename, :name, :phonenumber, :slogan, :surname, :urlphoto, :username + + def self.find_for_vkontakte_oauth access_token + @user = User.where(:uid => access_token.uid).first + end +end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 3370dea..81470d7 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -5,7 +5,42 @@ = stylesheet_link_tag "application", :media => "all" = javascript_include_tag "application" = csrf_meta_tags + + / Le HTML5 shim, for IE6-8 support of HTML elements + /[if lt IE 9] + = javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js" + = stylesheet_link_tag "application", :media => "all" + %link(href="images/favicon.ico" rel="shortcut icon") + %link(href="images/apple-touch-icon.png" rel="apple-touch-icon") + %link(href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon" sizes="72x72") + %link(href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon" sizes="114x114") + %body + .container + .navbar.navbar-fixed-top + .navbar-inner + .container + %a.btn.btn-navbar(data-target=".nav-collapse" data-toggle="collapse") + %span.icon-bar + %span.icon-bar + %span.icon-bar + %a.brand(href=root_path) Купи Прогулку + + .container.nav-collapse + %ul.nav + - if user_signed_in? + %li= link_to "#{current_user.username} (vkontakte)", current_user.url + %li= link_to "My profile", edit_user_path(current_user) + %li= link_to "Sign out", destroy_user_session_path, :method => :delete .container - = bootstrap_flash - = yield \ No newline at end of file + .content + .row + .span9 + = yield + .span3 + -unless user_signed_in? + %p= link_to image_tag('vkontakte-logo.png'), user_omniauth_authorize_path(:vkontakte) + + %footer + %p © Company 2012 + = javascript_include_tag "application" diff --git a/app/views/pages/main.html.haml b/app/views/pages/main.html.haml index 0fb17b8..975e854 100644 --- a/app/views/pages/main.html.haml +++ b/app/views/pages/main.html.haml @@ -1,3 +1,3 @@ %h1 С кем хочешь погулять? = link_to "Man", men_path -= link_to "Woman", women_path \ No newline at end of file += link_to "Woman", women_path diff --git a/app/views/users/_form.html.haml b/app/views/users/_form.html.haml new file mode 100644 index 0000000..cc1928a --- /dev/null +++ b/app/views/users/_form.html.haml @@ -0,0 +1,26 @@ += semantic_form_for @user do |f| + - if @user.errors.any? + #error_explanation + %h2= "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:" + %ul + - @user.errors.full_messages.each do |msg| + %li= msg + = f.inputs do + - hint = "для организаторов, данные не публикуются" + = f.input :username, label: 'Имя на сайте' + = f.input :name, label: 'Ваше имя', :hint => hint + = f.input :surname, label: 'Ваша фамилия', :hint => hint + = f.input :middlename, label: 'Ваше отчество', :hint => hint + = f.input :phonenumber, label: 'Контактный телефон', :hint => hint, :as => :string + = f.input :email, label: 'Ваш имейл', :hint => 'для уведомлений' + = f.input :urlphoto, label: 'Ваше фото' + = f.input :slogan, label: 'Ваш девиз' + = f.input :password, :include_blank => false + - unless user_signed_in? + = f.input :uid, :as => 'hidden', :input_html => { :value => session["devise.vkontakte_data"]["uid"]} + = f.input :url, :as => 'hidden', :input_html => { :value => session["devise.vkontakte_data"]["info"]["urls"]["Vkontakte"]} + = f.select :gender, [["Male", false], ["Female", true]], label: 'Ваш пол' + + = f.action :submit, :as => 'button', label: 'Сохранить' + + diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml new file mode 100644 index 0000000..603fc1d --- /dev/null +++ b/app/views/users/edit.html.haml @@ -0,0 +1,5 @@ +%h1= current_user.username + ', edit profile' + += render 'form' + += link_to 'Back', root_path diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml new file mode 100644 index 0000000..64d2962 --- /dev/null +++ b/app/views/users/new.html.haml @@ -0,0 +1,8 @@ +%h1 +%h1='Welcome ' + session["devise.vkontakte_data"]["info"]["first_name"] + += render 'form' + += link_to 'Back', root_path + + diff --git a/app/views/users/omniauth_callbacks/vkontakte.html.haml b/app/views/users/omniauth_callbacks/vkontakte.html.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml new file mode 100644 index 0000000..5e084fe --- /dev/null +++ b/app/views/users/show.html.haml @@ -0,0 +1,34 @@ +%p#notice= notice + +%p + %b Gender: + = @user.gender +%p + %b Username: + = @user.username +%p + %b Surname: + = @user.surname +%p + %b Name: + = @user.name +%p + %b Middlename: + = @user.middlename +%p + %b Phonenumber: + = @user.phonenumber +%p + %b Email: + = @user.email +%p + %b Urlprofile: + = @user.url +%p + %b Urlphoto: + = @user.urlphoto +%p + %b Slogan: + = @user.slogan + += link_to 'Back', root_path diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index ad83db7..a9da34e 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -5,7 +5,7 @@ # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class with default "from" parameter. config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" - + config.omniauth :vkontakte, 'APP_ID', 'APP_SECRET' # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" @@ -229,4 +229,4 @@ # When using omniauth, Devise cannot automatically set Omniauth path, # so you need to do it manually. For the users scope, it would be: # config.omniauth_path_prefix = "/my_engine/users/auth" -end \ No newline at end of file +end diff --git a/config/routes.rb b/config/routes.rb index d5895dc..7a91154 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,14 @@ KupiProgulku::Application.routes.draw do + devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } + resources :users + + get "omniauth_callbacks/vkontakte" + resources :lots do resources :bets end - ActiveAdmin.routes(self) devise_for :admin_users, ActiveAdmin::Devise.config diff --git a/db/migrate/20130130234423_create_users.rb b/db/migrate/20130130234423_create_users.rb new file mode 100644 index 0000000..db649d8 --- /dev/null +++ b/db/migrate/20130130234423_create_users.rb @@ -0,0 +1,18 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :gender + t.string :username + t.string :surname + t.string :name + t.string :middlename + t.integer :phonenumber + t.string :url + t.string :urlphoto + t.string :slogan + t.integer :uid + + t.timestamps + end + end +end diff --git a/db/migrate/20130130234924_add_devise_to_users.rb b/db/migrate/20130130234924_add_devise_to_users.rb new file mode 100644 index 0000000..98ae688 --- /dev/null +++ b/db/migrate/20130130234924_add_devise_to_users.rb @@ -0,0 +1,53 @@ +class AddDeviseToUsers < ActiveRecord::Migration + def self.up + change_table(:users) do |t| + ## Database authenticatable + t.string :email, :null => false, :default => "" + t.string :encrypted_password, :null => false, :default => "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, :default => 0 + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + ## Token authenticatable + # t.string :authentication_token + + + # Uncomment below if timestamps were not included in your original model. + # t.timestamps + end + + add_index :users, :email, :unique => true + add_index :users, :reset_password_token, :unique => true + # add_index :users, :confirmation_token, :unique => true + # add_index :users, :unlock_token, :unique => true + # add_index :users, :authentication_token, :unique => true + end + + def self.down + # By default, we don't want to make any assumption about how to roll back a migration when your + # model already existed. Please edit below which fields you would like to remove in this migration. + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index be63c21..d128500 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130107165259) do +ActiveRecord::Schema.define(:version => 20130130234924) do create_table "active_admin_comments", :force => true do |t| t.string "resource_id", :null => false @@ -78,4 +78,32 @@ t.datetime "updated_at", :null => false end + create_table "users", :force => true do |t| + t.string "gender" + t.string "username" + t.string "surname" + t.string "name" + t.string "middlename" + t.integer "phonenumber" + t.string "url" + t.string "urlphoto" + t.string "slogan" + t.integer "uid" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :default => "", :null => false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", :default => 0 + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + end + + add_index "users", ["email"], :name => "index_users_on_email", :unique => true + add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true + end