hero_generator 0.0.1.alpha5 → 0.0.1.alpha6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/lib/generators/hero/authentication/USAGE +8 -0
  2. data/lib/generators/hero/authentication/authentication_generator.rb +107 -0
  3. data/lib/generators/hero/authentication/templates/config/config.yml +22 -0
  4. data/lib/generators/hero/authentication/templates/config/initializers/action_mailer.rb +60 -0
  5. data/lib/generators/hero/authentication/templates/config/initializers/load_config.rb +3 -0
  6. data/lib/generators/hero/authentication/templates/config/locales/en.yml +52 -0
  7. data/lib/generators/hero/authentication/templates/config/routes.rb +29 -0
  8. data/lib/generators/hero/authentication/templates/controllers/application_controller.rb +9 -0
  9. data/lib/generators/hero/authentication/templates/controllers/confirmation_controller.rb +80 -0
  10. data/lib/generators/hero/authentication/templates/controllers/sessions_controller.rb +24 -0
  11. data/lib/generators/hero/authentication/templates/controllers/settings_controller.rb +33 -0
  12. data/lib/generators/hero/authentication/templates/controllers/users_controller.rb +32 -0
  13. data/lib/generators/hero/authentication/templates/mailers/confirmation_mailer.rb +30 -0
  14. data/lib/generators/hero/authentication/templates/migrations/20120213162337_create_users.rb +15 -0
  15. data/lib/generators/hero/authentication/templates/models/authentication.rb +33 -0
  16. data/lib/generators/hero/authentication/templates/models/user.rb +144 -0
  17. data/lib/generators/hero/authentication/templates/tests/spec/controllers/sessions_controller_spec.rb +6 -0
  18. data/lib/generators/hero/authentication/templates/tests/spec/controllers/users_controller_spec.rb +6 -0
  19. data/lib/generators/hero/authentication/templates/tests/spec/factories.rb +20 -0
  20. data/lib/generators/hero/authentication/templates/tests/spec/models/user_spec.rb +154 -0
  21. data/lib/generators/hero/authentication/templates/tests/spec/requests/new_email_request_spec.rb +69 -0
  22. data/lib/generators/hero/authentication/templates/tests/spec/requests/password_resets_spec.rb +58 -0
  23. data/lib/generators/hero/authentication/templates/tests/spec/requests/user_confirmation_spec.rb +61 -0
  24. data/lib/generators/hero/authentication/templates/tests/spec/requests/user_sign_in_spec.rb +13 -0
  25. data/lib/generators/hero/authentication/templates/tests/spec/requests/user_sign_up_spec.rb +55 -0
  26. data/lib/generators/hero/authentication/templates/tests/spec/routing/confirmation_mailer_spec.rb +49 -0
  27. data/lib/generators/hero/authentication/templates/tests/spec/spec_helper.rb +34 -0
  28. data/lib/generators/hero/authentication/templates/tests/spec/support/mailer_macros.rb +10 -0
  29. data/lib/generators/hero/authentication/templates/views/confirmation/new_email_token.html.haml +11 -0
  30. data/lib/generators/hero/authentication/templates/views/confirmation/order_new_password.html.haml +11 -0
  31. data/lib/generators/hero/authentication/templates/views/confirmation/password_token.html.haml +11 -0
  32. data/lib/generators/hero/authentication/templates/views/confirmation/recover_password.html.haml +15 -0
  33. data/lib/generators/hero/authentication/templates/views/confirmation/registration.html.haml +10 -0
  34. data/lib/generators/hero/authentication/templates/views/confirmation/resend_signup_token.html.haml +13 -0
  35. data/lib/generators/hero/authentication/templates/views/confirmation/user_email.html.haml +0 -0
  36. data/lib/generators/hero/authentication/templates/views/confirmation_mailer/new_email_request.text.haml +9 -0
  37. data/lib/generators/hero/authentication/templates/views/confirmation_mailer/registration.text.haml +11 -0
  38. data/lib/generators/hero/authentication/templates/views/confirmation_mailer/resend_signup_token.text.haml +11 -0
  39. data/lib/generators/hero/authentication/templates/views/confirmation_mailer/send_password_reset.text.haml +9 -0
  40. data/lib/generators/hero/authentication/templates/views/sessions/new.html.haml +16 -0
  41. data/lib/generators/hero/authentication/templates/views/settings/index.html.haml +28 -0
  42. data/lib/generators/hero/authentication/templates/views/users/new.html.haml +35 -0
  43. data/lib/generators/hero/hero.rb +28 -0
  44. data/lib/hero_generator/engine.rb +6 -0
  45. data/lib/hero_generator/version.rb +1 -1
  46. metadata +53 -11
  47. data/.gitignore +0 -4
  48. data/hero_generator.gemspec +0 -28
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate hero_authentication Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,107 @@
1
+ require 'generators/nifty'
2
+ #require 'rails/generators/migration'
3
+
4
+ module Hero
5
+ module Generators
6
+ class AuthenticationGenerator < Rails::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ attr_accessor :user_name, :session_name
10
+
11
+ argument :user_name, :type => :string, :default => "user"
12
+ argument :session_name, :type => :string, :default => "session"
13
+
14
+
15
+ def copy_files
16
+ template "models/user.rb", "app/models/#{user_singular_name}.rb"
17
+ template "models/authentication.rb", "app/models/authentication.rb"
18
+
19
+ template "controllers/users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb"
20
+ template "controllers/settings_controller.rb", "app/controllers/settings_controller.rb"
21
+ template "controllers/sessions_controller.rb", "app/controllers/sessions_controller.rb"
22
+ template "controllers/confirmation_controller.rb", "app/controllers/confirmation_controller.rb"
23
+ template "controllers/application_controller.rb", "app/controllers/application_controller.rb"
24
+
25
+ template "mailers/confirmation_mailer.rb", "app/mailers/confirmation_mailer.rb"
26
+
27
+ template "views/confirmation/new_email_token.html.haml", "app/views/confirmation/new_email_token.html.haml"
28
+ template "views/confirmation/order_new_password.html.haml", "app/views/confirmation/order_new_password.html.haml"
29
+ template "views/confirmation/password_token.html.haml", "app/views/confirmation/password_token.html.haml"
30
+ template "views/confirmation/recover_password.html.haml", "app/views/confirmation/recover_password.html.haml"
31
+ template "views/confirmation/registration.html.haml", "app/views/confirmation/registration.html.haml"
32
+ template "views/confirmation/resend_signup_token.html.haml", "app/views/confirmation/resend_signup_token.html.haml"
33
+ template "views/confirmation/user_email.html.haml", "app/views/confirmation/user_email.html.haml"
34
+
35
+ template "views/confirmation_mailer/new_email_request.text.haml", "app/views/confirmation_mailer/new_email_request.text.haml"
36
+ template "views/confirmation_mailer/registration.text.haml", "app/views/confirmation_mailer/registration.text.haml"
37
+ template "views/confirmation_mailer/resend_signup_token.text.haml", "app/views/confirmation_mailer/resend_signup_token.text.haml"
38
+ template "views/confirmation_mailer/send_password_reset.text.haml", "app/views/confirmation_mailer/send_password_reset.text.haml"
39
+
40
+ template "views/sessions/new.html.haml", "app/views/sessions/new.html.haml"
41
+ template "views/settings/index.html.haml", "app/views/settings/index.html.haml"
42
+ template "views/users/new.html.haml", "app/views/users/new.html.haml"
43
+
44
+ # config, migrations & initializer
45
+ template "config/config.yml", "config/config.yml"
46
+ template "config/initializers/action_mailer.rb", "config/initializers/action_mailer.rb"
47
+ template "config/initializers/load_config.rb", "config/initializers/load_config.rb"
48
+ template "migrations/20120213162337_create_users.rb", "db/migrate/20120213162337_create_users.rb"
49
+ template "config/routes.rb", "config/routes.rb"
50
+ template "config/locales/en.yml", "config/locales/en.yml"
51
+
52
+ # tests
53
+ template "tests/spec/controllers/sessions_controller_spec.rb", "spec/controllers/sessions_controller_spec.rb"
54
+ template "tests/spec/controllers/users_controller_spec.rb", "spec/controllers/users_controller_spec.rb"
55
+
56
+ template "tests/spec/models/user_spec.rb", "spec/models/user_spec.rb"
57
+ template "tests/spec/requests/new_email_request_spec.rb", "spec/requests/new_email_request_spec.rb"
58
+ template "tests/spec/requests/password_resets_spec.rb", "spec/requests/password_resets_spec.rb"
59
+ template "tests/spec/requests/user_confirmation_spec.rb", "spec/requests/user_confirmation_spec.rb"
60
+ template "tests/spec/requests/user_sign_in_spec.rb", "spec/requests/user_sign_in_spec.rb"
61
+ template "tests/spec/requests/user_sign_up_spec.rb", "spec/requests/user_sign_up_spec.rb"
62
+
63
+ template "tests/spec/routing/confirmation_mailer_spec.rb", "spec/routing/confirmation_mailer_spec.rb"
64
+
65
+ template "tests/spec/support/mailer_macros.rb", "spec/support/mailer_macros.rb"
66
+
67
+ template "tests/spec/factories.rb", "spec/factories.rb"
68
+ template "tests/spec/spec_helper.rb", "spec/spec_helper.rb"
69
+ end
70
+
71
+
72
+ private
73
+
74
+ def user_singular_name
75
+ user_name.underscore
76
+ end
77
+
78
+ def user_plural_name
79
+ user_singular_name.pluralize
80
+ end
81
+
82
+ def user_class_name
83
+ user_name.camelize
84
+ end
85
+
86
+ def user_plural_class_name
87
+ user_plural_name.camelize
88
+ end
89
+
90
+ def session_singular_name
91
+ session_name.underscore
92
+ end
93
+
94
+ def session_plural_name
95
+ session_singular_name.pluralize
96
+ end
97
+
98
+ def session_class_name
99
+ session_name.camelize
100
+ end
101
+
102
+ def session_plural_class_name
103
+ session_plural_name.camelize
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,22 @@
1
+
2
+ const: &const
3
+
4
+ mailers: &mailers
5
+ registration_mailer: &mailconfig
6
+ from: "outbox@projekt.wm2011.boyke.de"
7
+
8
+ development: &development
9
+ <<: *const
10
+ <<: *mailers
11
+
12
+
13
+ test:
14
+ <<: *development
15
+
16
+ cucumber:
17
+ <<: *development
18
+
19
+ production:
20
+ <<: *const
21
+ <<: *mailers
22
+
@@ -0,0 +1,60 @@
1
+ # Email settings
2
+
3
+ if Rails.env == "production"
4
+ ActionMailer::Base.delivery_method = :smtp
5
+ ActionMailer::Base.raise_delivery_errors = true
6
+ ActionMailer::Base.perform_deliveries = true
7
+ ActionMailer::Base.smtp_settings = {
8
+ :address => "smtp.1und1.de",
9
+ :port => 25,
10
+ :domain => 'projekt1.wm2011.boyke.de',
11
+ :authentication => :plain,
12
+ :enable_starttls_auto => true,
13
+ :user_name => "outbox@projekt.wm2011.boyke.de",
14
+ :password => "xwm2011x"
15
+ }
16
+ end
17
+
18
+ if Rails.env == "development"
19
+ ActionMailer::Base.delivery_method = :smtp
20
+ ActionMailer::Base.raise_delivery_errors = true
21
+ ActionMailer::Base.perform_deliveries = false
22
+ ActionMailer::Base.smtp_settings = {
23
+ :address => "smtp.1und1.de",
24
+ :port => 25,
25
+ :domain => 'projekt2.wm2011.boyke.de',
26
+ :authentication => :plain,
27
+ :enable_starttls_auto => true,
28
+ :user_name => "outbox@projekt.wm2011.boyke.de",
29
+ :password => "xwm2011x"
30
+ }
31
+ end
32
+
33
+ if Rails.env == "test"
34
+ ActionMailer::Base.perform_deliveries = true
35
+ ActionMailer::Base.smtp_settings = {
36
+ :openssl_verify_mode => 'none'
37
+ }
38
+ end
39
+
40
+ if ActionMailer::Base.delivery_method == :smtp and ActionMailer::Base.smtp_settings.has_key?(:pop3_auth)
41
+ class ActionMailer::Base
42
+ alias_method :base_perform_delivery_smtp, :perform_delivery_smtp
43
+ @@pop3_auth_done = nil
44
+
45
+ private
46
+
47
+ def perform_delivery_smtp(mail)
48
+ do_pop_auth if !@@pop3_auth_done or (Time.now - smtp_settings[:pop3_auth][:expires]) >= @@pop3_auth_done
49
+ base_perform_delivery_smtp(mail)
50
+ end
51
+
52
+ def do_pop_auth
53
+ require 'net/pop'
54
+ pop = Net::POP3.new(smtp_settings[:pop3_auth][:server])
55
+ pop.start(smtp_settings[:pop3_auth][:user_name], smtp_settings[:pop3_auth][:password])
56
+ @@pop3_auth_done = Time.now
57
+ pop.finish
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ YAML::ENGINE.yamler = "syck" # http://crohr.me/2011/02/23/issue-with-ruby1.9.2-yaml-parser-and-merge-keys-in-yaml-configuration-file.html
2
+ APP_CONFIG = YAML.load_file("#{Rails.root.to_s}/config/config.yml")[Rails.env]
3
+
@@ -0,0 +1,52 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ fe:
6
+ common:
7
+ button:
8
+ send: 'Send'
9
+ user:
10
+ new:
11
+ title: 'Register'
12
+ label_email: 'Email'
13
+ label_password: 'Password'
14
+ label_password_confirmation: 'Password Confirmation'
15
+ create:
16
+ flash:
17
+ success: "Ihnen wurde eine Mail geschickt"
18
+ error: "Fehler in der Eingabe"
19
+
20
+ session:
21
+ new:
22
+ title: 'Login'
23
+ label_email: 'Email'
24
+ label_password: 'Password'
25
+ create:
26
+ flash:
27
+ success: "Eingeloggt, hurra!"
28
+ error:
29
+ not_confirmed: "Bitte erst die Registrierung bestätigen."
30
+ wrong_password_or_email: "Falsche Mail oder Password"
31
+
32
+
33
+ confirmation:
34
+ order_new_password:
35
+ flash:
36
+ success: 'Es wurde eine Email mit Passwort versendet'
37
+ registration:
38
+ flash:
39
+ success: 'Endlich richtig dabei.'
40
+ error: 'falscher token'
41
+ resend_signup_token:
42
+ flash:
43
+ success: "Token wurde nochmal gesendet"
44
+ error: "Sie sind schon freigeschaltet. Was soll das?"
45
+
46
+ confirmation_mailer:
47
+ send_password_reset:
48
+ subject: 'Neues Passwort angefordert'
49
+ registration:
50
+ subject: 'Bitte Anmeldung bestätigen'
51
+ resend_signup_token:
52
+ subject: 'Neuer Registrierungstoken'
@@ -0,0 +1,29 @@
1
+ Wrkplc::Application.routes.draw do
2
+ default_url_options :host => "localhost:3000"
3
+
4
+ get "log_out" => "sessions#destroy", :as => "log_out"
5
+ get "registrieren" => "users#new", :as => "sign_up_form"
6
+ post "sign_up" => "users#create", :as => "sign_up"
7
+
8
+ match 'confirm/resend_confirmation' => "confirmation#resend_signup_token", :as => 'resend_signup_token'
9
+ match 'confirm/:action(/:token)', :controller => :confirmation, :as => 'confirm'
10
+
11
+
12
+ match "log_in" => "sessions#new", :as => "log_in", :via => :get
13
+ match "log_in" => "sessions#create", :as => "log_in", :via => :post
14
+
15
+ get 'recover_password_auth(/:token)' => "confirmation#recover_password_auth", :as => 'recover_password_auth'
16
+ match 'recover_password(/:token)' => "confirmation#recover_password", :as => 'recover_password'
17
+
18
+ match 'new_email(/:token)' => "confirmation#new_email", :as => 'new_email'
19
+
20
+ match 'request_password' => "confirmation#order_new_password", :as => 'order_new_password'
21
+
22
+ match 'notice' => 'application#notice', :as => 'notice'
23
+
24
+ root :to => "users#new"
25
+
26
+ resources :users
27
+ resources :sessions
28
+ match '/:controller(/:action(/:id))'
29
+ end
@@ -0,0 +1,9 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ include Authentication
4
+
5
+ def notice
6
+ # left empty on purpose
7
+ end
8
+
9
+ end
@@ -0,0 +1,80 @@
1
+ class ConfirmationController < ApplicationController
2
+
3
+ def registration
4
+ @user = User.where( :signup_token => params[:token] ).first unless params[:token].nil?
5
+
6
+ if @user
7
+ @user.confirm_signup!
8
+ redirect_to log_in_path, :notice => t( 'fe.confirmation.registration.flash.success' )
9
+ end
10
+
11
+ flash[:error] = t( 'fe.confirmation.registration.flash.error') if params[:token]
12
+ end
13
+
14
+ def resend_signup_token
15
+ @user = User.authenticate( params[:email], params[:password] )
16
+ if @user
17
+ if @user.resend_signup_token
18
+ flash[:notice] = t( 'fe.confirmation.resend_signup_token.flash.success' )
19
+ else
20
+ flash[:notice] = t( 'fe.confirmation.resend_signup_token.flash.error' )
21
+ end
22
+ redirect_to log_in_path
23
+ end
24
+ end
25
+
26
+ def order_new_password
27
+ if params[:email]
28
+ @user = User.where( :email => params[:email] ).first
29
+ if @user && @user.send_password_reset
30
+ flash[:notice] = t( 'fe.confirmation.order_new_password.flash.success' )
31
+ end
32
+ redirect_to root_path
33
+ end
34
+ end
35
+
36
+ #
37
+ # Aufruf des Links, der in der E-Mail steht, wenn man ein neues Passwort anfordert
38
+ #
39
+
40
+ def recover_password_auth
41
+ @user = User.find_by_password_token( params[:token] ) unless params[:token].nil?
42
+ render @user ? :recover_password : :password_token
43
+ end
44
+
45
+
46
+ def recover_password
47
+ @token = params[:token]
48
+ @user = User.find_by_password_token( params[:token] ) unless params[:token].nil?
49
+
50
+ if @user
51
+ if !params[:recover_password].nil? && params[:recover_password_confirmation] == params[:recover_password]
52
+ if @user.confirm_password!(params[:recover_password])
53
+ redirect_to( log_in_path, :notice => t( 'fe.confirmation.recover_password.flash_success' ))
54
+ else
55
+ flash.now[:notice] = t( 'fe.confirmation.recover_password.flash_error' )
56
+ end
57
+ end
58
+ else
59
+ redirect_to recover_password_auth_path
60
+ end
61
+ end
62
+
63
+
64
+ def new_email
65
+ @user = User.find_by_new_email_token( params[:token] ) unless params[:token].nil?
66
+ if @user
67
+ if @user.confirm_new_email!
68
+ redirect_to( log_in_path, :notice => t( 'fe.confirmation.new_email.flash_success' ))
69
+ else
70
+ flash[:notice] = t( 'fe.confirmation.new_email.flash_error' )
71
+ end
72
+ else
73
+ render :new_email_token
74
+ end
75
+ end
76
+
77
+
78
+
79
+
80
+ end
@@ -0,0 +1,24 @@
1
+ class SessionsController < ApplicationController
2
+ def new
3
+ end
4
+
5
+ def create
6
+ @user = User.authenticate(params[:email], params[:password])
7
+ if @user
8
+ if @user.confirmed?
9
+ session[:user_id] = @user.id
10
+ redirect_to root_url, :notice => t( 'fe.session.create.flash.success' )
11
+ else
12
+ redirect_to confirm_path( :action => "registration" ), :notice => t( 'fe.session.create.flash.error.not_confirmed' )
13
+ end
14
+ else
15
+ flash.now.alert = t( 'fe.session.create.flash.error.wrong_password_or_email' )
16
+ render :new
17
+ end
18
+ end
19
+
20
+ def destroy
21
+ session[:user_id] = nil
22
+ redirect_to root_url, :notice => 'ausgeloggt'
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ class SettingsController < ApplicationController
2
+
3
+ def index
4
+ @user = User.new
5
+ end
6
+
7
+ def change_user_email
8
+ email_updated = false
9
+ @user = current_user
10
+
11
+ flash.now[:notice] = t( 'fe.settings.change_user_email.flash_error' )
12
+
13
+ if User.authenticate( current_user.email, params[:user][:password] )
14
+ current_user.set_new_email = true
15
+ current_user.new_email = params[:user][:new_email]
16
+ current_user.new_email_confirmation = params[:user][:new_email_confirmation]
17
+ if current_user.send_new_email( params[:user][:new_email] )
18
+ email_updated = true
19
+ end
20
+ else
21
+ flash.now[:notice] = t( "fe.settings.update_email.flash.error.wrong_password" )
22
+ end
23
+
24
+ if email_updated
25
+ flash.now[:notice] = t( "fe.settings.update_email.flash.success" )
26
+ redirect_to "/settings"
27
+ else
28
+ render :index
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,32 @@
1
+ class UsersController < ApplicationController
2
+
3
+ def new
4
+ @user = User.new
5
+ end
6
+
7
+ def create
8
+ @user = User.new(params[:user])
9
+
10
+ # password(_confirmation) removed from mass assignment
11
+ @user.password = params[:user][:password]
12
+ @user.password_confirmation = params[:user][:password_confirmation]
13
+
14
+ if @user.save
15
+ redirect_to root_url, :notice => t( 'fe.user.create.flash.success' )
16
+ @user.send_registration
17
+ else
18
+ flash.now[:error] = t( 'fe.user.create.flash.error' )
19
+ render :new
20
+ end
21
+ end
22
+
23
+
24
+ end
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
@@ -0,0 +1,30 @@
1
+ class ConfirmationMailer < ActionMailer::Base
2
+
3
+ helper :application
4
+
5
+ default :from => APP_CONFIG['registration_mailer']['from']
6
+
7
+ def registration( user )
8
+ @user = user
9
+ @confirmation_url = confirm_url( user.signup_token )
10
+ mail( :to => user.email, :subject => t( 'confirmation_mailer.registration.subject' ))
11
+ end
12
+
13
+ def resend_signup_token( user )
14
+ @user = user
15
+ @confirmation_url = confirm_url( :registration, @user.signup_token )
16
+ mail( :to => user.email, :subject => t( 'confirmation_mailer.resend_signup_token.subject' ))
17
+ end
18
+
19
+ def send_password_reset( user )
20
+ @confirmation_url = recover_password_url( user.password_token )
21
+ mail( :to => user.email, :subject => t( 'confirmation_mailer.send_password_reset.subject' ))
22
+ end
23
+
24
+ def new_email_request( user )
25
+ @user = user
26
+ @confirmation_url = new_email_url( @user.new_email_token )
27
+ mail( :to => @user.new_email, :subject => t( 'confirmation_mailer.new_email_request.subject' ))
28
+ end
29
+ end
30
+
@@ -0,0 +1,15 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :email
5
+ t.string :password_hash
6
+ t.string :password_salt
7
+ t.string :signup_token
8
+ t.string :password_token
9
+ t.string :new_email
10
+ t.string :new_email_token
11
+ t.datetime :confirmed, :null => true
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ # This module is included in your application controller which makes
2
+ # several methods available to all controllers and views. Here's a
3
+ # common example you might add to your application layout file.
4
+ #
5
+ # user_nav
6
+ #
7
+ # - if current_user
8
+ # = "Logged in as #{current_user.email}. "
9
+ # = link_to "Log out", log_out_path
10
+ # - else
11
+ # = link_to "Registrieren", sign_up_form_path
12
+ # = " or "
13
+ # = link_to "Anmelden", log_in_path
14
+ #
15
+ #
16
+ # - [:notice, :error, :success].each do |key|
17
+ # - unless flash[key].blank?
18
+ # %p{ :class => "flash #{key}" }= flash[key]
19
+ #
20
+
21
+ module Authentication
22
+
23
+ def self.included(controller)
24
+ controller.send :helper_method, :current_user
25
+ end
26
+
27
+ def current_user
28
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
29
+ end
30
+
31
+ end
32
+
33
+