|
|
|
@ -2,28 +2,22 @@
|
|
|
|
|
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import { login, getCapabilities, getUserData} from '../api/user';
|
|
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
|
|
|
|
// import cdk from 'cdk';
|
|
|
|
|
|
|
|
|
|
var rtcEngineClient = '';
|
|
|
|
|
|
|
|
|
|
export const UserModule = {
|
|
|
|
|
export default {
|
|
|
|
|
namespaced: true,
|
|
|
|
|
state: {
|
|
|
|
|
username: '',
|
|
|
|
|
password: '',
|
|
|
|
|
jwt: localStorage.getItem('jwt') || null,
|
|
|
|
|
subscriberId: localStorage.getItem('subscriberId') || null,
|
|
|
|
|
loggedUsername: '',
|
|
|
|
|
subscriber: null,
|
|
|
|
|
capabilities: null,
|
|
|
|
|
numbers: null
|
|
|
|
|
capabilities: null
|
|
|
|
|
},
|
|
|
|
|
getters: {
|
|
|
|
|
isLogged(state, getters) {
|
|
|
|
|
return !_.isEmpty(state.jwt) && !_.isEmpty(state.subscriberId);
|
|
|
|
|
},
|
|
|
|
|
hasUser(state, getters) {
|
|
|
|
|
return state.subscriber !== null;
|
|
|
|
|
},
|
|
|
|
|
getUsername(state, getters) {
|
|
|
|
|
if(state.subscriber !== null && !_.isEmpty(state.subscriber.display_name)) {
|
|
|
|
|
return state.subscriber.display_name;
|
|
|
|
@ -44,32 +38,34 @@ export const UserModule = {
|
|
|
|
|
login(state, options) {
|
|
|
|
|
state.jwt = options.jwt;
|
|
|
|
|
state.subscriberId = options.subscriberId;
|
|
|
|
|
state.subscriber = options.subscriber;
|
|
|
|
|
state.capabilities = options.capabilities;
|
|
|
|
|
},
|
|
|
|
|
setUserData(state, options) {
|
|
|
|
|
state.subscriber = options.subscriber;
|
|
|
|
|
state.capabilities = options.capabilities;
|
|
|
|
|
state.numbers = options.numbers;
|
|
|
|
|
},
|
|
|
|
|
logout(state) {
|
|
|
|
|
state.jwt = null;
|
|
|
|
|
state.subscriberId = null;
|
|
|
|
|
},
|
|
|
|
|
updatePassword (state, password) {
|
|
|
|
|
state.password = password;
|
|
|
|
|
},
|
|
|
|
|
updateUsername (state, username) {
|
|
|
|
|
state.username = username;
|
|
|
|
|
state.subscriber = null;
|
|
|
|
|
state.capabilities = null;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
|
|
|
|
login(context) {
|
|
|
|
|
login(context, options) {
|
|
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
|
|
login(context.state.username, context.state.password).then((result)=>{
|
|
|
|
|
login(options.username, options.password).then((result)=>{
|
|
|
|
|
localStorage.setItem('jwt', result.jwt);
|
|
|
|
|
localStorage.setItem('subscriberId', result.subscriberId);
|
|
|
|
|
}).then(()=>{
|
|
|
|
|
return getUserData(localStorage.getItem('subscriberId'));
|
|
|
|
|
}).then((result)=>{
|
|
|
|
|
context.commit('login', {
|
|
|
|
|
jwt: localStorage.getItem('jwt'),
|
|
|
|
|
subscriberId: localStorage.getItem('subscriberId')
|
|
|
|
|
subscriberId: localStorage.getItem('subscriberId'),
|
|
|
|
|
subscriber: result.subscriber,
|
|
|
|
|
capabilities: result.capabilities
|
|
|
|
|
});
|
|
|
|
|
resolve();
|
|
|
|
|
}).catch((err)=>{
|
|
|
|
@ -93,8 +89,7 @@ export const UserModule = {
|
|
|
|
|
getUserData(localStorage.getItem('subscriberId')).then((result)=>{
|
|
|
|
|
context.commit('setUserData', {
|
|
|
|
|
subscriber: result.subscriber,
|
|
|
|
|
capabilities: result.capabilities,
|
|
|
|
|
numbers: result.numbers
|
|
|
|
|
capabilities: result.capabilities
|
|
|
|
|
});
|
|
|
|
|
resolve();
|
|
|
|
|
}).catch((err)=>{
|
|
|
|
|