Login + Logout implemented; ProfilCard v1 implemented;

This commit is contained in:
2019-07-19 23:12:38 +02:00
parent 1fe9f22109
commit 5f0c8c1d2f
45 changed files with 2534 additions and 708 deletions
+140
View File
@@ -0,0 +1,140 @@
var auth = {};
function clearAuthState() {
auth.user = ''; // Login name
auth.name = ''; // Full name
auth.type = ''; // type of login (domain specific)
auth.mail = ''; // Full mail address
auth.roles = {}; // Role authorizations e.g. {user: true}
auth.gender = ''; // Gender (e.g. Frau)
}
clearAuthState();
function fillAuthState(state) {
// Shallow copy
if (auth === undefined) {
auth = state;
}
for (e in auth) {
auth[e] = state[e];
}
}
// Login component: Login panel (if not logged in) or Logout element (if logged in)
Vue.component('login-panel', {
template: `
<div class="modal-card" style="width: auto">
<header class="modal-card-head">
<p class="modal-card-title">Login (Ohmportal)</p>
</header>
<section class="modal-card-body">
<b-field>
<b-input
v-model=user
placeholder="User"
:value="user"
required>
</b-input>
</b-field>
<b-field>
<b-input
v-model=pwd
type="password"
placeholder="Password"
:value="pwd"
@keyup.enter.native="login"
required>
</b-input>
</b-field>
<b-checkbox>Eingeloggt bleiben</b-checkbox>
<div v-if="error" style="color:red;"> Versuche es nochmal.</div>
</section>
<footer class="modal-card-foot">
<button class="button" type="button" @click.prevent="$parent.close()">Close</button>
<button class="button is-primary" @click.prevent="login">Login</button>
</footer>
</div>`,
data: function () {
return {
auth: auth,
user: '',
pwd: '',
error: false,
};
},
methods: {
closeLoginPanel: function() {
this.$emit('close-login-panel');
},
showLoginPanel: function() {
this.$emit('show-login-panel');
},
pwd_changed: function(evt) {
// Only required for PasswordInsert Apps etc. who send only(!) change events
this.pwd = e.target.value;
// Alternative call the input event
//e.target.dispatchEvent(new Event('input'));
},
login: function() {
clearAuthState();
$.ajax({
url: "api/login",
data: {
user: this.user,
pwd: this.pwd
},
method: "POST"
}).done(successful_login).fail(failed_login);
function successful_login(resData) {
fillAuthState(resData);
console.info("Correct credentials");
this.closeLoginPanel;
//console.log(resData);
router.push('/home');
}
function failed_login(err) {
console.info("Wrong credentials");
this.showError=true;
this.showLoginPanel;
console.log("error: " + err.responseText);
console.log(err);
}
},
checkData: function() {
clearAuthState();
$.ajax({
url: "api/login",
data: undefined,
method: "POST"
}).done(successful_login).fail(failed_login);
function successful_login(res) {
console.info("Re-Auth: Correct credentials");
this.closeLoginPanel;
//console.log(res);
router.push('/home')
}
function failed_login(err) {
console.info("Re-Auth: Wrong credentials");
this.showError=true;
this.showLoginPanel;
console.log("error: " + err.responseText);
console.log(err);
}
},
logout: function() {
clearAuthState();
$.ajax({ url: "api/logout", method: "POST" });
this.closeLoginPanel;
}
},
});
-57
View File
@@ -1,57 +0,0 @@
Vue.component('login-panel', {
template: `
<form action="">
<div class="modal-card" style="width: auto">
<header class="modal-card-head">
<p class="modal-card-title">Login</p>
</header>
<section class="modal-card-body">
<b-field>
<b-input
placeholder="User (Ohmportal)"
:value="user"
v-model=user
required>
</b-input>
</b-field>
<b-field>
<b-input
type="password"
placeholder="Password"
:value="pwd"
required>
</b-input>
</b-field>
<b-checkbox>Eingeloggt bleiben</b-checkbox>
<div v-if="showError" style="color:red;"> Versuche es nochmal.</div>
</section>
<footer class="modal-card-foot">
<button class="button" type="button" @click="$parent.close()">Close</button>
<button class="button is-primary" @click="checkData()">Login</button>
</footer>
</div>
</form>`,
data: function () {
return {
user: "name",
pwd:"password",
showError:false,
};
},
methods: {
checkData(){
if(this.user === "name" && this.pwd === "password"){
console.log("correct");
this.$parent.close();
}else{
console.log("wrong");
this.showError=true;
}
},
logIn(){
$parent.close();
},
},
});
+1 -2
View File
@@ -53,7 +53,6 @@ Vue.component('nav-router', {
</div>
</div>
</div>`,
});
const routes = [
@@ -63,7 +62,7 @@ const routes = [
{ path: "/createMessage", component: CreateMsgRouter },
{ path: "/bookmark", component: BookmarkRouter },
{ path: "/profil", component: ProfilRouter },
];
];
const router = new VueRouter({
routes,
+34 -37
View File
@@ -1,45 +1,42 @@
const ProfilRouter = {
template: `
<div>
<div v-if="isAuthentified">
<ProfilCard
v-for="(profil, index) in profilcard"
:key="profil.id"
:profil="profil"
></ProfilCard>
<b-button type="button" class="btn btn-primary" data-dismiss="modal" v-on:click="logOut()">Logout</b-button>
</div>
<div>
<div v-if="isAuth">
<profil-card></profil-card>
</div>
<div v-else>
<button class="button is-primary is-medium"
@click="isLPVisible = true">
Login
</button>
<div v-else-if="!isAuthentified">
<button class="button is-primary is-medium"
@click="showLoginModal = true">
Login
</button>
<b-modal :active.sync="showLoginModal" has-modal-card>
<login-panel></login-panel>
</b-modal>
</div>
</div>`,
<b-modal :active.sync="isLPVisible"
@close-login-panel="closeLoginPanel"
@show-login-panel="showLoginPanel"
has-modal-card>
<login-panel></login-panel>
</b-modal>
</div>
</div>`,
data: function () {
return {
showLoginModal: false,
isAuthentified: false,
profilcard: _profilcard,
isAuth: false,
isLPVisible: false,
};
},
methods: {
closeLoginPanel: function() {
this.isLPVisible = false;
},
showLoginPanel: function() {
this.isLPVisible = true;
},
},
created: function() {
//console.info(auth);
},
beforeMount: function() {
this.isAuth = (auth != null && auth.mail != '');
//console.info('beforeMount: '+this.isAuth);
},
};
/*
$('#myModal').on('show.bs.modal', function (event) {
console.log("Modal Opened")
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('whatever') // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('.modal-title').text('New message to ' + recipient)
modal.find('.modal-body input').val(recipient)
})
*/
+57 -58
View File
@@ -1,72 +1,71 @@
Vue.component('ProfilCard', {
template: `<div>
<div class="profil-card card">
<br/>
<img class="prof-image" src="img/profil_icon.png" alt="Card image cap">
Vue.component('profil-card', {
template: `
<div class="profil-card card">
<img class="prof-image" src="img/profil_icon.png" alt="Card image cap">
<div class="logout-item"><i class="material-icons" @click="$router.push('/login')">exit_to_app</i></div>
<div class="logout-item" style="float: right;">
<b-button type="button" class="btn btn-primary" data-dismiss="modal" @click.prevent="logout">
<i class="material-icons" style="float: left; margin: -0.1rem 0.2rem 0 -0.2rem;" @click.prevent="logout">exit_to_app</i>
Logout</b-button>
</div>
<div class="profil-text">
<h6><b>Benutzername:</b><br><br>
<b>{{ profil.user }}</b><br><br>
<b>Studiengang:</b><br><br>
{{ profil.major }}<br><br>
<b>Semester:</b><br><br>
{{ profil.semester }}<br></h6>
</div>
<div class="profil-text">
<span style="font-size:120%; display:inline-block; margin: 0.8rem 0 0 0;"><b>{{ auth.name }}</b></span><br><br>
<span style="font-size:90%; display:inline-block; margin: 0 0 0.8rem 0;"><b>{{ auth.type }}</b></span>
<br><br>
</div>
<hr class="first">
<hr class="first">
<div class="btnprofil">
<button @click="isCardModalActive = true"><b>Abonniert: <br/>{{ profil.abos }}</b> <br/></button>
<button @click="$router.push('/bookmark')"><b>Gespeichert:<br/> {{ profil.saved }}</b><br/></button>
</div>
<div class="btnprofil">
<button @click="isCardModalActive = true"><b>Abonniert: <br/>{{ abo }}</b> <br/></button>
<button @click="$router.push('/bookmark')"><b>Gespeichert:<br/> {{ saved }}</b><br/></button>
</div>
<section>
<b-modal :active.sync="isCardModalActive" :width="600" scroll="keep">
<div class="card">
<header class="modal-card-head">
<p class="modal-card-title">Abonnierte Kanäle</p>
</header>
<div class="card-content">
<div class="content">
<ul>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
</ul>
</div>
</div>
<footer class="modal-card-foot">
<b-button size="is-medium" @click="isCardModalActive = false">Close</b-button>
</footer>
<section>
<b-modal :active.sync="isCardModalActive" :width="600" scroll="keep">
<div class="card">
<header class="modal-card-head">
<p class="modal-card-title">Abonnierte Kanäle</p>
</header>
<div class="card-content">
<div class="content">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</b-modal>
</section>
</div>
</div>`,
props: ['profil'],
</div>
<footer class="modal-card-foot">
<b-button size="is-medium" @click="isCardModalActive = false">Close</b-button>
</footer>
</div>
</b-modal>
</section>
</div>`,
data: function () {
return {
isCardModalActive: false
auth: auth,
abo: 7,
saved: 3,
isCardModalActive: false,
majorList: {
},
};
},
methods: {
close: function () {
computed: {
},
methods: {
logout: function() {
clearAuthState();
$.ajax({ url: "api/logout", method: "POST" });
router.push('/profil');
}
}
});