nuVistA/htdocs/Login.vue

150 lines
5.2 KiB
Vue
Raw Normal View History

2022-09-22 07:10:08 -04:00
<template>
2022-09-26 17:38:27 -04:00
<div class="accordion mb-3 shadow">
<div class="accordion-item">
2022-09-26 18:35:10 -04:00
<h2 class="accordion-header"><button class="accordion-button" :class="{ testing: (x_server) && (x_server.production) && (x_server.production != '1') }" type="button" @click="() => show = !show"><template v-if="user">{{user[2]}}<template v-if="server"> @ {{server.domain}}</template></template><template v-else>Login</template></button></h2>
2022-09-26 17:38:27 -04:00
<div class="accordion-collapse collapse" :class="{ show }">
<div class="accordion-body">
<div class="card">
<div class="card-body">
<p class="card-text row"><code class="col" v-if="banner"><pre>{{banner.join('\n')}}</pre></code><code class="col" v-if="user"><pre>{{user.join('\n')}}</pre></code></p>
</div>
<button class="btn btn-danger" style="width: 100%;" type="button" v-if="user" v-on:click="logout">Logout</button>
<div class="input-group flex-nowrap" v-if="!user">
<span class="input-group-text">🔑</span>
<select class="form-control" v-model="host">
<option value="vista.bronx.med.va.gov:19201">Bronx BRX</option>
<option value="test.bronx.med.va.gov:19001">Bronx BRX-TEST</option>
<option value="vista.east-orange.med.va.gov:19203">East Orange NJH</option>
<option value="test.east-orange.med.va.gov:19003">East Orange NJH-TEST</option>
<option value="vista.hudson-valley.med.va.gov:19205">Hudson Valley NVH</option>
<option value="test.hudson-valley.med.va.gov:19005">Hudson Valley NVH-TEST</option>
<option value="vista.brooklyn.med.va.gov:19208">NY Harbor NYH</option>
<option value="test.brooklyn.med.va.gov:19008">NY Harbor NYH-TEST</option>
<option value="vista.northport.med.va.gov:19209">Northport NOP</option>
<option value="test.northport.med.va.gov:19009">Northport NOP-TEST</option>
<option value="vista.v02.med.va.gov:19224">VISN 2 V02</option>
<option value="test.v02.med.va.gov:19024">VISN 2 V02-TEST</option>
</select>
<input type="password" class="form-control" placeholder="Access Code" v-model="accesscode" />
<input type="password" class="form-control" placeholder="Verify Code" v-model="verifycode" />
<button class="btn btn-primary" type="button" v-on:click="login">Login<template v-if="!(accesscode || verifycode)"> (omit AV codes for SAML)</template></button>
</div>
</div>
</div>
</div>
2022-09-22 07:10:08 -04:00
</div>
</div>
</template>
2022-09-26 17:38:27 -04:00
<style scoped>
.accordion-button.testing:not(.collapsed) {
color: #e40c63;
background-color: #ffe7f1;
}
</style>
2022-09-22 07:10:08 -04:00
<script>
import vistax from './vistax.mjs';
export default {
props: {
secret: String,
client: Object,
2022-09-26 17:38:27 -04:00
server: {
type: Object,
default: null
},
2022-09-22 07:10:08 -04:00
user: {
type: Array,
default: null
}
},
emits: {
'update:client': Object,
2022-09-26 17:38:27 -04:00
'update:server': {
type: Object,
default: null
},
2022-09-22 07:10:08 -04:00
'update:user': {
type: Array,
default: null
}
},
data() {
return {
2022-09-26 17:38:27 -04:00
show: false,
2022-09-22 07:10:08 -04:00
x_client: this.client,
2022-09-26 17:38:27 -04:00
x_server: this.server,
2022-09-22 07:10:08 -04:00
x_user: this.user,
banner: null,
accesscode: null,
verifycode: null
};
},
2022-09-27 19:22:57 -04:00
computed: {
host: {
get() {
return vistax.state.host;
},
set(value) {
vistax.state.host = value;
}
}
},
2022-09-22 07:10:08 -04:00
watch: {
2022-09-27 19:22:57 -04:00
host: {
2022-09-27 19:56:26 -04:00
handler(value) {
this.connect();
2022-09-27 19:22:57 -04:00
}, immediate: true
2022-09-26 17:38:27 -04:00
},
2022-09-22 07:10:08 -04:00
client(value) { this.x_client = value; },
2022-09-27 19:56:26 -04:00
x_client(value) { this.$emit('update:client', value); if(!value) this.connect(); },
2022-09-26 17:38:27 -04:00
server(value) { this.x_server = value; },
x_server(value) { this.$emit('update:server', value); },
2022-09-22 07:10:08 -04:00
user(value) { this.x_user = value; },
x_user(value) { this.$emit('update:user', value); }
},
methods: {
2022-09-27 19:56:26 -04:00
async connect() {
this.logout();
this.x_client = await (this.host ? vistax.Client.fromCookie(this.secret, this.host) : vistax.Client.fromCookie(this.secret));
this.banner = await this.x_client.XUS_INTRO_MSG();
if((await this.x_client.userinfo()).result) try {
var user = await this.x_client.XUS_GET_USER_INFO();
this.x_user = user[0] ? user : null
} catch(ex) {
this.x_user = null;
}
this.$emit('update:user', this.x_user);
this.show = !this.x_user;
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
console.log('Backend secret', this.secret);
console.log(this.banner);
},
2022-09-26 17:38:27 -04:00
async login(evt) {
2022-09-27 19:22:57 -04:00
if(this.x_client) {
var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
if(!!res.result[0]) {
var user = await this.x_client.XUS_GET_USER_INFO();
this.x_user = user[0] ? user : null
} else this.x_user = null;
this.$emit('update:user', this.x_user);
this.show = !this.x_user;
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
console.log('Authenticate', res);
}
2022-09-26 17:38:27 -04:00
},
async logout(evt) {
if(this.x_client) {
console.log('Close', await this.x_client.close());
this.$emit('update:client', this.x_client = null);
this.$emit('update:server', this.x_server = null);
this.$emit('update:user', this.x_user = null);
}
2022-09-27 19:22:57 -04:00
this.banner = null;
this.show = true;
2022-09-22 07:10:08 -04:00
}
}
};
</script>