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';
import UsersFetcher from '../fetchers/UsersFetcher';
import cookie from 'react-cookie';
import DocumentHelper from '../utils/DocumentHelper';
class UserActions {
fetchUsers() {
......@@ -23,14 +26,15 @@ class UserActions {
}
logout() {
console.log("LOGGING OUT");
fetch('/api/v1/users/sign_out', {method: 'delete', credentials: 'same-origin'})
fetch('/users/sign_out', {
method: 'delete',
credentials: 'same-origin',
data: {authenticity_token: DocumentHelper.getMetaContent("csrf-token")}
})
.then(response => {
console.log(response);
if (response.status == 204) {
console.log("DELETING COOKIE");
cookie.remove('_chemotion_session');
window.location = '/users/sign_in';
location.reload();
}
});
}
......
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
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authenticate_user!
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
end
......@@ -9,11 +9,10 @@
= f.label :password
%br/
= f.password_field :password, autocomplete: "off", class: 'form-control'
/
- if devise_mapping.rememberable?
.form-group.field
= f.check_box :remember_me
= f.label :remember_me
- if devise_mapping.rememberable?
.form-group.field
= f.check_box :remember_me
= f.label :remember_me
.form-group.actions
= f.submit "Log in", class: 'btn btn-primary'
= 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