|
@@ -21,32 +21,75 @@ Vue.use(vueDebounce);
|
|
|
new Vue({
|
|
|
render: h => h(App),
|
|
|
created: function () {
|
|
|
- this.socket.on('edit-project', project => {
|
|
|
- if (this.project && this.project.identifier === project.identifier) {
|
|
|
- this.project = project;
|
|
|
- }
|
|
|
- });
|
|
|
- this.socket.on('remove-project', project => {
|
|
|
- if (this.project && this.project.identifier === project.identifier) {
|
|
|
- this.project = null;
|
|
|
- }
|
|
|
+ this.socket.on('edit-project', project => {
|
|
|
+ if (this.project && this.project.identifier === project.identifier) {
|
|
|
+ this.project = project;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.socket.on('remove-project', project => {
|
|
|
+ if (this.project && this.project.identifier === project.identifier) {
|
|
|
+ this.project = null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.socket.on('connect', () => this.connected = true);
|
|
|
+ setInterval(() => this.connected = sio.connected, 1000);
|
|
|
+ },
|
|
|
+
|
|
|
+ mounted: function(){
|
|
|
+ if(localStorage.credentials){
|
|
|
+ this.credentials = JSON.parse(localStorage.credentials);
|
|
|
+
|
|
|
+
|
|
|
+ if(this.credentials.username != null)
|
|
|
+ this.login();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ this.credentials = {username: null, password: null}
|
|
|
+ },
|
|
|
+
|
|
|
+ methods: {
|
|
|
+ authenticate: function(username, password){
|
|
|
+ let creds = {username, password}
|
|
|
+ this.credentials = creds;
|
|
|
+
|
|
|
+ this.login( (resp) => {
|
|
|
+ if (resp.status === 200);
|
|
|
+ localStorage.credentials = JSON.stringify(creds);
|
|
|
});
|
|
|
|
|
|
- this.socket.on('connect', () => this.connected = true);
|
|
|
- setInterval(() => this.connected = sio.connected, 1000);
|
|
|
+ },
|
|
|
+ login: function(callback){
|
|
|
+
|
|
|
+ this.socket.username = this.credentials.username;
|
|
|
+ this.socket.password = this.credentials.password;
|
|
|
+
|
|
|
+ return this.socket.authenticate(callback);
|
|
|
+ },
|
|
|
+ logout: function(){
|
|
|
+ localStorage.removeItem("credentials");
|
|
|
+ this.credentials = {username: null, password: null}
|
|
|
+ this.socket.logout();
|
|
|
+ },
|
|
|
},
|
|
|
data: function () {
|
|
|
return {
|
|
|
project: null,
|
|
|
connected: false,
|
|
|
+ credentials: null,
|
|
|
socket: {
|
|
|
username: null,
|
|
|
password: null,
|
|
|
+
|
|
|
authenticated: false,
|
|
|
latestErrorTxt: "",
|
|
|
+
|
|
|
headers: function () {
|
|
|
const authHeaders = new Headers();
|
|
|
- authHeaders.set('Authorization', 'Basic ' + window.btoa(this.username + ":" + this.password));
|
|
|
+ authHeaders.set('Authorization',
|
|
|
+ 'Basic ' + window.btoa(this.username + ":" + this.password));
|
|
|
+ console.log(authHeaders.get("Authorization"));
|
|
|
return authHeaders;
|
|
|
},
|
|
|
url: function (name) {
|
|
@@ -95,27 +138,33 @@ new Vue({
|
|
|
body: form
|
|
|
});
|
|
|
},
|
|
|
- authenticate: function () {
|
|
|
+
|
|
|
+ authenticate: function (callback) {
|
|
|
+
|
|
|
if (this.username == "" && this.password == "") {
|
|
|
this.latestErrorTxt = "Please enter a valid username and password!";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ console.log("Sock:auth", this.username, this.password)
|
|
|
this.get('/authenticate')
|
|
|
.then((response) => {
|
|
|
this.authenticated = (response.status === 200);
|
|
|
- if (!this.authenticated) {
|
|
|
+ if (!this.authenticated)
|
|
|
this.latestErrorTxt = "Invalid username or password!";
|
|
|
- }
|
|
|
+ else if (callback)
|
|
|
+ callback(response)
|
|
|
});
|
|
|
return this.authenticated;
|
|
|
},
|
|
|
+
|
|
|
logout: function () {
|
|
|
this.authenticated = false;
|
|
|
this.username = null;
|
|
|
this.password = null;
|
|
|
this.latestErrorTxt = "";
|
|
|
},
|
|
|
+
|
|
|
media: function (file, maxWidth, maxHeight) {
|
|
|
if (maxHeight)
|
|
|
return `${self}/data/${file.identifier}/${maxWidth}x${maxHeight}?uuid=${file.uuid}`
|