WIP reorganization
This commit is contained in:
1 parent
6706dfe634
commit
054e37dfb7
266 files changed
+98
-620
No files matched your search
@@ -0,0 +1 @@
|
||||
require('../imports/client/index.js');
|
||||
@@ -0,0 +1,54 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
// Throw error if there is no user logged in
|
||||
OHIF.user.validate = () => {
|
||||
if (!OHIF.user.userLoggedIn()) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
};
|
||||
|
||||
// Get the persistent data by key
|
||||
OHIF.user.getData = key => {
|
||||
// Check if there is an user logged in
|
||||
OHIF.user.validate();
|
||||
|
||||
// Get the user object
|
||||
const user = Meteor.user();
|
||||
|
||||
// Get user profile data
|
||||
const profile = user && user.profile;
|
||||
|
||||
// Get the user persistent data
|
||||
const data = profile && profile.persistent;
|
||||
|
||||
let result = data;
|
||||
const keys = key.split('.');
|
||||
keys.forEach(key => {
|
||||
if (typeof result !== 'object' || !result) return;
|
||||
result = result[key];
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// Store the persistent data by giving a key and a value to store
|
||||
OHIF.user.setData = (key, value) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
// Check if there is an user logged in
|
||||
OHIF.user.validate();
|
||||
} catch(error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
// Call the update method on server-side
|
||||
Meteor.call('ohif.user.data.set', key, value, error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.user.getAccessToken = () => {};
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.user.getName = () => {
|
||||
const user = Meteor.user();
|
||||
if (!user) return '';
|
||||
const nameSplit = user.profile.fullName.split(' ');
|
||||
const lastName = nameSplit[nameSplit.length - 1];
|
||||
nameSplit[nameSplit.length - 1] = lastName.substr(0, 1) + '.';
|
||||
return nameSplit.join(' ');
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.user.getUserId = () => Meteor.userId();
|
||||
@@ -0,0 +1,10 @@
|
||||
import './data';
|
||||
import './getName';
|
||||
import './getUserId';
|
||||
import './getAccessToken';
|
||||
import './login';
|
||||
import './logout';
|
||||
import './schema';
|
||||
import './userLoggedIn';
|
||||
|
||||
import './userLogin/'
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.user.login = params => {
|
||||
return new Promise((resolve, reject) => {
|
||||
Meteor.loginWithPassword(params.username, params.password, error => {
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.user.logout = () => new Promise((resolve, reject) => {
|
||||
Meteor.logout(error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Meteor } from "meteor/meteor";
|
||||
import { Router } from 'meteor/clinical:router';
|
||||
|
||||
if (Meteor.settings.public.userAuthenticationRoutesEnabled === true) {
|
||||
Router.route('/login', function() {
|
||||
this.layout('layout', { data: {} });
|
||||
this.render('userLogin');
|
||||
}, { name: 'userLogin' });
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { ReactiveVar } from 'meteor/reactive-var';
|
||||
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
||||
|
||||
OHIF.user.schema = new ReactiveVar(new SimpleSchema({
|
||||
username: {
|
||||
type: String,
|
||||
label: 'Username'
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
label: 'Password'
|
||||
}
|
||||
}));
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.user.userLoggedIn = () => !!Meteor.userId();
|
||||
@@ -0,0 +1,3 @@
|
||||
import './userLogin.html';
|
||||
import './userLogin.js';
|
||||
import './userLogin.styl';
|
||||
@@ -0,0 +1,23 @@
|
||||
<template name="userLogin">
|
||||
<div class="user-login">
|
||||
{{>section 'userLoginBefore'}}
|
||||
<div class="user-login-box">
|
||||
<div class="user-login-logo">{{>section 'userLoginLogo'}}</div>
|
||||
{{#form class='user-login-form form-themed p-a-2' schema=instance.schema api=instance.api hideValidationBox=true}}
|
||||
<h3>Sign In</h3>
|
||||
<hr class="m-h-2">
|
||||
{{>section 'userLoginFieldsBefore'}}
|
||||
{{>inputText labelClass='form-group' key='username'}}
|
||||
{{>inputPassword labelClass='form-group' key='password'}}
|
||||
{{>section 'userLoginFieldsAfter'}}
|
||||
<hr class="m-t-0 m-b-2">
|
||||
{{#button action='login' class='form-control btn btn-primary'}}Enter{{/button}}
|
||||
|
||||
{{ #each additionalLoginButtons }}
|
||||
{{>Template.dynamic template=template}}
|
||||
{{ /each }}
|
||||
{{/form}}
|
||||
</div>
|
||||
{{>section 'userLoginAfter'}}
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Template } from 'meteor/templating';
|
||||
import { Router } from 'meteor/clinical:router';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Template.userLogin.onCreated(() => {
|
||||
const instance = Template.instance();
|
||||
|
||||
instance.api = {
|
||||
login() {
|
||||
// Check if the form has valid data
|
||||
const form = instance.$('form').data('component');
|
||||
if (!form.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the form data
|
||||
const formData = form.value();
|
||||
|
||||
// Handle errors and display the error message on the respective field
|
||||
const errorHandler = error => {
|
||||
const reason = (error && error.reason) || 'An error has ocurred';
|
||||
const isPassword = reason && reason.toLowerCase().indexOf('password') > -1;
|
||||
const displayComponent = form.item(isPassword ? 'password' : 'username');
|
||||
displayComponent.error(reason);
|
||||
Meteor.defer(() => displayComponent.$element.focus());
|
||||
};
|
||||
|
||||
// Call the login method
|
||||
return OHIF.user.login(formData).catch(errorHandler);
|
||||
}
|
||||
};
|
||||
|
||||
instance.schema = OHIF.user.schema;
|
||||
});
|
||||
|
||||
Template.userLogin.helpers({
|
||||
additionalLoginButtons() {
|
||||
return OHIF.user.additionalLoginButtons || [];
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,80 @@
|
||||
@import "{ohif:design}/app"
|
||||
|
||||
html, body
|
||||
height: 100%
|
||||
|
||||
.user-login
|
||||
theme('color', '$textPrimaryColor')
|
||||
height: 100%
|
||||
position: relative
|
||||
overflow: hidden
|
||||
|
||||
&:before, &:after
|
||||
bottom: 0
|
||||
content: ''
|
||||
display: block
|
||||
left: 0
|
||||
position: absolute
|
||||
width: 100%
|
||||
|
||||
&:before
|
||||
theme('background-color', '$primaryBackgroundColor')
|
||||
height: 100%
|
||||
z-index: 1
|
||||
|
||||
&:after
|
||||
theme('background-color', '$uiGrayDark')
|
||||
animation(login-bg 0.5s ease 0.5s forwards)
|
||||
bottom: -50%
|
||||
height: 50%
|
||||
z-index: 2
|
||||
|
||||
.user-login-box
|
||||
animation(login-box 0.5s forwards)
|
||||
left: 50%
|
||||
position: absolute
|
||||
width: 300px
|
||||
z-index: 3
|
||||
|
||||
.user-login-logo
|
||||
animation(login-logo 0.5s ease 0.5s forwards)
|
||||
left: 0
|
||||
position: absolute
|
||||
top: 0
|
||||
width: 100%
|
||||
z-index: 1
|
||||
|
||||
.user-login-form
|
||||
theme('background-color', '$uiGrayDarkest')
|
||||
theme('border', '1px solid $uiBorderColor')
|
||||
theme('color', '$textPrimaryColor')
|
||||
border-radius: 3px
|
||||
position: relative
|
||||
z-index: 2
|
||||
|
||||
h3
|
||||
margin: 0
|
||||
text-align: center
|
||||
|
||||
.btn-primary
|
||||
font-weight: bold
|
||||
|
||||
@keyframes login-box
|
||||
from
|
||||
top: 100%
|
||||
transform(translateX(-50%) translateY(0%))
|
||||
to
|
||||
top: 50%
|
||||
transform(translateX(-50%) translateY(-50%))
|
||||
|
||||
@keyframes login-logo
|
||||
from
|
||||
transform(translateY(0))
|
||||
to
|
||||
transform(translateY(-100%))
|
||||
|
||||
@keyframes login-bg
|
||||
from
|
||||
bottom: -50%
|
||||
to
|
||||
bottom: 0
|
||||
@@ -0,0 +1,3 @@
|
||||
import './mongo.js';
|
||||
import './user.js';
|
||||
import './wadoProxy.js';
|
||||
@@ -0,0 +1,26 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
// Mongo data manipulation utilities
|
||||
class MongoUtils {
|
||||
|
||||
// Check if there is an user logged in
|
||||
static validateUser() {
|
||||
// Throw error if there is no user logged in
|
||||
if (!Meteor.userId()) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
}
|
||||
|
||||
// Generic callback to MongoDB write operations
|
||||
static writeCallback(error, affected) {
|
||||
// Throw error if it was not possible to complete the write operation
|
||||
if (error) {
|
||||
throw new Meteor.Error('data-write', error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Expose the class in the OHIF object
|
||||
OHIF.MongoUtils = MongoUtils;
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Accounts } from 'meteor/accounts-base';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
// Manipulate user's persistent data
|
||||
class UserData {
|
||||
|
||||
// Get the persistent data by key
|
||||
static get(key) {
|
||||
// Check if there is an user logged in
|
||||
OHIF.MongoUtils.validateUser();
|
||||
|
||||
// Get the user's profile data
|
||||
const profileData = Meteor.user().profile;
|
||||
|
||||
// Return the data if it is set
|
||||
if (profileData.persistent) {
|
||||
return profileData.persistent[key];
|
||||
}
|
||||
}
|
||||
|
||||
// Store the persistent data by giving a key and a value to store
|
||||
static set(key, value) {
|
||||
// Check if there is an user logged in
|
||||
OHIF.MongoUtils.validateUser();
|
||||
|
||||
// Get the user data
|
||||
const user = Meteor.user();
|
||||
|
||||
// Build the path to the persistent data with the given key
|
||||
const persistentPath = `profile.persistent.${key}`;
|
||||
|
||||
// Build the query to update the user's data
|
||||
let query;
|
||||
if (!user.profile.persistent) {
|
||||
const persistentData = OHIF.object.getNestedObject({ [key]: value });
|
||||
query = { $set: { 'profile.persistent': persistentData } };
|
||||
} else {
|
||||
query = { $set: { [persistentPath]: value } };
|
||||
}
|
||||
|
||||
// Update the user's profile data with the persistent information
|
||||
Accounts.users.update(user._id, query, OHIF.MongoUtils.writeCallback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Register the methods
|
||||
Meteor.methods({
|
||||
'ohif.user.data.get': key => UserData.get(key),
|
||||
'ohif.user.data.set': (key, value) => UserData.set(key, value)
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Meteor } from "meteor/meteor";
|
||||
import { Accounts } from "meteor/accounts-base";
|
||||
import { OHIF } from "meteor/ohif:core";
|
||||
|
||||
const doAuth = Meteor.users.find().count() ? true : false;
|
||||
|
||||
OHIF.user.authenticateUser = request => {
|
||||
// Only allow logged-in users to access this route
|
||||
const userId = request.headers['x-user-id'];
|
||||
const loginToken = request.headers['x-auth-token'];
|
||||
if (!userId || !loginToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hashedToken = Accounts._hashLoginToken(loginToken);
|
||||
|
||||
return !!Meteor.users.findOne({
|
||||
_id: userId,
|
||||
'services.resume.loginTokens.hashedToken': hashedToken
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
Package.describe({
|
||||
name: 'ohif:user-meteor-accounts',
|
||||
summary: 'OHIF Integration with Meteor Accounts',
|
||||
version: '0.0.1'
|
||||
});
|
||||
|
||||
Package.onUse(function(api) {
|
||||
api.versionsFrom('1.7');
|
||||
|
||||
api.use('ecmascript');
|
||||
api.use('templating');
|
||||
api.use('stylus');
|
||||
|
||||
api.use('accounts-base');
|
||||
api.use('accounts-password');
|
||||
|
||||
// Our custom packages
|
||||
api.use('ohif:core');
|
||||
|
||||
// Client imports
|
||||
api.mainModule('client/main.js', 'client');
|
||||
|
||||
// Server imports
|
||||
api.mainModule('server/main.js', 'server');
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
require('../imports/server/index.js');
|
||||
Reference in new issue
Block a user