aadhar 0.0.11 → 0.0.12
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.
- checksums.yaml +8 -8
- data/app/controllers/aadhar/sessions_controller.rb +5 -3
- data/app/controllers/aadhar/users_controller.rb +0 -1
- data/app/models/authentication_token.rb +20 -0
- data/app/models/user.rb +2 -11
- data/db/migrate/20150130043153_create_users.rb +0 -1
- data/db/migrate/20150227220755_create_authentication_tokens.rb +9 -0
- data/lib/aadhar/authenticate.rb +4 -1
- data/lib/aadhar/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTlkMTg0MmZjOGMxMzBlM2Y5NDU3M2EyOTQ4NjBkYjdiYTVkY2EwMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDA5OTBhZmZmMTVkMTQzOTRlZDUxZmNkNDUzNTU3MmNjYTU3YzM2Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmJmNjlhMTk1ZGE2ZTE3Y2E2ZWUyMDM3MDNiOTgzZDExYTA2ZDIxNDgyYjZl
|
10
|
+
ODBmNDk3NWYxZjhmZTYzOWE1YmQ2MTZkNmFkZWRhYzRlMTAyYWM2MDk0YTZi
|
11
|
+
NGNkMjNkNDY2NTk2YWIyY2FhZmViNmY1ZTZkY2UwN2VjNWNhMjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmE3Yjk1YjY4OGM5NjczN2ViOWI1MDYwY2RjYjY5ZWU2ZjQ5ZmVjNDA0MWM5
|
14
|
+
MmMxYWM2ODYxN2E4YTc2YWEzNWM2NmUxYTgzMDY4YzM5NGFiZTcwYTk3NDU2
|
15
|
+
ZjA1ZjExYWIyNTAwNjU2YTE3MWI2MWVjYjljZDNlZTQyZGE4NDk=
|
@@ -1,14 +1,15 @@
|
|
1
1
|
class Aadhar::SessionsController < Aadhar::ApplicationController
|
2
|
+
before_filter :authenticate, only: [:destroy]
|
2
3
|
|
3
4
|
def create
|
4
5
|
user = User.authenticate(params[:email], params[:password])
|
5
6
|
if user
|
6
|
-
user
|
7
|
+
authentication_token = AuthenticationToken.create_token(user)
|
7
8
|
render :status => 200,
|
8
9
|
:json => { :success => true,
|
9
10
|
:info => "Logged in",
|
10
11
|
:data => {
|
11
|
-
:auth_token =>
|
12
|
+
:auth_token => authentication_token.token,
|
12
13
|
:user => {
|
13
14
|
id: user.id,
|
14
15
|
email: user.email,
|
@@ -24,7 +25,8 @@ class Aadhar::SessionsController < Aadhar::ApplicationController
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def destroy
|
27
|
-
|
28
|
+
authentication_token = AuthenticationToken.where(token: params[:auth_token], user_id: current_user.id).first
|
29
|
+
authentication_token.destroy
|
28
30
|
render :status => 200,
|
29
31
|
:json => { :success => true,
|
30
32
|
:info => "Logged out",
|
@@ -5,7 +5,6 @@ class Aadhar::UsersController < Aadhar::ApplicationController
|
|
5
5
|
@user.set_temporary_password
|
6
6
|
@user.change_password = true
|
7
7
|
if @user.save
|
8
|
-
#RegistrationEmailJob.set(wait: 20.seconds).perform_later(@user, @user.temp_password)
|
9
8
|
UserMailer.signup_email(@user, @user.temp_password).deliver_later
|
10
9
|
render :status => 200,
|
11
10
|
:json => { :success => true,
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class AuthenticationToken < ActiveRecord::Base
|
2
|
+
belongs_to :user
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def generate_token
|
6
|
+
token = loop do
|
7
|
+
random_token = SecureRandom.urlsafe_base64(nil, false)
|
8
|
+
break random_token unless AuthenticationToken.exists?(token: random_token)
|
9
|
+
end
|
10
|
+
|
11
|
+
return token
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_token(user)
|
15
|
+
authentication_token = AuthenticationToken.create!(user_id: user.id, token: generate_token)
|
16
|
+
return authentication_token
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/app/models/user.rb
CHANGED
@@ -8,6 +8,8 @@ class User < ActiveRecord::Base
|
|
8
8
|
validates_presence_of :name
|
9
9
|
validates_uniqueness_of :email
|
10
10
|
|
11
|
+
has_many :authentication_tokens
|
12
|
+
|
11
13
|
def self.authenticate(email, password)
|
12
14
|
user = find_by_email(email)
|
13
15
|
if user && user.password_hash == ::BCrypt::Engine.hash_secret(password, user.password_salt)
|
@@ -38,15 +40,4 @@ class User < ActiveRecord::Base
|
|
38
40
|
return Array.new(password_length){||lower_alphabets[rand(lower_alphabets.size)]}.join
|
39
41
|
end
|
40
42
|
|
41
|
-
def generate_token
|
42
|
-
self.authentication_token = loop do
|
43
|
-
random_token = SecureRandom.urlsafe_base64(nil, false)
|
44
|
-
break random_token unless self.class.exists?(authentication_token: random_token)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def save_token
|
49
|
-
self.generate_token
|
50
|
-
self.save
|
51
|
-
end
|
52
43
|
end
|
data/lib/aadhar/authenticate.rb
CHANGED
@@ -7,7 +7,10 @@ module Aadhar
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def current_user
|
10
|
-
@current_user ||=
|
10
|
+
@current_user ||= begin
|
11
|
+
authentication = AuthenticationToken.where(token: params[:auth_token]).first
|
12
|
+
authentication.present? ? authentication.user : nil
|
13
|
+
end
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
data/lib/aadhar/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aadhar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krunal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- app/controllers/aadhar/users_controller.rb
|
88
88
|
- app/helpers/aadhar/application_helper.rb
|
89
89
|
- app/mailers/user_mailer.rb
|
90
|
+
- app/models/authentication_token.rb
|
90
91
|
- app/models/user.rb
|
91
92
|
- app/views/layouts/aadhar/application.html.erb
|
92
93
|
- app/views/layouts/aadhar/mailer.html.erb
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- app/views/user_mailer/signup_email.html.erb
|
96
97
|
- config/routes.rb
|
97
98
|
- db/migrate/20150130043153_create_users.rb
|
99
|
+
- db/migrate/20150227220755_create_authentication_tokens.rb
|
98
100
|
- lib/aadhar.rb
|
99
101
|
- lib/aadhar/authenticate.rb
|
100
102
|
- lib/aadhar/engine.rb
|