Browse code

Neukladanie usera do databazy automaticky, ukladanie mena a hesla do session

Cinan Rakosnik authored on 13/04/2013 at 10:25:12
Showing 2 changed files
... ...
@@ -27,28 +27,30 @@ class ApplicationController < ActionController::Base
27 27
             user_id = @token.user_id
28 28
             @token.delete
29 29
         else
30
-            user_id = !user_credentials ? nil : create_new_user(user_credentials)
30
+            user_id = nil
31 31
         end
32 32
 
33 33
         @token = Token.new
34 34
 
35
-        save_session(user_id)
35
+        save_session(user_id, user_credentials)
36 36
     end
37 37
 
38
-    def save_session(user_id)
39
-        session[:token] = Token.generate_token()
38
+    def save_session(user_id, user_credentials)
39
+        session[:token]      = Token.generate_token()
40 40
         session[:created_at] = Time.now
41
-        session[:ip] = request.remote_ip
41
+        session[:ip]         = request.remote_ip
42
+
43
+        if user_credentials
44
+            session[:users] = {} unless session[:users]
45
+            session[:users][user_credentials[:jid]] = user_credentials[:password]
46
+        end
42 47
 
43 48
         @token.save_session(session, user_id)
44 49
     end
45 50
 
46 51
     def create_new_user(user_credentials)
47 52
         jid  = user_credentials[:jid]
48
-        pass = user_credentials[:password]
49
-
50 53
         user = User.existing_jid(jid) || User.create_jid(jid)
51
-        user.update_pass(jid, pass)
52 54
 
53 55
         user.id
54 56
     end
... ...
@@ -4,8 +4,6 @@ class SessionsController < ApplicationController
4 4
 	end
5 5
 
6 6
 	def create
7
-		#require_dependency "signin.rb"
8
-
9 7
 		begin
10 8
 			Signin.try_login(params[:jid].downcase, params[:password])
11 9
 		rescue Signin::LoginError