Changed .add to .create
This commit is contained in:
@@ -1,50 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const {User} = require('./user');
|
|
||||||
const {Token, AuthToken} = require('./token');
|
|
||||||
|
|
||||||
let Auth = {}
|
|
||||||
Auth.errors = {}
|
|
||||||
|
|
||||||
Auth.errors.login = function(){
|
|
||||||
let error = new Error('LoginFailed');
|
|
||||||
error.name = 'LoginFailed';
|
|
||||||
error.message = `Invalid Credentials, login failed.`;
|
|
||||||
error.status = 401;
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
Auth.login = async function(data){
|
|
||||||
try{
|
|
||||||
let user = await User.login(data);
|
|
||||||
let token = await AuthToken.add(user);
|
|
||||||
|
|
||||||
return {user, token}
|
|
||||||
}catch(error){
|
|
||||||
throw this.errors.login();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Auth.checkToken = async function(data){
|
|
||||||
try{
|
|
||||||
let token = await AuthToken.get(data);
|
|
||||||
if(token.is_valid){
|
|
||||||
return await User.get(token.created_by);
|
|
||||||
}
|
|
||||||
}catch(error){
|
|
||||||
throw this.errors.login();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Auth.logOut = async function(data){
|
|
||||||
try{
|
|
||||||
let token = await AuthToken.get(data);
|
|
||||||
await token.remove();
|
|
||||||
}catch(error){
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {Auth, AuthToken};
|
|
||||||
@@ -48,7 +48,7 @@ class Host extends Table{
|
|||||||
console.log('addCache, corrent parent?', parentOBJ.wildcard_parent || parentOBJ.host)
|
console.log('addCache, corrent parent?', parentOBJ.wildcard_parent || parentOBJ.host)
|
||||||
console.log('addCache, got parent', parentOBJ)
|
console.log('addCache, got parent', parentOBJ)
|
||||||
|
|
||||||
await this.add({
|
await this.create({
|
||||||
...parentOBJ,
|
...parentOBJ,
|
||||||
host: host,
|
host: host,
|
||||||
is_cache: true,
|
is_cache: true,
|
||||||
@@ -56,7 +56,7 @@ class Host extends Table{
|
|||||||
wildcard_parent: parentOBJ.host
|
wildcard_parent: parentOBJ.host
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
await Cached.add({
|
await Cached.create({
|
||||||
host: host,
|
host: host,
|
||||||
parent: parentOBJ.host
|
parent: parentOBJ.host
|
||||||
});
|
});
|
||||||
@@ -86,7 +86,7 @@ class Host extends Table{
|
|||||||
|
|
||||||
static async add(data, ...args){
|
static async add(data, ...args){
|
||||||
try{
|
try{
|
||||||
let out = await super.add(data, ...args)
|
let out = await super.create(data, ...args)
|
||||||
await this.buildLookUpObj()
|
await this.buildLookUpObj()
|
||||||
if(out.is_wildcard) await out.createWildcardCert()
|
if(out.is_wildcard) await out.createWildcardCert()
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ module.exports = {Host: ModelPs(Host)};
|
|||||||
try{
|
try{
|
||||||
await Host.lookUpReady();
|
await Host.lookUpReady();
|
||||||
|
|
||||||
// let res = await Host.add({
|
// let res = await Host.create({
|
||||||
// host: '*.test.holycore.quest',
|
// host: '*.test.holycore.quest',
|
||||||
// ip: '192.168.1.47',
|
// ip: '192.168.1.47',
|
||||||
// 'created_by': 'william',
|
// 'created_by': 'william',
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class AuthToken extends Token{
|
|||||||
|
|
||||||
static async add(data){
|
static async add(data){
|
||||||
data.created_by = data.username;
|
data.created_by = data.username;
|
||||||
return super.add(data)
|
return super.create(data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,71 +126,6 @@ User.exists = async function(data){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// User.add = async function(data) {
|
|
||||||
// try{
|
|
||||||
// data = objValidate.processKeys(this.keyMap, data);
|
|
||||||
// let systemUser = await linuxUser.addUser(data.username);
|
|
||||||
// await require('util').promisify(setTimeout)(500)
|
|
||||||
// let systemUserPassword = await linuxUser.setPassword(data.username, data.password);
|
|
||||||
|
|
||||||
// return this.get(data.username);
|
|
||||||
|
|
||||||
// }catch(error){
|
|
||||||
// if(error.message.includes('exists')){
|
|
||||||
// let error = new Error('UserNameUsed');
|
|
||||||
// error.name = 'UserNameUsed';
|
|
||||||
// error.message = `PAM:${data.username} already exists`;
|
|
||||||
// error.status = 409;
|
|
||||||
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// User.addByInvite = async function(data){
|
|
||||||
// try{
|
|
||||||
// let token = await InviteToken.get(data.token);
|
|
||||||
|
|
||||||
// if(!token.is_valid){
|
|
||||||
// let error = new Error('Token Invalid');
|
|
||||||
// error.name = 'Token Invalid';
|
|
||||||
// error.message = `Token is not valid or as allready been used. ${data.token}`;
|
|
||||||
// error.status = 401;
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let user = await this.add(data);
|
|
||||||
|
|
||||||
// if(user){
|
|
||||||
// await token.consume({claimed_by: user.username});
|
|
||||||
// return user;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }catch(error){
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
// User.remove = async function(data){
|
|
||||||
// try{
|
|
||||||
// return await linuxUser.removeUser(this.username);
|
|
||||||
// }catch(error){
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// User.setPassword = async function(data){
|
|
||||||
// try{
|
|
||||||
// await linuxUser.setPassword(this.username, data.password);
|
|
||||||
|
|
||||||
// return this;
|
|
||||||
// }catch(error){
|
|
||||||
// throw error;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
User.invite = async function(){
|
User.invite = async function(){
|
||||||
try{
|
try{
|
||||||
let token = await InviteToken.add({created_by: this.username});
|
let token = await InviteToken.add({created_by: this.username});
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ User.exists = async function(data){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
User.add = async function(data) {
|
User.create = async function(data) {
|
||||||
try{
|
try{
|
||||||
data = objValidate.processKeys(this.keyMap, data);
|
data = objValidate.processKeys(this.keyMap, data);
|
||||||
let systemUser = await linuxUser.addUser(data.username);
|
let systemUser = await linuxUser.addUser(data.username);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class User extends Table{
|
|||||||
data['backing'] = data['backing'] || 'redis';
|
data['backing'] = data['backing'] || 'redis';
|
||||||
|
|
||||||
|
|
||||||
return await super.add(data)
|
return await super.create(data)
|
||||||
|
|
||||||
}catch(error){
|
}catch(error){
|
||||||
throw error;
|
throw error;
|
||||||
@@ -44,7 +44,7 @@ class User extends Table{
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = await this.add(data);
|
let user = await this.create(data);
|
||||||
|
|
||||||
if(user){
|
if(user){
|
||||||
await token.consume({claimed_by: user.username});
|
await token.consume({claimed_by: user.username});
|
||||||
@@ -69,7 +69,7 @@ class User extends Table{
|
|||||||
|
|
||||||
/* async invite(){
|
/* async invite(){
|
||||||
try{
|
try{
|
||||||
let token = await InviteToken.add({created_by: this.username});
|
let token = await InviteToken.create({created_by: this.username});
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ module.exports = {User};
|
|||||||
let user = await User.get(defaultUser);
|
let user = await User.get(defaultUser);
|
||||||
}catch(error){
|
}catch(error){
|
||||||
try{
|
try{
|
||||||
let user = await User.add({
|
let user = await User.create({
|
||||||
username:defaultUser,
|
username:defaultUser,
|
||||||
password: defaultUser,
|
password: defaultUser,
|
||||||
created_by:defaultUser
|
created_by:defaultUser
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ router.get('/', async function(req, res, next){
|
|||||||
router.post('/', async function(req, res, next){
|
router.post('/', async function(req, res, next){
|
||||||
try{
|
try{
|
||||||
req.body.created_by = req.user.username;
|
req.body.created_by = req.user.username;
|
||||||
let item = await Model.add(req.body);
|
let item = await Model.create(req.body);
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
message: `"${item[Model._key]}" added.`,
|
message: `"${item[Model._key]}" added.`,
|
||||||
|
|||||||
@@ -83,11 +83,7 @@ class Table{
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async create(...args){
|
static async create(data){
|
||||||
return this.add(...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async add(data){
|
|
||||||
// Add a entry to this redis table.
|
// Add a entry to this redis table.
|
||||||
try{
|
try{
|
||||||
// Validate the passed data by the keyMap schema.
|
// Validate the passed data by the keyMap schema.
|
||||||
@@ -140,7 +136,7 @@ class Table{
|
|||||||
|
|
||||||
// Create a new record for the updated entry. If that succeeds,
|
// Create a new record for the updated entry. If that succeeds,
|
||||||
// delete the old recored
|
// delete the old recored
|
||||||
let newObject = await this.constructor.add(newData);
|
let newObject = await this.constructor.create(newData);
|
||||||
|
|
||||||
if(newObject){
|
if(newObject){
|
||||||
await this.remove();
|
await this.remove();
|
||||||
|
|||||||
@@ -110,8 +110,8 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.subscribe(/./g, function(data, topic){
|
app.subscribe(/^model:Host/, function(data, topic){
|
||||||
console.log('topic', data);
|
console.log(topic, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
//search bar html event logic stolen from here
|
//search bar html event logic stolen from here
|
||||||
@@ -299,7 +299,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-header actionMessage" style="display:none"></div>
|
<div class="card-header actionMessage" style="display:none"></div>
|
||||||
<div class="card-header search-wrapper">
|
<div class="card-body search-wrapper">
|
||||||
<label class="control-label" for="search" style="margin-left: -5px;">Search Hosts: </label>
|
<label class="control-label" for="search" style="margin-left: -5px;">Search Hosts: </label>
|
||||||
<input type="search" id="search" host-search>
|
<input type="search" id="search" host-search>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
<div class="row" style="display:none">
|
<div class="row" style="display:none">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="card shadow-lg">
|
<div class="card shadow-lg">
|
||||||
|
|
||||||
<div class="card-header text-center">
|
<div class="card-header text-center">
|
||||||
<span class="card-icon float-start">
|
<span class="card-icon float-start">
|
||||||
<i class="fa-solid fa-user-plus"></i>
|
<i class="fa-solid fa-user-plus"></i>
|
||||||
@@ -83,7 +83,10 @@
|
|||||||
<label class="control-label">Again</label>
|
<label class="control-label">Again</label>
|
||||||
<input type="password" class="form-control" name="passwordMatch" placeholder="Retype password" validate="eq:password"/>
|
<input type="password" class="form-control" name="passwordMatch" placeholder="Retype password" validate="eq:password"/>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" onclick="formAJAX(this)" class="btn btn-info">Add</button>
|
<hr />
|
||||||
|
<button type="button" onclick="formAJAX(this)" class="btn btn-info">
|
||||||
|
Add
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user