summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
Diffstat (limited to 'users/app')
-rw-r--r--users/app/controllers/v1/sessions_controller.rb3
-rw-r--r--users/app/models/token.rb17
2 files changed, 19 insertions, 1 deletions
diff --git a/users/app/controllers/v1/sessions_controller.rb b/users/app/controllers/v1/sessions_controller.rb
index 9365d76..e3459d6 100644
--- a/users/app/controllers/v1/sessions_controller.rb
+++ b/users/app/controllers/v1/sessions_controller.rb
@@ -23,6 +23,7 @@ module V1
def update
authenticate!
+ @token = Token.create(:user_id => current_user.id)
render :json => login_response
end
@@ -35,7 +36,7 @@ module V1
def login_response
handshake = session.delete(:handshake)
- handshake.to_hash.merge(:id => current_user.id)
+ handshake.to_hash.merge(:id => current_user.id, :token => @token.id)
end
end
diff --git a/users/app/models/token.rb b/users/app/models/token.rb
new file mode 100644
index 0000000..44a6dfe
--- /dev/null
+++ b/users/app/models/token.rb
@@ -0,0 +1,17 @@
+class Token < CouchRest::Model::Base
+
+ use_database :tokens
+
+ property :user_id, String, accessible: false
+
+ validates :user_id, presence: true
+
+ def initialize(*args)
+ super
+ self.id = SecureRandom.urlsafe_base64(32)
+ end
+
+ design do
+ end
+end
+