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

Before

Width:  |  Height:  |  Size: 318 B

After

Width:  |  Height:  |  Size: 318 B

+61 -245
View File
@@ -1,15 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<html lang="de">
<head>
<title>OHM News</title>
<!-- NOTE: Meta Tags -->
<meta charset="utf-8">
<meta name="description" content="Ohm management app">
<meta name="keywords" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--for demonstration:-->
<!-- <meta http-equiv="refresh" content="10">
<!--for demonstration:-->
<!-- <meta http-equiv="refresh" content="30"> -->
<!-- NOTE: Define Theme Color -->
@@ -47,265 +46,82 @@
<link rel="apple-touch-startup-image" sizes="640x1136" href="ios-splash/apple_splash_640.png" /><!-- Phone -->
<!-- NOTE: CSS -->
<!-- CSS_Material Design for Bootstrap fonts and icons -->
<link rel="stylesheet" href="lib/bootstrap-font-and-icons.css">
<!-- CSS_Material Design for Bootstrap minified CSS -->
<!--<link rel="stylesheet" href="lib/bootstrap-material-design.min.css">-->
<link rel="stylesheet" href="lib/bootstrap-material-design-icons-2.5.94.min.css">
<!-- CSS_Buefy-->
<link rel="stylesheet" type="text/css" href="lib/buefy-0.7.5.css">
<!--<link rel="stylesheet" type="text/css" href="lib/buefy-0.7.5.min.css">-->
<!-- CSS_Custom Design -->
<link rel="stylesheet" type="text/css" href="style/style.css">
<!-- NOTE: Call manifest.json -->
<link rel="manifest" href="manifest.json">
<!-- NOTE: Load JQuery, Vue.js, VueRouter, Vuetify -->
<script src="lib/jquery-3.3.1.min.js"></script>
<script src="lib/vue-2.6.10.js"></script>
<script src="lib/vue-router-3.0.1.js"></script>
<!-- Buefy/Vuetify -->
<script src="lib/buefy-0.7.5.js"></script>
<!-- <script src="lib/buefy-0.7.5.min.js"></script>-->
<!-- NOTE: Material Icons e.g. seach -->
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.5.94/css/materialdesignicons.min.css">
<link rel="stylesheet" type="text/css" href="lib/buefy-0.7.5.css">
<!--<link rel="stylesheet" type="text/css" href="lib/buefy-0.7.5.min.css">-->
<!-- <script src="lib/vuetify-1.5.14.js"></script>-->
<!-- <script src="lib/vuetify-1.5.14.min.js"></script>-->
<!-- <link rel="stylesheet" type="text/css" href="lib/vuetify-1.5.14.css">-->
<!-- <link rel="stylesheet" type="text/css" href="lib/vuetify-1.5.14.min.css">-->
<!-- NOTE: Load .js Libraries -->
<script src="lib/vue-2.6.10.js"></script>
<script src="lib/vue-router-3.0.1.js"></script>
<script src="lib/buefy-0.7.5.js"></script>
<!-- <script src="lib/buefy-0.7.5.min.js"></script>-->
<script src="lib/jquery-3.3.1.min.js"></script>
<!-- CSS_Custom Design -->
<link rel="stylesheet" type="text/css" href="style/style.css">
<!-- NOTE: JavaScript Libs & Files -->
<script src="routes/home.js"></script>
<script src="routes/files.js"></script>
<script src="routes/createMessage.js"></script>
<script src="routes/bookmark.js"></script>
<script src="routes/profil.js"></script>
<script src="routes/msgCard.js"></script>
<script src="routes/messageData.js"></script>
<script src="routes/tagData.js"></script>
<!-- NOTE: Include .js Routes -->
<script src="routes/auth.js"></script><!-- Must load before profile.js -->
<script src="routes/home.js"></script>
<script src="routes/files.js"></script>
<script src="routes/createMessage.js"></script>
<script src="routes/bookmark.js"></script>
<script src="routes/profil.js"></script>
<script src="routes/msgCard.js"></script>
<script src="routes/messageData.js"></script>
<script src="routes/tagData.js"></script>
<script src="routes/profilCard.js"></script>
<script src="routes/profilData.js"></script>
<script src="routes/login.js"></script>
<script src="routes/navRoutes.js"></script>
<title>OHM News</title>
<script src="routes/navRoutes.js"></script>
<script src="search.js"></script>
</head>
<body>
<div id="api">
<div class="om-header-container">
<div class="om-header">
<a class="logo-img is-hidden-desktop" href="index.html"><img src="img/app_icon.png" width=45px height=45px></a>
<div id="api">
<div class="om-header-container">
<div class="om-header">
<a class="logo-img is-hidden-desktop" href="index.html"><img src="img/app_icon.png" width=45px height=45px></a>
<a class="logo-img is-hidden-touch" href="index.html"><img src="img/app_icon_desk.png" width=100px height=100px></a>
<form class="om-searchbar" @submit.prevent="search()">
<b-field>
<b-autocomplete v-model="searchtext" @keydown.native.enter="search" :data="filteredDataArray" placeholder="suche..." icon="magnify" @select="option => selected = option">
</b-autocomplete>
<button class="clearButton" @click="clear">x</button>
</b-field>
</form>
</div>
</div>
<search></search>
</div>
</div>
<div class="om-content">
<div id=xxx></div>
<nav-router></nav-router>
<router-view></router-view>
</div>
</div>
<div class="om-content">
<div id=xxx></div>
<nav-router></nav-router>
<router-view :key="auth.user"></router-view>
</div>
</div>
<script>
var isSearchActive = false;
var tagArray = ["lorem"];
const dat = [
'th',
'efi',
'wichtig',
];
<script>
new Vue({
router,
el: '#api',
components: {
// Locally registered components
},
data: {
// Locally registered variables
auth: auth,
},
computed:{
// Methods to change data appearance, does cache results
},
methods: {
// Methods to change data content, run always again
},
});
</script>
<script>
var app = new Vue({
router,
el: '#api',
data: function() {
return {
searchtext: "",
//isSearchActiv: false,
selected: [],
taglist: dat,
};
},
computed: {
filteredDataArray() {
return this.taglist.filter((option) => {
return option
.toString()
.toLowerCase()
.indexOf(this.searchtext.toLowerCase()) >= 0
})
}
},
methods: {
getFilteredTags(text) {
this.taglist = dat.filter((option) => {
return option
.toString()
.toLowerCase()
.indexOf(text.toLowerCase()) >= 0
})
this.search();
},
saveTagsToArray: function() {
tagArray = this.selected;
console.info(tagArray);
},
search: function() {
searching(this.searchtext);
},
list_messages: function() {
messages();
},
list_tags: function() {
$.ajax({
url: "api/tag/ids",
method: "GET"
})
.done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_taglist.splice(0, _taglist.length);
_taglist.push.apply(_taglist, jd);
console.log("tag: jd: " + jd);
for (var e in jd) {
if (!_tags[jd[e]]) {
get_insert_tag(jd[e]);
}
}
}).fail(function(e, f, g) {
console.log("err: " + e + f + g);
});
},
clear: function() {
console.log("clear");
isSearchActiv = false;
this.searchtext = "";
this.list_messages();
},
},
mounted: function() {
//this.search();
this.list_tags();
},
});
function get_insert_tag(id) {
$.ajax({
url: "api/tag/" + id,
method: "GET"
}).done(function(tag) {
dat.push("#" + tag.name);
console.log("it worked!");
}).fail(function(e, f, g) {
console.log("cannot load " + id + ".json: " + e + f + g);
})
}
function searching(searchtext) {
isSearchActiv = true;
console.log("Searchtext: " + searchtext.replace(/#/g, ''));
$.ajax({
url: "api/msg/search/" + searchtext.replace(/#/g, ''),
method: "GET"
}).done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
//console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
}).fail(function(e, f, g) {
console.log("searching: err: " + e + f + g);
})
}
function messages() {
$.ajax({
url: "api/msg/ids",
method: "GET"
})
.done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
//console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
}).fail(function(e, f, g) {
console.log("list_msg: err: " + e + f + g);
});
}
const search_data = [];
/*
export.default {
data: function () {
return {
selected: [],
taglist: data,
};
},
computed: {
filteredTagArray() {
this.taglist = data.filter((option) => {
return option
.toString()
.toLowerCase()
.indexOf(this.name.toLowerCase()) >= 0
})
},
},
methods: {
evaluate(text) {
this.taglist = data.filter((option) => {
return option
.toString()
.toLowerCase()
.indexOf(text.toLowerCase()) >= 0
})
},
},
mounted: function () {
if ($(this).bootstrapMaterialDesign)
$(this).bootstrapMaterialDesign();
},
};
*/
</script>
<!-- CDN_Vue.js minified lib -->
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.min.js"></script> -->
<!-- CDN_jQuery minified lib -->
<!--<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>-->
<!-- Load Popper.js -->
<script src="lib/popper-1.12.6.js"></script>
<!-- Load Bootstrap.js -->
<script src="lib/bootstrap-material-design.js"></script>
<!-- NOTE: Call main.js -->
<script src="main.js"></script>
<!-- NOTE: Call SW registration -->
<script src="registerSW.js"></script>
</body>
</html>
File diff suppressed because one or more lines are too long
+3 -9
View File
@@ -1,6 +1,6 @@
/******************************************************
* Main JavaScript file - Entry point of all JS files *
******************************************************/
/*
* Register ServiceWorker - load as last script
*/
// Wait until page loaded
window.addEventListener('load', () => {
@@ -18,9 +18,3 @@ window.addEventListener('load', () => {
return;
}*/
});
// NOTE: Set Bootstrap materialdesign
document.addEventListener("DOMContentLoaded", function () {
$('body').bootstrapMaterialDesign();
}, false);
+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');
}
}
});
+144
View File
@@ -0,0 +1,144 @@
var isSearchActive = false,
tagArray = ["lorem"];
const dat=[
'th',
'efi',
'wichtig',
],
search_data = [];
Vue.component('search',{
template: `
<form class="om-searchbar" @submit.prevent="search()">
<b-field>
<b-autocomplete
v-model="searchtext"
@keydown.native.enter="search"
:data="filteredDataArray"
placeholder="suche..."
icon="magnify"
@select="option => selected = option">
</b-autocomplete>
<button class="clearButton" @click="clear">x</button>
</b-field>
</form>`,
data: function() {
return{
searchtext: "",
selected: [],
taglist: dat,
};
},
computed:{
filteredDataArray() {
return this.taglist.filter((option) => {
return option
.toString()
.toLowerCase()
.indexOf(this.searchtext.toLowerCase()) >= 0
})
}
},
methods: {
getFilteredTags(text) {
this.taglist = dat.filter((option) => {
return option
.toString()
.toLowerCase()
.indexOf(text.toLowerCase()) >= 0
})
this.search();
},
search: function() {
searching(this.searchtext);
},
saveTagsToArray: function() {
tagArray = this.selected;
// console.info(tagArray);
},
list_messages: function() {
messages();
},
list_tags: function () {
$.ajax({url: "api/tag/ids", method: "GET"})
.done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_taglist.splice(0, _taglist.length);
_taglist.push.apply(_taglist, jd);
// console.log("tag: jd: " + jd);
for (var e in jd) {
if (!_tags[jd[e]]) {
get_insert_tag(jd[e]);
}
}
}).fail(function (e, f, g) {
console.log("err: " + e + f + g);
});
},
clear: function() {
console.log("clear");
isSearchActiv = false;
this.searchtext = "";
this.list_messages();
},
},
mounted: function() {
//this.search();
this.list_tags();
},
});
// Global Functions !!!
function get_insert_tag(id) {
$.ajax({
url: "api/tag/" + id,
method: "GET"
}).done(function(tag) {
dat.push("#" + tag.name);
}).fail(function(e, f, g) {
console.log("cannot load " + id + ".json: " + e + f + g);
})
}
function searching(searchtext) {
isSearchActiv = true;
console.log("Searchtext: " + searchtext.replace(/#/g, ''));
$.ajax({
url: "api/msg/search/" + searchtext.replace(/#/g, ''),
method: "GET"
}).done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
//console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
}).fail(function(e, f, g) {
console.log("searching: err: " + e + f + g);
})
}
function messages() {
$.ajax({
url: "api/msg/ids",
method: "GET"
})
.done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
//console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
}).fail(function(e, f, g) {
console.log("list_msg: err: " + e + f + g);
});
}