Allowing alternative authentication methods on ohif:user package
This commit is contained in:
1 parent
0a82bfd6b6
commit
dc405e53da
4 files changed
+39
-12
No files matched your search
@@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
|
||||
import { Template } from 'meteor/templating';
|
||||
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
||||
import { Router } from 'meteor/iron:router';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
Template.userLogin.onCreated(() => {
|
||||
const instance = Template.instance();
|
||||
@@ -17,20 +18,30 @@ Template.userLogin.onCreated(() => {
|
||||
// Get the form data
|
||||
const formData = form.value();
|
||||
|
||||
// Call the Meteor's login method
|
||||
Meteor.loginWithPassword(formData.username, formData.password, error => {
|
||||
if (!error) {
|
||||
const currentRoute = Router.current();
|
||||
const redirect = currentRoute.params.query.redirect;
|
||||
const path = redirect ? decodeURI(redirect) : '/';
|
||||
return Router.go(path);
|
||||
}
|
||||
|
||||
const { reason } = error;
|
||||
// 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);
|
||||
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
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user