Browse code

Odhlasenie pouzivatela

Cinan Rakosnik authored on 23/05/2013 at 11:14:44
Showing 6 changed files
... ...
@@ -24,4 +24,6 @@
24 24
         %span.status.icon-record.dnd
25 25
         %a{ href: '#' }
26 26
           DND
27
-          %span.icon-arrow-down.drop-down
28 27
\ No newline at end of file
28
+          %span.icon-arrow-down.drop-down
29
+    %a.logout.icon-exit.icon-after{ href: '/logout' }
30
+      Logout
29 31
\ No newline at end of file
... ...
@@ -129,6 +129,20 @@
129 129
       top: 2px;
130 130
       font-size: 13px;
131 131
     }
132
+
133
+    .logout {
134
+      left: 158px;
135
+      font-weight: normal;
136
+      float: left;
137
+      margin: 2px;
138
+      position: absolute;
139
+      top: 61px;
140
+      color: $status-color;
141
+
142
+      &:after {
143
+        padding-left: 4px;
144
+      }
145
+    }
132 146
   }
133 147
 
134 148
   h1 input, h2 input {
... ...
@@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
6 6
 		if authenticated?
7 7
 			create_new_authentication()
8 8
 
9
-            unless controller_name == 'chat'
9
+            if controller_name != 'chat' and (controller_name != 'sessions' and action_name != 'destroy')
10 10
                 redirect_to chat_path
11 11
             end
12 12
 		else
... ...
@@ -35,6 +35,12 @@ class ApplicationController < ActionController::Base
35 35
         save_session(user_id, user_credentials)
36 36
     end
37 37
 
38
+    def remove_session
39
+        reset_session()
40
+        cookies.delete :iv
41
+        cookies.delete :key
42
+    end
43
+
38 44
     private
39 45
 
40 46
     def save_session(user_id, user_credentials)
... ...
@@ -20,6 +20,9 @@ class SessionsController < ApplicationController
20 20
 	end
21 21
 
22 22
 	def destroy
23
-		self.remove_old_session(session[:token])
23
+        Token.remove_token(session[:token])
24
+        remove_session()
25
+
26
+        redirect_to root_path
24 27
 	end
25 28
 end
... ...
@@ -46,6 +46,10 @@ class Token
46 46
         where(token: token).first().user.jids
47 47
     end
48 48
 
49
+    def self.remove_token(token)
50
+        where(token: token).delete
51
+    end
52
+
49 53
     private
50 54
 
51 55
 	def self.generate_token
... ...
@@ -1,12 +1,12 @@
1 1
 Xmpp::Application.routes.draw do
2
-    get "chat/index"
2
+    get 'chat/index'
3 3
 
4 4
     resources :sessions, only: [:new, :create, :destroy]
5 5
 
6 6
     root :to => 'sessions#new'
7 7
 
8 8
     match '/signin',  to: 'sessions#new'
9
-    match '/signout', to: 'sessions#destroy', via: :delete
9
+    match '/logout',  to: 'sessions#destroy'
10 10
 
11 11
     match '/chat', to: 'chat#index'
12 12
 end