diff --git a/canapGEST/API/app/Http/Controllers/AuthController.php b/canapGEST/API/app/Http/Controllers/AuthController.php index 44b070abeffdc404a539cb3eea5e85d5e9b3a757..f9e945add94db032906badaeacb2e8f179079e34 100644 --- a/canapGEST/API/app/Http/Controllers/AuthController.php +++ b/canapGEST/API/app/Http/Controllers/AuthController.php @@ -47,8 +47,8 @@ class AuthController extends Controller $this->oClient->SetWantedAttributes(array('uniqueid', 'name', 'firstname', 'unit', 'unitid', 'where', 'group')); $this->oClient->SetWishedAttributes(array('email', 'title')); // $this->oClient->SetApplicationURL('https://canap-gest.epfl.ch:8443'); - // $this->oClient->SetApplicationURL('http://canap-gest-dev.local:8080'); - $this->oClient->SetApplicationURL('http://localhost:8000/api/auth/login'); + $this->oClient->SetApplicationURL('http://canap-gest-dev.local:8080'); + // $this->oClient->SetApplicationURL('http://localhost:8000/api/auth/login'); $this->oClient->SetCustomFilter('org=EPFL&group=canap-gest-users-dev'); $this->oClient->Authenticate(); diff --git a/canapGEST/Documentation/journal_travail.xlsx b/canapGEST/Documentation/journal_travail.xlsx index c26463dc75116a6add63c9fb7e1ed32d8c330f28..799cf12f03e650c69c237b49d3eedd2479fc9573 100644 Binary files a/canapGEST/Documentation/journal_travail.xlsx and b/canapGEST/Documentation/journal_travail.xlsx differ diff --git a/canapGEST/Site/src/layouts/MainNavbar.vue b/canapGEST/Site/src/layouts/MainNavbar.vue index cff676f7eb289723cd8464ac661b17755ce6ac3c..fbe6351e70d910d7bfc1ce0654c1e63d4954813b 100644 --- a/canapGEST/Site/src/layouts/MainNavbar.vue +++ b/canapGEST/Site/src/layouts/MainNavbar.vue @@ -3,22 +3,34 @@ <img src="../../public/statics/epfl_logo.png" width="100"> <v-toolbar-title>Canap-Gest</v-toolbar-title> <v-spacer></v-spacer> - <v-toolbar-items class="hidden-sm-and-down"> + <v-toolbar-items class="hidden-sm-and-down" v-if="!isLoged"> <v-btn flat class="white--text">Link One</v-btn> <v-btn flat class="white--text">Link Two</v-btn> <v-btn icon class="white--text"> <v-icon @click="login">account_circle</v-icon> </v-btn> </v-toolbar-items> + <v-toolbar-items class="hidden-sm-and-down" v-else> + <v-btn flat class="white--text">Nicolas Crausaz</v-btn> + <v-btn icon class="white--text"> + <v-icon @click="logout">logout</v-icon> + </v-btn> + </v-toolbar-items> </v-toolbar> </template> <script> export default { name: 'main-navbar', + computed: { + isLoged() { return this.$store.getters['moduleUser/userIsLogedIn'] } + }, methods: { login() { this.$store.dispatch('moduleUser/login') + }, + logout() { + this.$store.dispatch('moduleUser/logout') } }, } diff --git a/canapGEST/Site/src/plugins/axios.js b/canapGEST/Site/src/plugins/axios.js index 92775ec15920470e7862b1eab36907fe0ee59c85..cf4de35fd9428c2fc8fc1d166f79f7201ff99ced 100644 --- a/canapGEST/Site/src/plugins/axios.js +++ b/canapGEST/Site/src/plugins/axios.js @@ -1,10 +1,8 @@ import axios from 'axios' const instance = axios.create({ - baseURL: 'http://localhost:8000/api', - maxRedirects: 0 + headers: { 'Authorization': "Bearer " + localStorage.getItem('stored_token') }, + baseURL: 'http://localhost:8000/api' }) -instance.defaults.headers.common['Authorization'] = ''; - export default instance \ No newline at end of file diff --git a/canapGEST/Site/src/store/modules/user/actions.js b/canapGEST/Site/src/store/modules/user/actions.js index 498d8b9c19a580867b639cef0154ebcfdda118fa..dfcfdd7fc8c6dca16dba5752d2053765ebf313a8 100644 --- a/canapGEST/Site/src/store/modules/user/actions.js +++ b/canapGEST/Site/src/store/modules/user/actions.js @@ -1,26 +1,30 @@ import axios from '../../../plugins/axios' -export function login (/*context, params*/) { - // context.commit(mutation) - // axios({ - // method: "get", - // url: "auth/login" - // }) - - // window.location = 'http://localhost:8000/api/auth/login' - - axios.get('auth/login') - .then(response => { - // console.log(response.request.responseURL) - window.location = response.request.responseURL +export function login() { + axios({ + method: 'get', + url: '/auth/login' }) - .catch(err => { - console.log(err) - // window.location = 'http://localhost:8000/api/auth/login' - // console.log(err) + .then(response => { + if (!response.data.token) { + window.location = 'http://localhost:8000/api/auth/login' + } else { + localStorage.setItem('stored_token', response.data.token); + console.log('setting token:' + response.data.token) + } + }) +} + +export function getUserData(context) { + axios({ + method: 'get', + url: '/user' }) + .then(response => { + context.commit('setUserData', response.data) + }) } -export function logout (/*context, params*/) { - // context.commit(mutation) +export function logout() { + localStorage.removeItem('stored_token'); } \ No newline at end of file diff --git a/canapGEST/Site/src/store/modules/user/getters.js b/canapGEST/Site/src/store/modules/user/getters.js index 5c933b16b3f3f86ba60c90ceb2690242ffd56a40..cb5d186a2efe5799a9cfd39a19613a26deb2fe16 100644 --- a/canapGEST/Site/src/store/modules/user/getters.js +++ b/canapGEST/Site/src/store/modules/user/getters.js @@ -1,3 +1,4 @@ -export default { - +export function userIsLogedIn () { + // return localStorage.getItem('stored_token') != null + return localStorage.getItem('stored_token') } \ No newline at end of file diff --git a/canapGEST/Site/src/store/modules/user/index.js b/canapGEST/Site/src/store/modules/user/index.js index 85b6a31c35270aa9396dda24b795d61d69f747f7..1839ad7e30ba872d23944a9ede0abb1d428b3c40 100644 --- a/canapGEST/Site/src/store/modules/user/index.js +++ b/canapGEST/Site/src/store/modules/user/index.js @@ -1,12 +1,12 @@ import state from './state' -// import * as getters from './getters' -// import * as mutations from './mutations' +import * as getters from './getters' +import * as mutations from './mutations' import * as actions from './actions' export default { namespaced: true, state, - // getters, - // mutations, + getters, + mutations, actions } \ No newline at end of file diff --git a/canapGEST/Site/src/store/modules/user/mutations.js b/canapGEST/Site/src/store/modules/user/mutations.js index 5c933b16b3f3f86ba60c90ceb2690242ffd56a40..f46dd709c97701c65d032aec74e141d187b50e37 100644 --- a/canapGEST/Site/src/store/modules/user/mutations.js +++ b/canapGEST/Site/src/store/modules/user/mutations.js @@ -1,3 +1,4 @@ -export default { - +export function setUserData (state, data) { + console.log(data) + state.userData = data } \ No newline at end of file diff --git a/canapGEST/Site/src/store/modules/user/state.js b/canapGEST/Site/src/store/modules/user/state.js index 4ba933ec8da1ca20f9c8d426cf80e67a680455ff..a508fcbf01f6274dfb177b7b960925365dda6dbc 100644 --- a/canapGEST/Site/src/store/modules/user/state.js +++ b/canapGEST/Site/src/store/modules/user/state.js @@ -1,3 +1,13 @@ export default { - token: '' + userData: { + tequila: { + firstname: String, + name: String, + group: String, + user: String, + sciper: String + }, + role: String, + permissions: [] +} } \ No newline at end of file diff --git a/canapGEST/Site/src/views/HomeView.vue b/canapGEST/Site/src/views/HomeView.vue index 290ce4d6ff9b5b388f9e3ad3e403ebc86e4a408f..239e784c7acc7c556527cca7dcdc8c6c7c32c140 100644 --- a/canapGEST/Site/src/views/HomeView.vue +++ b/canapGEST/Site/src/views/HomeView.vue @@ -2,6 +2,8 @@ <div id="home-view"> <h1>Accueil</h1>Accueil: statistiques Il y a : 4 nouvelles postulations pour le métier : test depuis votre dernière connexion + <br> + <button @click="$store.dispatch('moduleUser/getUserData')">get data</button> </div> </template>