Allowing alternative authentication methods on ohif:user package
This commit is contained in:
parent
0a82bfd6b6
commit
dc405e53da
@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
|
|||||||
import { Template } from 'meteor/templating';
|
import { Template } from 'meteor/templating';
|
||||||
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
||||||
import { Router } from 'meteor/iron:router';
|
import { Router } from 'meteor/iron:router';
|
||||||
|
import { OHIF } from 'meteor/ohif:core';
|
||||||
|
|
||||||
Template.userLogin.onCreated(() => {
|
Template.userLogin.onCreated(() => {
|
||||||
const instance = Template.instance();
|
const instance = Template.instance();
|
||||||
@ -17,20 +18,30 @@ Template.userLogin.onCreated(() => {
|
|||||||
// Get the form data
|
// Get the form data
|
||||||
const formData = form.value();
|
const formData = form.value();
|
||||||
|
|
||||||
// Call the Meteor's login method
|
// Handle errors and display the error message on the respective field
|
||||||
Meteor.loginWithPassword(formData.username, formData.password, error => {
|
const errorHandler = error => {
|
||||||
if (!error) {
|
const reason = (error && error.reason) || 'An error has ocurred';
|
||||||
const currentRoute = Router.current();
|
|
||||||
const redirect = currentRoute.params.query.redirect;
|
|
||||||
const path = redirect ? decodeURI(redirect) : '/';
|
|
||||||
return Router.go(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { reason } = error;
|
|
||||||
const isPassword = reason && reason.toLowerCase().indexOf('password') > -1;
|
const isPassword = reason && reason.toLowerCase().indexOf('password') > -1;
|
||||||
const displayComponent = form.item(isPassword ? 'password' : 'username');
|
const displayComponent = form.item(isPassword ? 'password' : 'username');
|
||||||
displayComponent.error(reason);
|
displayComponent.error(reason);
|
||||||
displayComponent.$element.focus();
|
Meteor.defer(() => displayComponent.$element.focus());
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle success and redirect the user
|
||||||
|
const successHandler = () => {
|
||||||
|
const currentRoute = Router.current();
|
||||||
|
const redirect = currentRoute.params.query.redirect;
|
||||||
|
const path = redirect ? decodeURI(redirect) : '/';
|
||||||
|
return Router.go(path);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Call the login method
|
||||||
|
const promise = OHIF.user.login(formData).then(successHandler).catch(errorHandler);
|
||||||
|
|
||||||
|
// Display loading state
|
||||||
|
OHIF.ui.showDialog('dialogLoading', {
|
||||||
|
text: 'Signing in...',
|
||||||
|
promise
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
import './getName';
|
import './getName';
|
||||||
|
import './login';
|
||||||
import './logout';
|
import './logout';
|
||||||
|
|||||||
14
Packages/ohif-user/client/lib/login.js
Normal file
14
Packages/ohif-user/client/lib/login.js
Normal file
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -10,7 +10,8 @@ Package.onUse(function(api) {
|
|||||||
// Meteor client and server packages
|
// Meteor client and server packages
|
||||||
api.use([
|
api.use([
|
||||||
'ecmascript',
|
'ecmascript',
|
||||||
'accounts-base'
|
'accounts-base',
|
||||||
|
'accounts-password'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Meteor client-only packages
|
// Meteor client-only packages
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user