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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
/log/*.log
/tmp

.idea/
.idea/

/public/assets
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +36,7 @@ group :assets do
end

gem 'jquery-rails'

gem "rb-readline"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем этот гем?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно почистить, уж точно не для продакшена :)

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

Expand All @@ -51,4 +54,5 @@ gem 'jquery-rails'

group :development do
gem 'annotate'
end
gem 'localtunnel'
end
23 changes: 23 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -118,13 +122,26 @@ 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)
jwt (~> 0.1.4)
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Binary file added app/assets/images/images.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/assets/images/vk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/vkontakte-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/users.js.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/users/omniauth_callbacks.js.coffee
Original file line number Diff line number Diff line change
@@ -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/
8 changes: 6 additions & 2 deletions app/assets/stylesheets/bootstrap_and_overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/formtastic_fixes.css.sass
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.formtastic
input.btn

width: 270px
display: inline-block
//*display: inline
//*zoom: 1
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.css.scss
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users/omniauth_callbacks.css.scss
Original file line number Diff line number Diff line change
@@ -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/
11 changes: 11 additions & 0 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -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
79 changes: 79 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we going to support json? if no, why do we need this format?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be in future we will going to develop mobile application:)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's just a scaffold-generated code, lets just avoid it and not making "code for future", often it's just a dead code which is hard to maintain and support.

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
2 changes: 2 additions & 0 deletions app/helpers/users/omniauth_callbacks_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Users::OmniauthCallbacksHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
15 changes: 15 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -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
39 changes: 37 additions & 2 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
.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"
2 changes: 1 addition & 1 deletion app/views/pages/main.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%h1 С кем хочешь погулять?
= link_to "Man", men_path
= link_to "Woman", women_path
= link_to "Woman", women_path
26 changes: 26 additions & 0 deletions app/views/users/_form.html.haml
Original file line number Diff line number Diff line change
@@ -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: 'Сохранить'


5 changes: 5 additions & 0 deletions app/views/users/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%h1= current_user.username + ', edit profile'

= render 'form'

= link_to 'Back', root_path
8 changes: 8 additions & 0 deletions app/views/users/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%h1
%h1='Welcome ' + session["devise.vkontakte_data"]["info"]["first_name"]

= render 'form'

= link_to 'Back', root_path


Empty file.
34 changes: 34 additions & 0 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"

config.omniauth :vkontakte, 'APP_ID', 'APP_SECRET'
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"

Expand Down Expand Up @@ -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
end
Loading