lobby 0.0.1a

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 (116) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/lobby/application.js +13 -0
  5. data/app/assets/stylesheets/lobby/application.css +13 -0
  6. data/app/controllers/lobby/application_controller.rb +3 -0
  7. data/app/controllers/lobby/application_controller.rb~ +6 -0
  8. data/app/controllers/lobby/confirmation_controller.rb +46 -0
  9. data/app/controllers/lobby/confirmation_controller.rb~ +44 -0
  10. data/app/controllers/lobby/password_forgotten_controller.rb +48 -0
  11. data/app/controllers/lobby/password_forgotten_controller.rb~ +48 -0
  12. data/app/controllers/lobby/sessions_controller.rb +33 -0
  13. data/app/controllers/lobby/sessions_controller.rb~ +33 -0
  14. data/app/controllers/lobby/users_controller.rb +23 -0
  15. data/app/controllers/lobby/users_controller.rb~ +23 -0
  16. data/app/forms/password_forgotten_form.rb +5 -0
  17. data/app/forms/password_forgotten_form.rb~ +5 -0
  18. data/app/helpers/lobby/application_helper.rb +4 -0
  19. data/app/mailers/confirmation_mailer.rb +30 -0
  20. data/app/mailers/confirmation_mailer.rb~ +28 -0
  21. data/app/models/auth_user.rb~ +100 -0
  22. data/app/models/authentication.rb~ +13 -0
  23. data/app/models/lobby/auth_user.rb +100 -0
  24. data/app/models/lobby/auth_user.rb~ +100 -0
  25. data/app/models/lobby/authentication.rb +13 -0
  26. data/app/models/lobby/password_forgotten_form_abstract.rb +47 -0
  27. data/app/models/password_forgotten_form_abstract.rb~ +45 -0
  28. data/app/views/layouts/lobby/application.html.erb +14 -0
  29. data/app/views/sessions/new.html.haml +19 -0
  30. data/app/views/sessions/new.html.haml~ +0 -0
  31. data/config/locales/de.yml +529 -0
  32. data/config/locales/de.yml~ +529 -0
  33. data/config/locales/en.bootstrap.yml +18 -0
  34. data/config/locales/en.yml +532 -0
  35. data/config/locales/en.yml~ +530 -0
  36. data/config/routes.rb +21 -0
  37. data/config/routes.rb~ +23 -0
  38. data/db/migrate/20131205180849_create_users.rb +16 -0
  39. data/db/migrate/20131205180849_create_users.rb~ +16 -0
  40. data/lib/lobby/engine.rb +7 -0
  41. data/lib/lobby/engine.rb~ +5 -0
  42. data/lib/lobby/version.rb +3 -0
  43. data/lib/lobby/version.rb~ +3 -0
  44. data/lib/lobby.rb +4 -0
  45. data/lib/tasks/lobby_tasks.rake +4 -0
  46. data/test/dummy/README.rdoc +28 -0
  47. data/test/dummy/Rakefile +6 -0
  48. data/test/dummy/app/assets/javascripts/application.js +13 -0
  49. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  50. data/test/dummy/app/controllers/application_controller.rb +6 -0
  51. data/test/dummy/app/controllers/application_controller.rb~ +5 -0
  52. data/test/dummy/app/helpers/application_helper.rb +2 -0
  53. data/test/dummy/app/models/user.rb +30 -0
  54. data/test/dummy/app/models/user.rb~ +30 -0
  55. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  56. data/test/dummy/app/views/lobby/common/_form_errors.html.haml +6 -0
  57. data/test/dummy/app/views/lobby/confirmation/new_email_token.html.haml +10 -0
  58. data/test/dummy/app/views/lobby/confirmation/registration.html.haml +15 -0
  59. data/test/dummy/app/views/lobby/confirmation/registration.html.haml~ +15 -0
  60. data/test/dummy/app/views/lobby/confirmation/resend_signup_token.html.haml +17 -0
  61. data/test/dummy/app/views/lobby/confirmation/resend_signup_token.html.haml~ +17 -0
  62. data/test/dummy/app/views/lobby/confirmation/user_email.html.haml +0 -0
  63. data/test/dummy/app/views/lobby/confirmation_mailer/new_email_request.text.haml +1 -0
  64. data/test/dummy/app/views/lobby/confirmation_mailer/registration.text.haml +1 -0
  65. data/test/dummy/app/views/lobby/confirmation_mailer/resend_signup_token.text.haml +1 -0
  66. data/test/dummy/app/views/lobby/confirmation_mailer/send_password_reset.text.haml +1 -0
  67. data/test/dummy/app/views/lobby/password_forgotten/new.html.haml +21 -0
  68. data/test/dummy/app/views/lobby/password_forgotten/new.html.haml~ +21 -0
  69. data/test/dummy/app/views/lobby/password_forgotten/order_new_password.html.haml +13 -0
  70. data/test/dummy/app/views/lobby/password_forgotten/order_new_password.html.haml~ +13 -0
  71. data/test/dummy/app/views/lobby/password_forgotten/recover_password_auth.html.haml +9 -0
  72. data/test/dummy/app/views/lobby/sessions/new.html.haml +12 -0
  73. data/test/dummy/app/views/lobby/sessions/new.html.haml~ +12 -0
  74. data/test/dummy/app/views/lobby/users/new.html.haml +20 -0
  75. data/test/dummy/app/views/lobby/users/new.html.haml~ +20 -0
  76. data/test/dummy/bin/bundle +3 -0
  77. data/test/dummy/bin/rails +4 -0
  78. data/test/dummy/bin/rake +4 -0
  79. data/test/dummy/config/app_config.yml +31 -0
  80. data/test/dummy/config/application.rb +23 -0
  81. data/test/dummy/config/boot.rb +5 -0
  82. data/test/dummy/config/database.yml +25 -0
  83. data/test/dummy/config/environment.rb +5 -0
  84. data/test/dummy/config/environments/development.rb +29 -0
  85. data/test/dummy/config/environments/production.rb +80 -0
  86. data/test/dummy/config/environments/test.rb +36 -0
  87. data/test/dummy/config/initializers/action_mailer.rb +75 -0
  88. data/test/dummy/config/initializers/action_mailer.rb~ +75 -0
  89. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  90. data/test/dummy/config/initializers/constants.rb +1 -0
  91. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  92. data/test/dummy/config/initializers/inflections.rb +16 -0
  93. data/test/dummy/config/initializers/load_app_config.rb +3 -0
  94. data/test/dummy/config/initializers/mime_types.rb +5 -0
  95. data/test/dummy/config/initializers/secret_token.rb +12 -0
  96. data/test/dummy/config/initializers/session_store.rb +3 -0
  97. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  98. data/test/dummy/config/locales/en.yml +23 -0
  99. data/test/dummy/config/routes.rb +4 -0
  100. data/test/dummy/config.ru +4 -0
  101. data/test/dummy/db/development.sqlite3 +0 -0
  102. data/test/dummy/log/development.log +10657 -0
  103. data/test/dummy/public/404.html +58 -0
  104. data/test/dummy/public/422.html +58 -0
  105. data/test/dummy/public/500.html +57 -0
  106. data/test/dummy/public/favicon.ico +0 -0
  107. data/test/dummy/tmp/cache/assets/development/sprockets/14bc37f3a9c398f6798dd6a37b000ced +0 -0
  108. data/test/dummy/tmp/cache/assets/development/sprockets/940a306c051fc9ecf6ca85c072fac574 +0 -0
  109. data/test/dummy/tmp/cache/assets/development/sprockets/959f475481f39907c5c22136d3ad0b02 +0 -0
  110. data/test/dummy/tmp/cache/assets/development/sprockets/c4adbd06827a23aa54492fb7cb615529 +0 -0
  111. data/test/dummy/tmp/cache/assets/development/sprockets/c615a56268b779cf1f55f9134c8ae04e +0 -0
  112. data/test/dummy/tmp/cache/assets/development/sprockets/e4cc9c240851fac0c22ef37d0ee2fb62 +0 -0
  113. data/test/integration/navigation_test.rb +10 -0
  114. data/test/lobby_test.rb +7 -0
  115. data/test/test_helper.rb +15 -0
  116. metadata +294 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Lobby
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Lobby'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,3 @@
1
+ class Lobby::ApplicationController < ApplicationController
2
+
3
+ end
@@ -0,0 +1,6 @@
1
+ module Lobby
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery
4
+ include Authentication
5
+ end
6
+ end
@@ -0,0 +1,46 @@
1
+ module Lobby
2
+ class ConfirmationController < ApplicationController
3
+
4
+ def registration
5
+ @user = User.where( :signup_token => params[:token] ).first unless params[:token].nil?
6
+
7
+ if @user
8
+ @user.confirm_signup!
9
+ redirect_to log_in_url, flash: { success: t( 'confirmation.registration.flash.success' ) }
10
+ else
11
+ flash.now[:notice] = t( 'confirmation.registration.flash.error') if params[:token]
12
+ end
13
+ end
14
+
15
+ #
16
+ # User has lost email with signup token. we send this email again.
17
+ #
18
+
19
+ def resend_signup_token
20
+ flash[:notice] = nil
21
+ @user = User.find_by_email(params[:email])
22
+ if @user && @user.authenticate(params[:password])
23
+ if @user.resend_signup_token
24
+ redirect_to log_in_url, flash: { success: t( 'confirmation.resend_signup_token.flash.success' ) }
25
+ else
26
+ redirect_to log_in_url, flash: { danger: t( 'confirmation.resend_signup_token.flash.error' ) }
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ def new_email
33
+ @user = User.find_by_new_email_token( params[:token] ) unless params[:token].nil?
34
+ if @user
35
+ if @user.confirm_new_email!
36
+ redirect_to( root_url, :notice => t( '.flash.success' ))
37
+ else
38
+ flash[:notice] = t( '.flash.error' )
39
+ end
40
+ else
41
+ render :new_email_token
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,44 @@
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_url, flash: { success: t( 'confirmation.registration.flash.success' ) }
9
+ else
10
+ flash.now[:notice] = t( 'confirmation.registration.flash.error') if params[:token]
11
+ end
12
+ end
13
+
14
+ #
15
+ # User has lost email with signup token. we send this email again.
16
+ #
17
+
18
+ def resend_signup_token
19
+ flash[:notice] = nil
20
+ @user = User.find_by_email(params[:email])
21
+ if @user && @user.authenticate(params[:password])
22
+ if @user.resend_signup_token
23
+ redirect_to log_in_url, flash: { success: t( 'confirmation.resend_signup_token.flash.success' ) }
24
+ else
25
+ redirect_to log_in_url, flash: { danger: t( 'confirmation.resend_signup_token.flash.error' ) }
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ def new_email
32
+ @user = User.find_by_new_email_token( params[:token] ) unless params[:token].nil?
33
+ if @user
34
+ if @user.confirm_new_email!
35
+ redirect_to( root_url, :notice => t( '.flash.success' ))
36
+ else
37
+ flash[:notice] = t( '.flash.error' )
38
+ end
39
+ else
40
+ render :new_email_token
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,48 @@
1
+ module Lobby
2
+ class PasswordForgottenController < ApplicationController
3
+
4
+ before_action :check_token, only: [:new, :create]
5
+
6
+ def new
7
+ end
8
+
9
+ def create
10
+ if @password_forgotten_form.submit(password_forgotten_form_params)
11
+ flash[:success] = t('.notice.success')
12
+ redirect_to log_in_url
13
+ else
14
+ render "new"
15
+ end
16
+ end
17
+
18
+ def order_new_password
19
+ if params[:email]
20
+ @user = User.where( :email => params[:email] ).first
21
+ if @user && @user.send_password_reset
22
+ # nothing special. Send always the same notice. so you can prevent from e-mail-guessing.
23
+ else
24
+ puts "*******************************"
25
+ puts "An non-existing email was given"
26
+ puts "*******************************"
27
+ end
28
+ flash[:success] = t( '.flash.success' )
29
+ redirect_to log_in_url
30
+ end
31
+ end
32
+
33
+
34
+ def check_token
35
+ @token = params[:token]
36
+ @password_forgotten_form = PasswordForgottenForm.new(@token)
37
+
38
+ if @password_forgotten_form.user.blank?
39
+ render :recover_password_auth
40
+ false
41
+ end
42
+ end
43
+
44
+ def password_forgotten_form_params
45
+ params.require(:password_forgotten_form).permit(:new_password, :new_password_confirmation)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ module Lobby
2
+ class PasswordForgottenController < ApplicationController
3
+
4
+ before_action :check_token, only: [:new, :create]
5
+
6
+ def new
7
+ end
8
+
9
+ def create
10
+ if @password_forgotten_form.submit(password_forgotten_form_params)
11
+ flash[:success] = t('.notice.success')
12
+ redirect_to log_in_url
13
+ else
14
+ render "new"
15
+ end
16
+ end
17
+
18
+ def order_new_password
19
+ if params[:email]
20
+ @user = User.where( :email => params[:email] ).first
21
+ if @user && @user.send_password_reset
22
+ # nothing special. Send always the same notice. so you can prevent from e-mail-guessing.
23
+ else
24
+ puts "*******************************"
25
+ puts "An non-existing email was given"
26
+ puts "*******************************"
27
+ end
28
+ flash[:success] = t( '.flash.success' )
29
+ redirect_to log_in_url
30
+ end
31
+ end
32
+
33
+
34
+ def check_token
35
+ @token = params[:token]
36
+ @password_forgotten_form = Lobby::PasswordForgottenForm.new(@token)
37
+
38
+ if @password_forgotten_form.user.blank?
39
+ render :recover_password_auth
40
+ false
41
+ end
42
+ end
43
+
44
+ def password_forgotten_form_params
45
+ params.require(:password_forgotten_form).permit(:new_password, :new_password_confirmation)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,33 @@
1
+ module Lobby
2
+ class SessionsController < ApplicationController
3
+ def new
4
+ end
5
+
6
+ def create
7
+ @user = User.where('email = ? OR username = ?', params[:email], params[:email]).first
8
+ if @user && @user.authenticate(params[:password])
9
+ if @user.confirmed?
10
+ if @user.active?
11
+ session[:user_id] = @user.id
12
+ flash.now[:success] = t( 'sessions.create.flash.success' )
13
+ redirect_to root_url
14
+ else
15
+ flash.now[:danger] = t( 'sessions.create.flash.error.not_active' )
16
+ redirect_to log_in_url
17
+ end
18
+ else
19
+ flash.now[:danger] = t( 'sessions.create.flash.error.not_confirmed' )
20
+ redirect_to confirm_url( :action => "registration" )
21
+ end
22
+ else
23
+ flash.now[:danger] = t( 'sessions.create.flash.error.wrong_password_or_email' )
24
+ render :new
25
+ end
26
+ end
27
+
28
+ def destroy
29
+ session[:user_id] = nil
30
+ redirect_to root_url, flash: {success: t( 'sessions.destroy.success' ) }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module Lobby
2
+ class SessionsController < ApplicationController
3
+ def new
4
+ end
5
+
6
+ def create
7
+ @user = User.where('email = ? OR username = ?', params[:email], params[:email]).first
8
+ if @user && @user.authenticate(params[:password])
9
+ if @user.confirmed?
10
+ if @user.active?
11
+ session[:user_id] = @user.id
12
+ flash.now[:success] = t( 'sessions.create.flash.success' )
13
+ redirect_to root_url
14
+ else
15
+ flash.now[:danger] = t( 'sessions.create.flash.error.not_active' )
16
+ redirect_to log_in_url
17
+ end
18
+ else
19
+ flash.now[:danger] = t( 'sessions.create.flash.error.not_confirmed' )
20
+ redirect_to confirm_url( :action => "registration" )
21
+ end
22
+ else
23
+ flash.now[:danger] = t( 'sessions.create.flash.error.wrong_password_or_email' )
24
+ render :new
25
+ end
26
+ end
27
+
28
+ def destroy
29
+ session[:user_id] = nil
30
+ redirect_to root_url, flash: {success: t( 'sessions.destroy.success' ) }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ module Lobby
2
+ class UsersController < ApplicationController
3
+
4
+ def new
5
+ @user = User.new
6
+ end
7
+
8
+ def create
9
+ @user = User.new(user_params)
10
+ if @user.save
11
+ redirect_to log_in_url, flash: {success: t( '.success' ) }
12
+ @user.send_registration
13
+ else
14
+ render :new
15
+ end
16
+ end
17
+
18
+ def user_params
19
+ params.require(:user).permit(:email, :username, :password, :password_confirmation)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Lobby
2
+ class UsersController < ApplicationController
3
+
4
+ def new
5
+ @user = User.new
6
+ end
7
+
8
+ def create
9
+ @user = User.new(user_params)
10
+ if @user.save
11
+ redirect_to log_in_url, flash: {success: t( '.success' ) }
12
+ @user.send_registration
13
+ else
14
+ render :new
15
+ end
16
+ end
17
+
18
+ def user_params
19
+ params.require(:user).permit(:email, :username, :password, :password_confirmation)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Lobby
2
+ class PasswordForgottenForm < PasswordForgottenFormAbstract
3
+ USER_CLASS = "User"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Lobby
2
+ class PasswordForgottenForm < Lobby::PasswordForgottenFormAbstract
3
+ USER_CLASS = "User"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Lobby
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,30 @@
1
+ module Lobby
2
+ class ConfirmationMailer < ActionMailer::Base
3
+
4
+ helper :application
5
+
6
+ default :from => APP_CONFIG['registration_mailer']['from']
7
+
8
+ def registration( user )
9
+ @confirmation_url = confirm_url( :registration, 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_form_url( :token => 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
+ end
@@ -0,0 +1,28 @@
1
+ class ConfirmationMailer < ActionMailer::Base
2
+
3
+ helper :application
4
+
5
+ default :from => APP_CONFIG['registration_mailer']['from']
6
+
7
+ def registration( user )
8
+ @confirmation_url = confirm_url( :registration, user.signup_token )
9
+ mail( :to => user.email, :subject => t( 'confirmation_mailer.registration.subject' ))
10
+ end
11
+
12
+ def resend_signup_token( user )
13
+ @user = user
14
+ @confirmation_url = confirm_url( :registration, @user.signup_token )
15
+ mail( :to => user.email, :subject => t( 'confirmation_mailer.resend_signup_token.subject' ))
16
+ end
17
+
18
+ def send_password_reset( user )
19
+ @confirmation_url = recover_password_form_url( :token => user.password_token )
20
+ mail( :to => user.email, :subject => t( 'confirmation_mailer.send_password_reset.subject' ))
21
+ end
22
+
23
+ def new_email_request( user )
24
+ @user = user
25
+ @confirmation_url = new_email_url( @user.new_email_token )
26
+ mail( :to => @user.new_email, :subject => t( 'confirmation_mailer.new_email_request.subject' ))
27
+ end
28
+ end
@@ -0,0 +1,100 @@
1
+ module Lobby
2
+ module AuthUser
3
+
4
+ def self.included(base)
5
+ base.has_secure_password
6
+
7
+ base.validates :email, presence: true
8
+ base.validates :email, format: {with: EMAIL_REGEX, multiline: true}, if: Proc.new { |u| u.email.present? }
9
+ base.validates :email, uniqueness: true, :unless => :confirmed_duplicate, :on => :create, if: Proc.new { |u| u.email.present? }
10
+ base.validates :password, length: { minimum: 5 }, :on => :create, if: Proc.new { |u| u.password.present? }
11
+
12
+ base.extend ClassMethods
13
+ end
14
+
15
+
16
+ module ClassMethods
17
+ def confirmed
18
+ where("confirmed IS NOT NULL")
19
+ end
20
+
21
+ def with_email(email)
22
+ where(:email => email)
23
+ end
24
+
25
+ end
26
+
27
+
28
+ def confirmed_duplicate(test_mail = self.email)
29
+ if ((self.class.name.constantize.confirmed.with_email(test_mail).count == 0) ||
30
+ (self.class.name.constantize.with_email(test_mail).count == 0))
31
+ true
32
+ else
33
+ #self.id = self.class.name.constantize.confirmed.with_email(test_mail).first.id
34
+ false
35
+ end
36
+ end
37
+
38
+ def confirm_signup!
39
+ update_attribute(:confirmed, Time.now)
40
+ update_attribute(:signup_token, nil)
41
+ update_attribute(:active, true)
42
+ end
43
+
44
+ def confirm_new_email!
45
+ update_attribute(:email, new_email)
46
+ update_attribute(:new_email_token, nil)
47
+ end
48
+
49
+ def confirmed?
50
+ !self.confirmed.nil?
51
+ end
52
+
53
+ def active?
54
+ self.active == true
55
+ end
56
+
57
+ # Wenn der User sich registriert, dann wird ein signup_token für ihn hinterlegt.
58
+ # Dieser Token wird per Mail verschickt. Der User kann sich nun per Klick auf den
59
+ # Tokenlink verifizieren. Sollte die Mail nicht mehr erreichbar sein, so kann der User
60
+ # unter Angabe seiner Email einen neuen signup_Token anfordern. Der alte Token ist
61
+ # ab diesem Zeitpunkt ungültig.
62
+
63
+ # Nach erfolgreicher Verifizierung der Email-Adresse) wird das
64
+ # Feld confirmed mit einem Datum gefüllt. Ab diesem Zeitpunkt kann keine neuer
65
+ # Confirmation-Token generiert und verschickt werden.
66
+
67
+ def tokenmail(request)
68
+ ConfirmationMailer.send(request, self).deliver
69
+ end
70
+
71
+ def send_password_reset(with_mail = true)
72
+ return unless generate_token(:password_token)
73
+ if with_mail
74
+ tokenmail(:send_password_reset)
75
+ end
76
+ end
77
+
78
+ def send_registration
79
+ return unless generate_token(:signup_token)
80
+ tokenmail(:registration)
81
+ end
82
+
83
+ def resend_signup_token
84
+ return unless (!confirmed? && generate_token(:signup_token))
85
+ tokenmail(:resend_signup_token)
86
+ end
87
+
88
+ def send_new_email_request
89
+ return unless (confirmed? && generate_token(:new_email_token))
90
+ tokenmail(:new_email_request)
91
+ end
92
+
93
+
94
+ private
95
+
96
+ def generate_token( token )
97
+ (defined?( token ) && update_attribute( token, SecureRandom.hex(13) ))? true : false
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,13 @@
1
+ module Lobby
2
+ module Authentication
3
+
4
+ def self.included(controller)
5
+ controller.send :helper_method, :current_user, :auth_with_username?
6
+ end
7
+
8
+ def current_user
9
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
10
+ end
11
+
12
+ end
13
+ end