lobby 0.0.23 → 0.0.24

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.
@@ -2,14 +2,14 @@ module Lobby
2
2
  module AuthUser
3
3
 
4
4
  def self.included(base)
5
- base.has_secure_password
5
+ base.has_secure_password(validations: validate_password?)
6
6
 
7
- base.validates :email, presence: true
7
+ base.validates :email, presence: true, if: :email_required?
8
8
  base.validates :email, format: {with: EMAIL_REGEX, multiline: true}, if: Proc.new { |u| u.email.present? }
9
9
  base.validates :email, uniqueness: true, :unless => :confirmed_duplicate_email, :on => :create, if: Proc.new { |u| u.email.present? }
10
10
  base.validates :password, length: { minimum: 5 }, :on => :create, if: Proc.new { |u| u.password.present? }
11
11
 
12
- base.validates :username, presence: true
12
+ base.validates :username, presence: true, if: :username_required?
13
13
  base.validates :username, uniqueness: true, :unless => :confirmed_duplicate_username, :on => :create
14
14
 
15
15
  base.extend ClassMethods
@@ -97,6 +97,17 @@ module Lobby
97
97
  tokenmail(:resend_signup_token)
98
98
  end
99
99
 
100
+ def validate_password?
101
+ true
102
+ end
103
+
104
+ def email_required?
105
+ true
106
+ end
107
+
108
+ def username_required?
109
+ true
110
+ end
100
111
 
101
112
  private
102
113
 
@@ -0,0 +1,118 @@
1
+ module Lobby
2
+ module AuthUser
3
+
4
+ def self.included(base)
5
+ base.has_secure_password(validations: validate_password?)
6
+
7
+ base.validates :email, presence: true, if: :email_required?
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_email, :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.validates :username, presence: true, if: :username_required?
13
+ base.validates :username, uniqueness: true, :unless => :confirmed_duplicate_username, :on => :create
14
+
15
+ base.extend ClassMethods
16
+ end
17
+
18
+
19
+ module ClassMethods
20
+ def confirmed
21
+ where("confirmed IS NOT NULL")
22
+ end
23
+
24
+ def with_email(email)
25
+ where(:email => email)
26
+ end
27
+
28
+ def with_username(username)
29
+ where(:username => username)
30
+ end
31
+
32
+ end
33
+
34
+
35
+ def confirmed_duplicate_email(test_mail = self.email)
36
+ if ((self.class.name.constantize.confirmed.with_email(test_mail).count == 0) ||
37
+ (self.class.name.constantize.with_email(test_mail).count == 0))
38
+ true
39
+ else
40
+ false
41
+ end
42
+ end
43
+
44
+ def confirm_signup!
45
+ update_attribute(:confirmed, Time.now)
46
+ update_attribute(:signup_token, nil)
47
+ update_attribute(:active, true)
48
+ end
49
+
50
+ def confirmed?
51
+ !self.confirmed.nil?
52
+ end
53
+
54
+ def active?
55
+ self.active == true
56
+ end
57
+
58
+ # attr_accessible :username
59
+
60
+ def confirmed_duplicate_username(test_username = self.username)
61
+ if ((User.confirmed.with_username(test_username).count == 0) ||
62
+ (User.with_username(test_username).count == 0))
63
+ true
64
+ else
65
+ false
66
+ end
67
+ end
68
+
69
+ # Wenn der User sich registriert, dann wird ein signup_token für ihn hinterlegt.
70
+ # Dieser Token wird per Mail verschickt. Der User kann sich nun per Klick auf den
71
+ # Tokenlink verifizieren. Sollte die Mail nicht mehr erreichbar sein, so kann der User
72
+ # unter Angabe seiner Email einen neuen signup_Token anfordern. Der alte Token ist
73
+ # ab diesem Zeitpunkt ungültig.
74
+
75
+ # Nach erfolgreicher Verifizierung der Email-Adresse) wird das
76
+ # Feld confirmed mit einem Datum gefüllt. Ab diesem Zeitpunkt kann keine neuer
77
+ # Confirmation-Token generiert und verschickt werden.
78
+
79
+ def tokenmail(request)
80
+ ConfirmationMailer.send(request, self).deliver
81
+ end
82
+
83
+ def send_password_reset(with_mail = true)
84
+ return unless generate_token(:password_token)
85
+ if with_mail
86
+ tokenmail(:send_password_reset)
87
+ end
88
+ end
89
+
90
+ def send_registration
91
+ return unless generate_token(:signup_token)
92
+ tokenmail(:registration)
93
+ end
94
+
95
+ def resend_signup_token
96
+ return unless (!confirmed? && generate_token(:signup_token))
97
+ tokenmail(:resend_signup_token)
98
+ end
99
+
100
+ def validate_password?
101
+ true
102
+ end
103
+
104
+ def email_required?
105
+ true
106
+ end
107
+
108
+ def username_required?
109
+ true
110
+ end
111
+
112
+ private
113
+
114
+ def generate_token( token )
115
+ (defined?( token ) && update_attribute( token, SecureRandom.hex(13) ))? true : false
116
+ end
117
+ end
118
+ end
@@ -1,3 +1,3 @@
1
1
  module Lobby
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.24"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Lobby
2
- VERSION = "0.0.22"
2
+ VERSION = "0.0.23"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lobby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -245,6 +245,7 @@ files:
245
245
  - config/routes.rb
246
246
  - lib/lobby/engine.rb~
247
247
  - lib/lobby/auth_user.rb
248
+ - lib/lobby/auth_user.rb~
248
249
  - lib/lobby/engine.rb
249
250
  - lib/lobby/version.rb
250
251
  - lib/lobby/version.rb~