added profile stuffi
This commit is contained in:
@@ -61,3 +61,5 @@ export function fetchProfile(jwt: any) {
|
|||||||
Vue.$log.debug('JWT: ' + jwt);
|
Vue.$log.debug('JWT: ' + jwt);
|
||||||
return axios.get(`${API_URL}/v1/user/profile`, { headers: { Authorization: `Bearer ${jwt}` } });
|
return axios.get(`${API_URL}/v1/user/profile`, { headers: { Authorization: `Bearer ${jwt}` } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import Repository from './Repository';
|
import Repository from './Repository';
|
||||||
|
import Vue from 'vue/types/vue';
|
||||||
|
import axios from 'axios';
|
||||||
|
import {dictEmptyValToNull} from '@/utils';
|
||||||
|
|
||||||
const resource = '/user';
|
const resource = '/user';
|
||||||
|
|
||||||
@@ -17,4 +20,8 @@ export default {
|
|||||||
createUser(userData: any) {
|
createUser(userData: any) {
|
||||||
return Repository.post(`${resource}`, userData);
|
return Repository.post(`${resource}`, userData);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateProfile(userData: any) {
|
||||||
|
return Repository.put(`${resource}/profile`, dictEmptyValToNull(userData));
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,22 +4,62 @@
|
|||||||
<section class="hero is-primary">
|
<section class="hero is-primary">
|
||||||
<div class="hero-body">
|
<div class="hero-body">
|
||||||
<div class="container has-text-centered">
|
<div class="container has-text-centered">
|
||||||
<h2 class="title">Profile</h2>
|
<div class="clearfix">
|
||||||
<h3 class="title">Token validity ({{tokenValidity}})</h3>
|
<b-img left style="margin-right: 20px;" src="https://picsum.photos/125/125/?image=58"
|
||||||
<h3 class="title">Refresh token validity ({{refreshTokenValidity}})</h3>
|
alt="Left image"></b-img>
|
||||||
<h3 class="title">access_token ({{access_token}})</h3>
|
<h2 class="title" v-if="profile.nickname">{{profile.nickname}}</h2>
|
||||||
|
<h2 class="title" v-else-if="profile.first_name">
|
||||||
|
{{profile.first_name}} {{profile.last_name}}</h2>
|
||||||
|
<h2 class="title" v-else>{{profile.email}}</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<font-awesome-icon icon="envelope"/> {{profile.email}}
|
||||||
|
<a class="badge badge-pill badge-info">
|
||||||
|
<font-awesome-icon icon="pencil-alt"/></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p v-if="profile.nickname"><strong>{{$t('nickname')}}: </strong>{{profile.nickname}}</p>
|
||||||
|
<b-input-group style="max-width: 50%;" v-else size="sm">
|
||||||
|
<b-form-input name="nickname"
|
||||||
|
v-model="form.nickname"
|
||||||
|
class="form-control" type="text"
|
||||||
|
:placeholder="$t('nickname') + '('+profile.nickname +')'"></b-form-input>
|
||||||
|
<b-input-group-append>
|
||||||
|
<b-button :disabled="errors.has('nickname')"
|
||||||
|
@click="updateProfile('nickname')"
|
||||||
|
variant="outline-success">
|
||||||
|
<font-awesome-icon icon="check"></font-awesome-icon>
|
||||||
|
</b-button>
|
||||||
|
</b-input-group-append>
|
||||||
|
</b-input-group>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
<p><strong>{{$t('first_name')}}: </strong>{{profile.first_name}}</p>
|
||||||
|
<p><strong>{{$t('last_name')}}: </strong>{{profile.last_name}}</p>
|
||||||
|
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
<p class="title">Token validity ({{tokenValidity}})</p>
|
||||||
|
<p class="title">Refresh token validity ({{refreshTokenValidity}})</p>
|
||||||
|
<p class="title">access_token ({{access_token}})</p>
|
||||||
<p>{{profile.id}}</p>
|
<p>{{profile.id}}</p>
|
||||||
<p class="subtitle error-msg">{{ errorMsg }}</p>
|
<p class="subtitle error-msg">{{ errorMsg }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {EventBus} from '@/utils';
|
import {EventBus} from '@/utils';
|
||||||
import {getRemainingJwtValiditySeconds} from '../utils';
|
import {getRemainingJwtValiditySeconds} from '../utils';
|
||||||
|
import getRepository from '@/api/RepositoryFactory';
|
||||||
|
|
||||||
|
const userRepository = getRepository('user');
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -28,6 +68,12 @@
|
|||||||
errorMsg: '',
|
errorMsg: '',
|
||||||
tokenValidity: -1,
|
tokenValidity: -1,
|
||||||
refreshTokenValidity: -1,
|
refreshTokenValidity: -1,
|
||||||
|
form: {
|
||||||
|
first_name: '',
|
||||||
|
last_name: '',
|
||||||
|
nickname: '',
|
||||||
|
email: '',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -35,6 +81,19 @@
|
|||||||
this.$store.dispatch('login', {email: this.email, password: this.password})
|
this.$store.dispatch('login', {email: this.email, password: this.password})
|
||||||
.then(() => this.$router.push('/'));
|
.then(() => this.$router.push('/'));
|
||||||
},
|
},
|
||||||
|
updateProfile(fieldName) {
|
||||||
|
this.$parent.$data.isLoading = true;
|
||||||
|
const data = {};
|
||||||
|
data[fieldName]= this.form[fieldName];
|
||||||
|
this.$log.debug(this.form);
|
||||||
|
userRepository.updateProfile(data)
|
||||||
|
.then(() => {
|
||||||
|
this.$store.dispatch('loadRecorders')
|
||||||
|
.then(() => {
|
||||||
|
this.$parent.$data.isLoading = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$log.debug('Profile: mounting...');
|
this.$log.debug('Profile: mounting...');
|
||||||
@@ -62,7 +121,7 @@
|
|||||||
},
|
},
|
||||||
access_token() {
|
access_token() {
|
||||||
return this.$store.state.access_token;
|
return this.$store.state.access_token;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ import {
|
|||||||
faTrash,
|
faTrash,
|
||||||
faPencilAlt,
|
faPencilAlt,
|
||||||
faCogs,
|
faCogs,
|
||||||
|
faAt,
|
||||||
|
faUser,
|
||||||
|
faEnvelope,
|
||||||
} from '@fortawesome/free-solid-svg-icons';
|
} from '@fortawesome/free-solid-svg-icons';
|
||||||
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome';
|
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome';
|
||||||
|
|
||||||
@@ -41,7 +44,8 @@ import 'bootstrap-vue/dist/bootstrap-vue.css';
|
|||||||
|
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
library.add(faCoffee, faTrash, faPencilAlt, faScroll, faCheck, faCircle, faList, faPlus, faDoorOpen, faCogs);
|
library.add(faCoffee, faTrash, faPencilAlt, faScroll, faCheck, faCircle, faList, faPlus, faDoorOpen, faCogs, faAt,
|
||||||
|
faUser, faEnvelope);
|
||||||
|
|
||||||
Vue.component('font-awesome-icon', FontAwesomeIcon);
|
Vue.component('font-awesome-icon', FontAwesomeIcon);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const messages = {
|
|||||||
links: 'Essential Links',
|
links: 'Essential Links',
|
||||||
ecosystem: 'Ecosystem',
|
ecosystem: 'Ecosystem',
|
||||||
building_number: 'Building #',
|
building_number: 'Building #',
|
||||||
building_name: 'Building'
|
building_name: 'Building',
|
||||||
},
|
},
|
||||||
es: {
|
es: {
|
||||||
welcomeMsg: 'Bienvenido a tu aplicación Vue.js + TypeScript',
|
welcomeMsg: 'Bienvenido a tu aplicación Vue.js + TypeScript',
|
||||||
|
|||||||
Reference in New Issue
Block a user