Commit f99928e8 authored by Moises Sacal's avatar Moises Sacal
Browse files

added automatic email for ticket #25 and fixed ticket #26

parent 7bdffafc
This diff is collapsed.
...@@ -16,10 +16,13 @@ export class LabarchivesLoginField extends FieldBase<any> { ...@@ -16,10 +16,13 @@ export class LabarchivesLoginField extends FieldBase<any> {
usernameLabel: string; usernameLabel: string;
passwordLabel: string; passwordLabel: string;
loginLabel: string; loginLabel: string;
userLoginError: string;
userPasswordError: string;
helpLoginLabel: string; helpLoginLabel: string;
helpLoginLabelList: object[]; helpLoginLabelList: object[];
loginHelpImage: string; loginHelpImage: string;
loginHelpImageAlt: string; loginHelpImageAlt: string;
userEmail: string;
password: string; password: string;
submitted = false; submitted = false;
errorMessage: string = undefined; errorMessage: string = undefined;
...@@ -39,6 +42,8 @@ export class LabarchivesLoginField extends FieldBase<any> { ...@@ -39,6 +42,8 @@ export class LabarchivesLoginField extends FieldBase<any> {
this.columns = options['columns'] || []; this.columns = options['columns'] || [];
this.usernameLabel = options['usernameLabel'] || 'Username'; this.usernameLabel = options['usernameLabel'] || 'Username';
this.passwordLabel = options['passwordLabel'] || 'Password'; this.passwordLabel = options['passwordLabel'] || 'Password';
this.userLoginError = options['userLoginError'] || 'Please include username';
this.userPasswordError = options['userPasswordError'] || 'Please include password';
this.loginLabel = options['loginLabel'] || 'Login'; this.loginLabel = options['loginLabel'] || 'Login';
this.helpLoginLabel = options['helpLoginLabel'] || ''; this.helpLoginLabel = options['helpLoginLabel'] || '';
this.helpLoginLabelList = options['helpLoginLabelList'] || []; this.helpLoginLabelList = options['helpLoginLabelList'] || [];
...@@ -50,6 +55,7 @@ export class LabarchivesLoginField extends FieldBase<any> { ...@@ -50,6 +55,7 @@ export class LabarchivesLoginField extends FieldBase<any> {
registerEvents() { registerEvents() {
this.fieldMap['List'].field['checkLoggedIn'].subscribe(this.checkLogin.bind(this)); this.fieldMap['List'].field['checkLoggedIn'].subscribe(this.checkLogin.bind(this));
this.setUserEmail();
} }
checkLogin(status: boolean) { checkLogin(status: boolean) {
...@@ -57,12 +63,18 @@ export class LabarchivesLoginField extends FieldBase<any> { ...@@ -57,12 +63,18 @@ export class LabarchivesLoginField extends FieldBase<any> {
this.loading = false; this.loading = false;
} }
async setUserEmail() {
const userInfo = await this.labarchivesService.getUserInfo();
const user = userInfo['user'];
this.userEmail = user['email'];
}
async login(form) { async login(form) {
const formValid = this.loginValid(form); const formValid = this.loginValid(form);
if (formValid === '') { if (formValid === '') {
// TODO: Investigate this. Using this method to remove the trailing Base64 equals == // TODO: Investigate this. Using this method to remove the trailing Base64 equals ==
form.password = form.password.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''); form.password = form.password.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
this.user = {username: form.username, password: form.password}; this.user = {username: this.userEmail, password: form.password};
const login = await this.labarchivesService.login(this.user.username, this.user.password); const login = await this.labarchivesService.login(this.user.username, this.user.password);
if (login.status) { if (login.status) {
this.loggedIn = true; this.loggedIn = true;
...@@ -72,18 +84,17 @@ export class LabarchivesLoginField extends FieldBase<any> { ...@@ -72,18 +84,17 @@ export class LabarchivesLoginField extends FieldBase<any> {
} else { } else {
this.errorMessage = login.message; this.errorMessage = login.message;
} }
} else { } else {
this.errorMessage = formValid; this.errorMessage = formValid;
} }
} }
loginValid(form) { loginValid(form) {
if (!form.username) { if (!form.userEmail) {
return 'Please include username'; return this.userLoginError;
} }
if (!form.password) { if (!form.password) {
return 'Please include username'; return this.userPasswordError;
} }
return ''; return '';
} }
...@@ -102,7 +113,7 @@ export class LabarchivesLoginField extends FieldBase<any> { ...@@ -102,7 +113,7 @@ export class LabarchivesLoginField extends FieldBase<any> {
<form #form="ngForm"> <form #form="ngForm">
<div class="form-group"> <div class="form-group">
<label>{{ field.usernameLabel }}</label> <label>{{ field.usernameLabel }}</label>
<input type="text" class="form-control" ngModel name="username" <input type="text" class="form-control" [(ngModel)]="field.userEmail" name="userEmail" ngModel
attr.aria-label="{{ field.usernameLabel }}"> attr.aria-label="{{ field.usernameLabel }}">
</div> </div>
<div class="form-group"> <div class="form-group">
......
...@@ -89,4 +89,17 @@ export class LabarchivesService extends BaseService { ...@@ -89,4 +89,17 @@ export class LabarchivesService extends BaseService {
} }
} }
public async getUserInfo() {
const wsUrl = this.brandingAndPortalUrl + '/user/info';
try {
const result = await this.http.get(
wsUrl,
this.options
).toPromise();
return Promise.resolve((this.extractData(result)));
} catch (e) {
return Promise.reject(new Error(e));
}
}
} }
...@@ -12,6 +12,8 @@ class Config { ...@@ -12,6 +12,8 @@ class Config {
this.domain = la.domain; this.domain = la.domain;
this.parentRecord = workspaceConfig.parentRecord; this.parentRecord = workspaceConfig.parentRecord;
this.provisionerUser = workspaceConfig.provisionerUser; this.provisionerUser = workspaceConfig.provisionerUser;
this.location = la.location;
this.description = la.description;
this.brandingAndPortalUrl = ''; this.brandingAndPortalUrl = '';
this.redboxHeaders = { this.redboxHeaders = {
'Cache-Control': 'no-cache', 'Cache-Control': 'no-cache',
......
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
class UserInfo { class UserInfo {
constructor(id, orcid, fullName, notebooks) { constructor(id, orcid, fullName) {
this.id = id; this.id = id;
this.orcid = orcid; this.orcid = orcid;
this.fullName = fullName; this.fullName = fullName;
this.notebooks = notebooks['notebook'].map(nb => {
const getDefault = nb['is-default'];
const isDefault = getDefault['_'] !== 'false';
return new Notebook(nb['id'], nb['name'], isDefault);
});
} }
} }
exports.UserInfo = UserInfo; exports.UserInfo = UserInfo;
class Notebook {
constructor(id, name, isDefault) {
this.id = id;
this.name = name;
this.isDefault = isDefault;
}
}
...@@ -31,7 +31,7 @@ var Controllers; ...@@ -31,7 +31,7 @@ var Controllers;
rxjs_1.Observable.fromPromise(userInfo).flatMap(response => { rxjs_1.Observable.fromPromise(userInfo).flatMap(response => {
const userInfo = response['users']; const userInfo = response['users'];
if (userInfo) { if (userInfo) {
info = new UserInfo_1.UserInfo(userInfo['id'], userInfo['orcid'], userInfo['fullname'], userInfo['notebooks']); info = new UserInfo_1.UserInfo(userInfo['id'], userInfo['orcid'], userInfo['fullname']);
return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName); return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName);
} }
else { else {
...@@ -121,8 +121,8 @@ var Controllers; ...@@ -121,8 +121,8 @@ var Controllers;
rdmpOid: rdmp, rdmpOid: rdmp,
rdmpTitle: rdmpTitle, rdmpTitle: rdmpTitle,
title: nbName, title: nbName,
location: `https://au-mynotebook.labarchives.com`, location: this.config.location,
description: 'LabArchives Workspace', description: this.config.description,
type: this.config.recordType type: this.config.recordType
}; };
return WorkspaceService.createWorkspaceRecord(this.config, username, record, this.config.recordType, this.config.workflowStage); return WorkspaceService.createWorkspaceRecord(this.config, username, record, this.config.recordType, this.config.workflowStage);
......
...@@ -31,7 +31,9 @@ module.exports = { ...@@ -31,7 +31,9 @@ module.exports = {
appId: 'labarchives', appId: 'labarchives',
recordType: 'labarchives', recordType: 'labarchives',
workspaceFileName: 'README.md', workspaceFileName: 'README.md',
key: {"akid": "USER", "password": "PASSWORD"} key: {"akid": "USER", "password": "PASSWORD"},
location: 'https://au-mynotebook.labarchives.com',
description: 'LabArchives Workspace'
} }
} }
}; };
...@@ -34,7 +34,9 @@ module.exports = { ...@@ -34,7 +34,9 @@ module.exports = {
definition: { definition: {
name: 'Login', name: 'Login',
loginLabel: 'Login', loginLabel: 'Login',
userLoginError:'Please include your UTS email address',
usernameLabel: 'UTS email address', usernameLabel: 'UTS email address',
userPasswordError: 'Please include your password token',
passwordLabel: 'LabArchives password token for external applications', passwordLabel: 'LabArchives password token for external applications',
helpLoginLabel: 'To get your Lab Archives password token:', helpLoginLabel: 'To get your Lab Archives password token:',
helpLoginLabelList: [ helpLoginLabelList: [
......
...@@ -13,6 +13,8 @@ export class Config { ...@@ -13,6 +13,8 @@ export class Config {
types: any; types: any;
workspaceFileName: string; workspaceFileName: string;
key: any; key: any;
location: string;
description: string;
constructor(workspaces) { constructor(workspaces) {
const workspaceConfig = workspaces; const workspaceConfig = workspaces;
...@@ -27,6 +29,8 @@ export class Config { ...@@ -27,6 +29,8 @@ export class Config {
this.parentRecord = workspaceConfig.parentRecord; this.parentRecord = workspaceConfig.parentRecord;
this.provisionerUser = workspaceConfig.provisionerUser; this.provisionerUser = workspaceConfig.provisionerUser;
this.location = la.location;
this.description = la.description;
this.brandingAndPortalUrl = ''; this.brandingAndPortalUrl = '';
this.redboxHeaders = { this.redboxHeaders = {
......
...@@ -3,23 +3,10 @@ export class UserInfo { ...@@ -3,23 +3,10 @@ export class UserInfo {
id: string; id: string;
orcid: string; orcid: string;
fullName: string; fullName: string;
notebooks: Array<Notebook>;
constructor(id: string, orcid: string, fullName: string, notebooks: any) { constructor(id: string, orcid: string, fullName: string) {
this.id = id; this.id = id;
this.orcid = orcid; this.orcid = orcid;
this.fullName = fullName; this.fullName = fullName;
this.notebooks = notebooks['notebook'].map(nb => {
const getDefault = nb['is-default'];
const isDefault = getDefault['_'] !== 'false';
return new Notebook(nb['id'], nb['name'], isDefault);
});
}
}
class Notebook {
constructor(public id: string,
public name: string,
public isDefault: boolean) {
} }
} }
...@@ -49,7 +49,7 @@ export module Controllers { ...@@ -49,7 +49,7 @@ export module Controllers {
Observable.fromPromise(userInfo).flatMap(response => { Observable.fromPromise(userInfo).flatMap(response => {
const userInfo = response['users']; const userInfo = response['users'];
if (userInfo) { if (userInfo) {
info = new UserInfo(userInfo['id'], userInfo['orcid'], userInfo['fullname'], userInfo['notebooks']); info = new UserInfo(userInfo['id'], userInfo['orcid'], userInfo['fullname']);
return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName); return WorkspaceService.workspaceAppFromUserId(userId, this.config.appName);
} else { } else {
//Doing this because if the password is incorrect labarchives returns a 404! //Doing this because if the password is incorrect labarchives returns a 404!
...@@ -142,8 +142,8 @@ export module Controllers { ...@@ -142,8 +142,8 @@ export module Controllers {
rdmpOid: rdmp, rdmpOid: rdmp,
rdmpTitle: rdmpTitle, rdmpTitle: rdmpTitle,
title: nbName, title: nbName,
location: `https://au-mynotebook.labarchives.com`, location: this.config.location, //`https://au-mynotebook.labarchives.com`,
description: 'LabArchives Workspace', description: this.config.description, //'LabArchives Workspace',
type: this.config.recordType type: this.config.recordType
}; };
return WorkspaceService.createWorkspaceRecord( return WorkspaceService.createWorkspaceRecord(
......
...@@ -40,6 +40,7 @@ export module Services { ...@@ -40,6 +40,7 @@ export module Services {
} }
} }
async userInfo(key: any, userId: string) { async userInfo(key: any, userId: string) {
try { try {
if (key && key['akid'] && key['password']) { if (key && key['akid'] && key['password']) {
...@@ -53,7 +54,6 @@ export module Services { ...@@ -53,7 +54,6 @@ export module Services {
} }
userInfoViaId
async insertNode(key: any, userId: string, nbId: string, displayText) { async insertNode(key: any, userId: string, nbId: string, displayText) {
try { try {
if (key && key['akid'] && key['password']) { if (key && key['akid'] && key['password']) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment