Commit 9b5fe199 authored by Marco Sehrer's avatar Marco Sehrer
Browse files

Merge pull request #85 from ninjaconcept/85-fix-user-logout-and-enable-remember-me

Fix User Logout and enable Remember Me
parents 833233bc faabb585
...@@ -2,6 +2,9 @@ import alt from '../alt'; ...@@ -2,6 +2,9 @@ import alt from '../alt';
import UsersFetcher from '../fetchers/UsersFetcher'; import UsersFetcher from '../fetchers/UsersFetcher';
import cookie from 'react-cookie'; import cookie from 'react-cookie';
import DocumentHelper from '../utils/DocumentHelper';
class UserActions { class UserActions {
fetchUsers() { fetchUsers() {
...@@ -23,14 +26,15 @@ class UserActions { ...@@ -23,14 +26,15 @@ class UserActions {
} }
logout() { logout() {
console.log("LOGGING OUT"); fetch('/users/sign_out', {
fetch('/api/v1/users/sign_out', {method: 'delete', credentials: 'same-origin'}) method: 'delete',
credentials: 'same-origin',
data: {authenticity_token: DocumentHelper.getMetaContent("csrf-token")}
})
.then(response => { .then(response => {
console.log(response); console.log(response);
if (response.status == 204) { if (response.status == 204) {
console.log("DELETING COOKIE"); location.reload();
cookie.remove('_chemotion_session');
window.location = '/users/sign_in';
} }
}); });
} }
......
var DocumentHelper = {
getMetaContent: function(name) {
var metas = document.getElementsByTagName('meta');
for (var i=0; i<metas.length; i++) {
if (metas[i].getAttribute("name") == name) {
return metas[i].getAttribute("content");
}
}
return "";
}
}
module.exports = DocumentHelper;
\ No newline at end of file
...@@ -3,4 +3,5 @@ class ApplicationController < ActionController::Base ...@@ -3,4 +3,5 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
before_action :authenticate_user! before_action :authenticate_user!
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
end end
...@@ -9,11 +9,10 @@ ...@@ -9,11 +9,10 @@
= f.label :password = f.label :password
%br/ %br/
= f.password_field :password, autocomplete: "off", class: 'form-control' = f.password_field :password, autocomplete: "off", class: 'form-control'
/ - if devise_mapping.rememberable?
- if devise_mapping.rememberable? .form-group.field
.form-group.field = f.check_box :remember_me
= f.check_box :remember_me = f.label :remember_me
= f.label :remember_me
.form-group.actions .form-group.actions
= f.submit "Log in", class: 'btn btn-primary' = f.submit "Log in", class: 'btn btn-primary'
= render "devise/shared/links" = render "devise/shared/links"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment