This commit is contained in:
Thomas Blazek
2013-08-25 15:22:41 +02:00
14 changed files with 92 additions and 24 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/config/initializers/omniauth_secrets.rb
# See http://help.github.com/ignore-files/ for more about ignoring files. # See http://help.github.com/ignore-files/ for more about ignoring files.
# #
# If you find yourself ignoring temporary files generated by your text editor # If you find yourself ignoring temporary files generated by your text editor

View File

@@ -53,6 +53,8 @@ gem "paper_trail" , '>=2.7.0'
# User management # User management
gem "devise" ,'~>2.2.3' gem "devise" ,'~>2.2.3'
gem "omniauth"
gem "omniauth-facebook"
# Roles for users # Roles for users
gem "rolify" gem "rolify"

View File

@@ -67,6 +67,8 @@ GEM
factory_girl_rails (4.2.1) factory_girl_rails (4.2.1)
factory_girl (~> 4.2.0) factory_girl (~> 4.2.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faraday (0.8.8)
multipart-post (~> 1.2.0)
formtastic (2.2.1) formtastic (2.2.1)
actionpack (>= 3.0) actionpack (>= 3.0)
formtastic-bootstrap (2.0.0) formtastic-bootstrap (2.0.0)
@@ -79,7 +81,9 @@ GEM
paper_trail (~> 2) paper_trail (~> 2)
haml (4.0.0) haml (4.0.0)
tilt tilt
hashie (2.0.5)
hike (1.2.1) hike (1.2.1)
httpauth (0.2.0)
i18n (0.6.1) i18n (0.6.1)
journey (1.0.4) journey (1.0.4)
jquery-fileupload-rails (0.4.1) jquery-fileupload-rails (0.4.1)
@@ -89,6 +93,8 @@ GEM
railties (>= 3.0, < 5.0) railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.7.7) json (1.7.7)
jwt (0.1.8)
multi_json (>= 1.5)
libv8 (3.11.8.13) libv8 (3.11.8.13)
mail (2.4.4) mail (2.4.4)
i18n (>= 0.4.0) i18n (>= 0.4.0)
@@ -96,6 +102,21 @@ GEM
treetop (~> 1.4.8) treetop (~> 1.4.8)
mime-types (1.21) mime-types (1.21)
multi_json (1.5.1) multi_json (1.5.1)
multipart-post (1.2.0)
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.1.4)
hashie (>= 1.2, < 3)
rack
omniauth-facebook (1.4.1)
omniauth-oauth2 (~> 1.1.0)
omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
orm_adapter (0.4.0) orm_adapter (0.4.0)
paper_trail (2.7.0) paper_trail (2.7.0)
activerecord (~> 3.0) activerecord (~> 3.0)
@@ -199,6 +220,8 @@ DEPENDENCIES
haml haml
jquery-fileupload-rails jquery-fileupload-rails
jquery-rails jquery-rails
omniauth
omniauth-facebook
paper_trail (>= 2.7.0) paper_trail (>= 2.7.0)
paperclip (~> 3.4.0) paperclip (~> 3.4.0)
rails (= 3.2.9) rails (= 3.2.9)

View File

@@ -19,7 +19,7 @@ class MembershipsController < ApplicationController
# POST /memberships.json # POST /memberships.json
def create def create
@membership = Membership.new(params[:membership]) @membership = Membership.new(params[:membership])
@membership.fetprofile= Fetprofle.find(params[:fetprofile_id]) @membership.fetprofile= Fetprofile.find(params[:fetprofile_id])
respond_to do |format| respond_to do |format|
if @membership.save if @membership.save
format.html { redirect_to @membership.fetprofile, notice: 'Membership was successfully created.' } format.html { redirect_to @membership.fetprofile, notice: 'Membership was successfully created.' }

View File

@@ -0,0 +1,15 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end

View File

@@ -15,12 +15,13 @@
# #
class Fetprofile < ActiveRecord::Base class Fetprofile < ActiveRecord::Base
attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname,:memberships_attributes
has_many :memberships has_many :memberships
has_many :gremien, :through=> :membership has_many :gremien, :through=> :membership
mount_uploader :picture, PictureUploader mount_uploader :picture, PictureUploader
def name def name
[vorname, nachname, "(",short,")"].join(" ") [vorname, nachname, "(",short,")"].join(" ")
end end
accepts_nested_attributes_for :memberships
scope :active, -> { where(:active=>:true).order(:vorname) } scope :active, -> { where(:active=>:true).order(:vorname) }
end end

View File

@@ -30,10 +30,29 @@ class User < ActiveRecord::Base
# :token_authenticatable, :confirmable, # :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable # :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,:confirmable, devise :database_authenticatable, :registerable,:confirmable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable,:omniauthable, :omniauth_providers => [:facebook]
# Setup accessible (or protected) attributes for your model # Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid, :name
# attr_accessible :title, :body # attr_accessible :title, :body
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
unless user
user = User.create(name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20]
)
end
user
end
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
user.email = data["email"] if user.email.blank?
end
end
end
end end

View File

@@ -17,20 +17,19 @@
<div class="span4"><%= f.input :picture, :as=>:file %></div> <div class="span4"><%= f.input :picture, :as=>:file %></div>
<div class="span4"> <%= f.input :fetmailalias %></div> <div class="span4"> <%= f.input :fetmailalias %></div>
</div> </div>
<% @fetprofile.memberships.each do |m| %>
<%= semantic_fields_for m do |mf| %> <%= f.inputs :for => :memberships do |membership,i| %>
<div class="row-fluid"> <div class="row-fluid">
<div class="span1"></div> <div class="span1"></div>
<%= mf.inputs do %>
<div class="span3"><%= mf.input :start, :as=>:date %></div> <div class="span3"><%= membership.input :start, :as=>:date %></div>
<div class="span3"><%= mf.input :stop %></div> <div class="span3"><%= membership.input :stop %></div>
<div class="span3"><%= mf. input :gremium %></div> <div class="span3"><%= membership. input :gremium %></div>
<div class="span2"><%= mf.input :typ ,:as=>:radio, :collection=>{"mitglied"=>1, "ersatzmitglied"=>2} %></div> <div class="span2"><%= membership.input :typ ,:as=>:radio, :collection=>{"mitglied"=>1, "ersatzmitglied"=>2} %></div>
</div> <% end %>
<% end %> <% end %>
</div>
<% end %>
<% end
end %>
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
<%= f.actions do %> <%= f.actions do %>

View File

@@ -1,4 +1,4 @@
<%= semantic_form_for @membership do |f| %> <%= semantic_form_for [@membership.fetprofile,@membership] do |f| %>
<%= f.inputs do %> <%= f.inputs do %>
<%= f.input :gremium, :as=>:radio %> <%= f.input :gremium, :as=>:radio %>
<%= f.input :start %> <%= f.input :start %>

View File

@@ -2,4 +2,4 @@
<%= render 'form' %> <%= render 'form' %>
<%= link_to 'Back', memberships_path %> <%= link_to 'Back', @membership.fetprofile %>

View File

@@ -223,7 +223,7 @@ Devise.setup do |config|
# ==> OmniAuth # ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting # Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks. # up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' #config.omniauth :facebook, 'appid', 'secret'
# ==> Warden configuration # ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or # If you want to use other strategies, that are not supported by Devise, or

View File

@@ -0,0 +1 @@

View File

@@ -1,6 +1,6 @@
Fetsite::Application.routes.draw do Fetsite::Application.routes.draw do
devise_for :users devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
resources :home, :only=>[:index] resources :home, :only=>[:index]
#get 'home',:controller=>home,:action=>:index,:as=>"home_index" #get 'home',:controller=>home,:action=>:index,:as=>"home_index"
scope '(:locale)/admin' do scope '(:locale)/admin' do
@@ -39,10 +39,10 @@
resources :galleries do resources :galleries do
resources :fotos resources :fotos
end end
resources :memberships, :except=>[:new, :show, :edit]
resources :gremien resources :gremien
resources :fetprofiles do resources :fetprofiles do
resources :memberships, :only=>[:new, :show, :edit] resources :memberships
end end
resources :lecturers resources :lecturers
resources :semesters resources :semesters

View File

@@ -0,0 +1,7 @@
class AddColumnsToUsers < ActiveRecord::Migration
def change
add_column :users, :provider, :string
add_column :users, :uid, :string
add_column :users, :name, :string
end
end