-
Notifications
You must be signed in to change notification settings - Fork 1
Upd for simple vlontakte auth and registration #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: yarik_dev
Are you sure you want to change the base?
Changes from all commits
f67a78d
88e0658
1387369
a92298e
3fdef06
f30033c
651ebaa
f137fc3
d96b79e
a1b042a
ab54d9e
7463819
c36dbdf
8431421
093b838
a11d50d
a0a97a1
b9fa558
578ce80
c9e705b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,6 @@ | |
| /log/*.log | ||
| /tmp | ||
|
|
||
| .idea/ | ||
| .idea/ | ||
|
|
||
| /public/assets | ||
| 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/ |
| 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/ |
| 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 | ||
|
|
||
| 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/ |
| 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/ |
| 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 |
| 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 } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be in future we will going to develop mobile application:)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| module Users::OmniauthCallbacksHelper | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| module UsersHelper | ||
| end |
| 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 |
| 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 |
| 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: 'Сохранить' | ||
|
|
||
|
|
| 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 |
| 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 | ||
|
|
||
|
|
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
||
|
|
@@ -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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем этот гем?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужно почистить, уж точно не для продакшена :)