Commit faabb585 authored by Fernando D'Agostino's avatar Fernando D'Agostino
Browse files

Refactor and renaming

parent c66c3681
......@@ -3,7 +3,6 @@ import 'whatwg-fetch';
import UserActions from './actions/UserActions';
import UserStore from './stores/UserStore';
import Functions from './utils/Functions';
export default class UserAuth extends Component {
constructor(props) {
......@@ -27,19 +26,6 @@ export default class UserAuth extends Component {
currentUser: state.currentUser
});
}
logout(){
$.ajax({
method: "DELETE",
url: "/users/sign_out.json",
data: {
authenticity_token: Functions.getMetaContent("csrf-token")
}
}).done(function(){
location.reload();
});
UserActions.logout();
}
render() {
return (
......@@ -47,7 +33,7 @@ export default class UserAuth extends Component {
<p className='navbar-text'>
{`Logged in as ${this.state.currentUser.name}.`}
</p>
<a onClick={() => this.logout()} className='btn btn-primary navbar-btn'>Logout</a>
<a onClick={() => UserActions.logout()} className='btn btn-primary navbar-btn'>Logout</a>
</span>
);
}
......
......@@ -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,12 +26,15 @@ class UserActions {
}
logout() {
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) {
cookie.remove('_chemotion_session');
window.location = '/users/sign_in';
location.reload();
}
});
}
......
var Functions = {
var DocumentHelper = {
getMetaContent: function(name) {
var metas = document.getElementsByTagName('meta');
......@@ -12,4 +12,4 @@ var Functions = {
}
}
module.exports = Functions;
\ No newline at end of file
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
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