package.json and .js files added.

master
Luka Vandervelden 4 years ago
parent d881a4e948
commit 6938e01eae

@ -0,0 +1,137 @@
// Generated by LiveScript 1.6.0
(function(){
var bulma, h, AuthWS;
bulma = require("./bulma.ls");
h = require('maquette').h;
AuthWS = function(socketUrl){
var self, requestTypes, responseTypes, key, value;
self = {};
requestTypes = {
"get-token": 0,
"add-user": 1,
"get-user": 2,
"get-user-by-credentials": 3,
"mod-user": 4,
"register": 5,
"get-extra": 6,
"set-extra": 7,
"update-password": 8,
"list-users": 9
};
responseTypes = {
"error": 0,
"token": 1,
"user": 2,
"user-added": 3,
"user-edited": 4,
"extra": 5,
"extra-updated": 6,
"users-list": 7
};
self.userOnSocketError = [];
self.userOnSocketClose = [];
self.callbacks = {};
for (key in responseTypes) {
value = responseTypes[key];
self.callbacks[value] = [];
}
self.addEventListener = function(type, callback){
var ref$;
type = responseTypes[type];
return (ref$ = self.callbacks)[type] = ref$[type].concat([callback]);
};
self.openSocket = function(){
self.socket = new WebSocket(socketUrl);
self.socket.onerror = function(event){
var i$, ref$, len$, f;
for (i$ = 0, len$ = (ref$ = self.userOnSocketError).length; i$ < len$; ++i$) {
f = ref$[i$];
f(event);
}
return self.socket.close();
};
self.socket.onclose = function(event){
var i$, ref$, len$, f, results$ = [];
for (i$ = 0, len$ = (ref$ = self.userOnSocketClose).length; i$ < len$; ++i$) {
f = ref$[i$];
results$.push(f(event));
}
return results$;
};
return self.socket.onmessage = function(event){
var message, i$, ref$, len$, f, results$ = [];
message = JSON.parse(event.data);
for (i$ = 0, len$ = (ref$ = self.callbacks[message.mtype]).length; i$ < len$; ++i$) {
f = ref$[i$];
results$.push(f(JSON.parse(message.payload)));
}
return results$;
};
};
self.reopen = function(){
self.socket.close();
return self.openSocket();
};
self.openSocket();
self.send = function(type, opts){
return self.socket.send(JSON.stringify({
mtype: type,
payload: opts
}));
};
self.getToken = function(login, password){
return self.send(requestTypes['get-token'], JSON.stringify({
login: login,
password: password
}));
};
self.getUserByCredentials = function(login, password){
return self.send(requestTypes['get-user-by-credentials'], JSON.stringify({
login: login,
password: password
}));
};
self.login = function(login, password){
self.getToken(login, password);
return self.getUserByCredentials(login, password);
};
self.getUser = function(uid){
return self.send(requestTypes['get-user'], JSON.stringify({
uid: uid
}));
};
self.register = function(login, password){
return self.send(requestTypes['register'], JSON.stringify({
login: login,
password: password
}));
};
self.getExtra = function(token, name){
return self.send(requestTypes['get-extra'], JSON.stringify({
token: token,
name: name
}));
};
self.setExtra = function(token, name, extra){
return self.send(requestTypes['set-extra'], JSON.stringify({
token: token,
name: name,
extra: extra
}));
};
self.updatePassword = function(login, oldPassword, newPassword){
return self.send(requestTypes['update-password'], JSON.stringify({
login: login,
old_password: oldPassword,
new_password: newPassword
}));
};
self.listUsers = function(token){
return self.send(requestTypes['list-users'], JSON.stringify({
token: token
}));
};
return self;
};
module.exports = AuthWS;
}).call(this);

@ -0,0 +1,39 @@
// Generated by LiveScript 1.6.0
(function(){
var h;
h = require('maquette').h;
module.exports = {
box: function(args, children){
return h('div.box', args, children);
},
title: function(level, args, label){
if (!label) {
label = args;
args = {};
}
return h("div.title.is-" + level, args, [label]);
},
label: function(args, label){
if (!label) {
label = args;
args = {};
}
return h('label.label', args, [label]);
},
input: function(args, children){
return h('input.input', args, children);
},
field: function(args, children){
return h('div.field', args, children);
},
modal: function(args, content){
return h('div.modal', args, [h('div.modal-background', args.background), h('div.modal-content', [args.content])]);
},
form: function(method, url, content){
return h('form.form', {
action: url,
method: method
}, content);
}
};
}).call(this);

@ -0,0 +1,67 @@
// Generated by LiveScript 1.6.0
(function(){
var maquette, createProjector, h, projector, bulma, AuthWS, LoginForm, UserConfigurationPanel, UserAdminPanel, model, authwsUrl;
maquette = require("maquette");
createProjector = maquette.createProjector, h = maquette.h;
projector = createProjector();
bulma = require("./bulma.ls");
AuthWS = require("./authws.ls");
LoginForm = require("./login-form.ls");
UserConfigurationPanel = require("./user-configuration-panel.ls");
UserAdminPanel = require("./user-admin-panel.ls");
model = {
token: void 8
};
authwsUrl = "ws://localhost:9999/auth.JSON";
document.addEventListener('DOMContentLoaded', function(){
var userConfigPanel, userAdminPanel, loginForm;
userConfigPanel = void 8;
userAdminPanel = void 8;
loginForm = LoginForm({
enableRegistration: true,
authwsUrl: authwsUrl,
onLogin: function(user, token){
model.user = user;
model.token = token;
if (false) {
userAdminPanel = UserAdminPanel({
authwsUrl: authwsUrl,
user: model.user,
token: model.token,
onModelUpdate: function(){
return projector.scheduleRender();
},
onLogout: function(){
model.token = void 8;
return model.user = void 8;
}
});
} else {
userConfigPanel = UserConfigurationPanel({
authwsUrl: authwsUrl,
user: model.user,
token: model.token,
onModelUpdate: function(){
return projector.scheduleRender();
},
onLogout: function(){
model.token = void 8;
return model.user = void 8;
}
});
}
return projector.scheduleRender();
},
onError: function(error){
return projector.scheduleRender();
}
});
return projector.append(document.body, function(){
return h('div.body', [model.token === void 8
? h('div.section.hero.is-fullheight', [h('div.hero-body', [h('div.container', [h('div.columns', [h('div.column', []), h('div.column.is-3', [loginForm.render()]), h('div.column', [])])])])])
: userConfigPanel
? h('div.section', [h('div.container', [userConfigPanel.render()])])
: userAdminPanel ? h('div.section', [h('div.container', [userAdminPanel.render()])]) : void 8]);
});
});
}).call(this);

@ -0,0 +1,179 @@
// Generated by LiveScript 1.6.0
(function(){
var maquette, h, bulma, AuthWS, LoginForm;
maquette = require("maquette");
h = maquette.h;
bulma = require("./bulma.ls");
AuthWS = require("./authws.ls");
LoginForm = function(args){
var self, authWs;
args || (args = {});
self = {
onLogin: args.onLogin || function(){},
onError: args.onError || function(){},
scheduleRender: args.scheduleRender || function(){},
currentView: "login",
enableRegistration: args.enableRegistration || false,
registrating: false,
input: {
login: "",
password: "",
repeatPassword: ""
},
lockedInput: true,
error: void 8,
authwsUrl: args.authwsUrl || (location.protocol === 'https' ? 'wss' : 'ws') + '://' + location.hostname + ":9999/auth.JSON"
};
authWs = AuthWS(self.authwsUrl);
authWs.socket.onopen = function(){
console.log("socket is open");
self.lockedInput = false;
return self.scheduleRender();
};
authWs.userOnSocketError.push(function(){
self.error = "socket error";
return self.onError.apply(this, arguments);
});
authWs.addEventListener('token', function(message){
self.error = void 8;
self.token = message.token;
self.lockedInput = false;
if (self.user) {
return self.onLogin(self.user, self.token);
}
});
authWs.addEventListener('user', function(message){
self.error = void 8;
self.user = message.user;
if (self.token) {
return self.onLogin(self.user, self.token);
}
});
authWs.addEventListener('user-added', function(message){
var ref$, login, password;
ref$ = {
login: self.input.login,
password: self.input.password
}, login = ref$.login, password = ref$.password;
console.log("user added, duh");
self.user = message.user;
return authWs.getToken(login, password);
});
authWs.addEventListener('error', function(message){
if (message.reason === "user not found") {
return;
}
self.error = message.reason;
self.lockedInput = false;
return self.onError(message.reason);
});
self.render = function(){
if (self.error === "socket error") {
return h('div.notification.is-danger', [h('div.title.is-4', ["WebSocket error!"]), h('p', ["Cannot connect to authd."])]);
}
return h('form.form.login-form', {
key: self,
onsubmit: function(e){
var ref$, login, password;
ref$ = {
login: self.input.login,
password: self.input.password
}, login = ref$.login, password = ref$.password;
self.lockedInput = true;
if (self.registrating) {
authWs.register(login, password);
} else {
authWs.getToken(login, password);
authWs.getUserByCredentials(login, password);
}
return e.preventDefault();
}
}, [
h('div.field', {
key: 'login'
}, [
bulma.label("Login"), bulma.input({
type: "text",
id: "login",
name: "login",
classes: {
"is-danger": self.error === "invalid credentials"
},
disabled: self.lockedInput,
oninput: function(e){
return self.input.login = e.target.value;
}
})
]), h('div.field', {
key: 'password'
}, [
bulma.label("Password"), bulma.input({
type: "password",
id: "password",
name: "password",
classes: {
"is-danger": self.error === "invalid credentials"
},
oninput: function(e){
return self.input.password = e.target.value;
},
disabled: self.lockedInput
})
]), self.registrating ? h('div.field', {
key: 'password-repeat'
}, [
bulma.label("Password (reapeat)"), bulma.input({
type: 'password',
id: 'password-repeat',
name: 'password-repeat',
classes: {
"is-danger": self.input.password !== self.input.repeatPassword
},
disabled: self.lockedInput,
oninput: function(e){
return self.input.repeatPassword = e.target.value;
}
})
]) : void 8, self.error ? h('div.field', {
key: 'error-notification'
}, [h('div.notification.is-danger', [self.error])]) : void 8, self.registrating
? h('div.field.is-grouped', {
key: 'login-button'
}, [self.input.login === ""
? h('button.button.is-static.is-fullwidth', {
type: 'submit'
}, ["(empty login)"])
: self.input.password !== self.input.repeatPassword
? h('button.button.is-static.is-fullwidth', {
type: 'submit'
}, ["(passwords dont match)"])
: self.input.password === ""
? h('button.button.is-static.is-fullwidth', {
type: 'submit'
}, ["(empty password)"])
: h('button.button.is-success.is-fullwidth', {
type: 'submit'
}, ["Register!"])])
: h('div.field.is-grouped', {
key: 'login-button'
}, [h('button.button.is-fullwidth.is-success', {
type: 'submit'
}, ["Log in!"])]), h('div.field.level', {
key: 'extra-buttons'
}, [self.enableRegistration ? h('div.level-right', [self.registrating
? h('a.link', {
onclick: function(e){
return self.registrating = false;
}
}, ["Log in"])
: h('a.link', {
onclick: function(e){
return self.registrating = true;
}
}, ["Create account!"])]) : void 8])
]);
};
return self;
};
module.exports = LoginForm;
}).call(this);

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -0,0 +1,15 @@
{
"name": "authd-maquettec",
"version": "0.1.0",
"description": "maquette client for authd",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.karchnu.fr/WeirdOS/authd-maquettec"
},
"author": "",
"license": "ISC"
}

@ -0,0 +1,48 @@
// Generated by LiveScript 1.6.0
(function(){
var h, AuthWS, UserAdminPanel;
h = require("maquette").h;
AuthWS = require("./authws.ls");
UserAdminPanel = function(args){
var self, authws;
self = {
token: args.token,
authwsUrl: args.authwsUrl,
onLogout: args.onLogout || function(){},
onModelUpdate: args.onModelUpdate || function(){},
users: []
};
authws = AuthWS(self.authwsUrl);
authws.socket.onopen = function(){
return authws.listUsers(self.token);
};
authws.addEventListener('users-list', function(message){
self.users = message.users;
return self.onModelUpdate();
});
self.render = function(){
var user;
return h('div.section', [
h('div.container', [h('table.table.is-fullwidth', [
h('thead', [h('tr', [h('th', ["Login"]), h('th', ["UID"]), h('th', ["GID"])])]), h('tbody', [(function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = self.users).length; i$ < len$; ++i$) {
user = ref$[i$];
results$.push(h('tr', {
key: user.uid
}, [h('td', [user.login]), h('td', [user.uid.toString()]), h('td', [user.gid.toString()])]));
}
return results$;
}())])
])]), h('div.button', {
onclick: function(){
self.onLogout();
return self.onModelUpdate();
}
}, ["Log out"])
]);
};
return self;
};
module.exports = UserAdminPanel;
}).call(this);

@ -0,0 +1,222 @@
// Generated by LiveScript 1.6.0
(function(){
var h, AuthWS, getFullName, defaultSideBarRenderer, defaultHeadingRenderer, Fields, UserConfigurationPanel;
h = require("maquette").h;
AuthWS = require("./authws.ls");
getFullName = function(self){
var fullName, ref$;
fullName = ((ref$ = self.profile) != null ? ref$.fullName : void 8) || "";
if (fullName === "") {
return self.user.login;
} else {
return fullName;
}
};
defaultSideBarRenderer = function(self){
var avatar, ref$;
return h('div', {
key: 'side-bar'
}, [h('figure.image.is-128x128.is-clipped', [(avatar = (ref$ = self.profile) != null ? ref$.avatar : void 8) ? h('img', {
src: avatar,
alt: "Avatar of " + getFullName(self)
}) : void 8])]);
};
defaultHeadingRenderer = function(self){
var fullName;
fullName = getFullName(self);
return h('div.section', {
key: 'heading'
}, [h('div.media', [
h('div.media-content', [h('div.title.is-2', [fullName]), fullName !== self.user.login ? h('div.title.is-3.subtitle', [self.user.login]) : void 8]), self.onLogout ? h('div.media-right', [h('a', {
onclick: function(){
return self.onLogout();
}
}, ["Logout"])]) : void 8
])]);
};
Fields = {
renderTextInput: function(token, authWs, key, inputs, model, onRequest){
var upload;
upload = function(){
var payload, _key, ref$, value;
console.log("clickity click", key, inputs[key], inputs);
if (!inputs[key]) {
return;
}
payload = {};
for (_key in ref$ = model) {
value = ref$[_key];
payload[_key] = value;
}
payload[key] = inputs[key];
inputs[key] = void 8;
onRequest();
return authWs.setExtra(token, "profile", payload);
};
return h('div.field.has-addons', {
key: key
}, [
h('div.control.is-expanded', [h('input.input', {
value: inputs[key] || model[key],
oninput: function(e){
console.log("input for", key);
return inputs[key] = e.target.value;
}
})]), h('div.control', [h('div.button', {
onclick: upload
}, ["Update"])])
]);
}
};
UserConfigurationPanel = function(args){
var self, authWs;
self = {
user: args.user || {},
profile: args.profile,
token: args.token,
authwsUrl: args.authwsUrl || (location.protocol === 'https' ? 'wss' : 'ws') + '://' + location.hostname + ":9999/auth.JSON",
sideBarRenderer: args.sideBarRenderer || defaultSideBarRenderer,
headingRenderer: args.headingRenderer || defaultHeadingRenderer,
onModelUpdate: args.onModelUpdate || function(){},
onLogout: args.onLogout || void 8,
model: args.model || [["fullName", "Full Name", "string"], ["avatar", "Profile Picture", "image-url"], ["email", "Mail Address", "string"]],
input: {}
};
authWs = AuthWS(self.authwsUrl);
authWs.addEventListener('extra', function(message){
if (message.name === "profile") {
console.log("got profile", message.extra);
self.profile = message.extra || {};
return self.onModelUpdate();
}
});
authWs.addEventListener('extra-updated', function(message){
if (message.name === "profile") {
console.log("got profile", message.extra);
self.profile = message.extra || {};
return self.onModelUpdate();
}
});
authWs.addEventListener('error', function(message){
self.error = message.reason;
return self.onModelUpdate();
});
authWs.addEventListener('user-edited', function(message){
self.input["password.old"] = void 8;
self.input["password.new"] = void 8;
self.input["password.new2"] = void 8;
self.success = "password";
return self.onModelUpdate();
});
if (!self.profile) {
authWs.socket.onopen = function(){
return authWs.getExtra(self.token, "profile");
};
}
self.render = function(){
var element, key, label, type, service, permissions;
return h('div.columns', {
key: self
}, [
h('div.column.is-narrow', [self.sideBarRenderer(self)]), h('div.column', [
self.headingRenderer(self), self.profile
? h('div.box', {
key: 'profile'
}, [h('div.form', [
h('div.title.is-4', ["Profile"]), (function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = self.model).length; i$ < len$; ++i$) {
element = ref$[i$];
key = element[0], label = element[1], type = element[2];
switch (type) {
case "string":
case "image-url":
results$.push(h('div.field', {
key: key
}, [h('div.label', [label]), Fields.renderTextInput(self.token, authWs, key, self.input, self.profile, fn$)]));
}
}
return results$;
function fn$(){
return self.error = void 8;
}
}())
])])
: h('div.button.is-loading'), h('div.box', {
key: 'password'
}, [
h('div.title.is-4', ["Password"]), h('div.label', ["Old password"]), h('div.control', [
h('input.input', {
type: 'password',
value: self.input["password.old"],
oninput: function(e){
return self.input["password.old"] = e.target.value;
}
}), self.error === "invalid credentials" ? h('div.help.is-danger', ["The old password was invalid!"]) : void 8
]), h('div.label', ["New password"]), h('div.control', [h('input.input', {
type: 'password',
value: self.input["password.new"],
oninput: function(e){
return self.input["password.new"] = e.target.value;
}
})]), h('div.label', ["New password (repeat)"]), h('div.field.has-addons', [
h('div.control.is-expanded', [h('input.input', {
type: 'password',
value: self.input["password.new2"],
oninput: function(e){
return self.input["password.new2"] = e.target.value;
}
})]), h('div.control', [h('div.button', {
classes: {
"is-danger": self.input["password.new"] && self.input["password.new"] !== self.input["password.new2"],
"is-static": !self.input["password.new"] && self.input["password.new"] !== self.input["password.new2"]
},
onclick: function(){
if (self.input["password.new"] !== self.input["password.new2"]) {
return;
}
self.error = void 8;
return authWs.updatePassword(self.user.login, self.input["password.old"], self.input["password.new"]);
}
}, ["Update"])])
]), self.success === "password" ? h('div.help.is-success', ["Password successfully updated!"]) : void 8
]), self.showDeveloper
? h('div.box', {
key: 'passwd'
}, [
h('div.title.is-4', ["Permissions"]), h('div.form', [
h('div.field', {
key: 'uid'
}, [h('div.label', ["User ID"]), h('div.control', [self.user.uid.toString()])]), h('div.field', {
key: 'gid'
}, [h('div.label', ["Group ID"]), h('div.control', [self.user.gid.toString()])]), h('div.field', {
key: 'permissions'
}, [
h('div.label', ["Permissions"]), h('div.control.is-grouped', [h('div.tags', [(function(){
var ref$, results$ = [];
for (service in ref$ = self.user.permissions) {
permissions = ref$[service];
results$.push(permissions.map(fn$));
}
return results$;
function fn$(perm){
return h('div.tag', [service, permission]);
}
}())])])
])
])
])
: h('a.is-pulled-right.is-small.has-text-grey', {
key: 'passwd',
onclick: function(){
self.showDeveloper = true;
return self.onModelUpdate();
}
}, ["Show developer data!"])
])
]);
};
return self;
};
module.exports = UserConfigurationPanel;
}).call(this);
Loading…
Cancel
Save