Commit f99928e8 authored by Moises Sacal's avatar Moises Sacal

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> {
usernameLabel: string;
passwordLabel: string;
loginLabel: string;
userLoginError: string;
userPasswordError: string;
helpLoginLabel: string;
helpLoginLabelList: object[];
loginHelpImage: string;
loginHelpImageAlt: string;
userEmail: string;
password: string;
submitted = false;
errorMessage: string = undefined;
......@@ -39,6 +42,8 @@ export class LabarchivesLoginField extends FieldBase<any> {
this.columns = options['columns'] || [];
this.usernameLabel = options['usernameLabel'] || 'Username';
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.helpLoginLabel = options['helpLoginLabel'] || '';
this.helpLoginLabelList = options['helpLoginLabelList'] || [];
......@@ -50,6 +55,7 @@ export class LabarchivesLoginField extends FieldBase<any> {
registerEvents() {
this.fieldMap['List'].field['checkLoggedIn'].subscribe(this.checkLogin.bind(this));
this.setUserEmail();
}
checkLogin(status: boolean) {
......@@ -57,12 +63,18 @@ export class LabarchivesLoginField extends FieldBase<any> {
this.loading = false;
}
async setUserEmail() {
const userInfo = await this.labarchivesService.getUserInfo();
const user = userInfo['user'];
this.userEmail = user['email'];
}
async login(form) {
const formValid = this.loginValid(form);
if (formValid === '') {
// TODO: Investigate this. Using this method to remove the trailing Base64 equals ==
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);
if (login.status) {
this.loggedIn = true;
......@@ -72,18 +84,17 @@ export class LabarchivesLoginField extends FieldBase<any> {
} else {
this.errorMessage = login.message;
}
} else {
this.errorMessage = formValid;
}
}
loginValid(form) {
if (!form.username) {
return 'Please include username';
if (!form.userEmail) {
return this.userLoginError;
}
if (!form.password) {
return 'Please include username';
return this.userPasswordError;
}
return '';
}
......@@ -102,7 +113,7 @@ export class LabarchivesLoginField extends FieldBase<any> {
<form #form="ngForm">
<div class="form-group">
<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 }}">
</div>
<div class="form-group">
......
......@@ -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 {
this.domain = la.domain;
this.parentRecord = workspaceConfig.parentRecord;
this.provisionerUser = workspaceConfig.provisionerUser;
this.location = la.location;
this.description = la.description;
this.brandingAndPortalUrl = '';
this.redboxHeaders = {
'Cache-Control': 'no-cache',
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class UserInfo {
constructor(id, orcid, fullName, notebooks) {
constructor(id, orcid, fullName) {
this.id = id;
this.orcid = orcid;
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;
class Notebook {
constructor(id, name, isDefault) {
this.id = id;
this.name = name;
this.isDefault = isDefault;
}
}
......@@ -31,7 +31,7 @@ var Controllers;
rxjs_1.Observable.fromPromise(userInfo).flatMap(response => {
const userInfo = response['users'];
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);
}
else {
......@@ -121,8 +121,8 @@ var Controllers;
rdmpOid: rdmp,
rdmpTitle: rdmpTitle,
title: nbName,
location: `https://au-mynotebook.labarchives.com`,
description: 'LabArchives Workspace',
location: this.config.location,
description: this.config.description,
type: this.config.recordType
};
return WorkspaceService.createWorkspaceRecord(this.config, username, record, this.config.recordType, this.config.workflowStage);
......
......@@ -31,7 +31,9 @@ module.exports = {
appId: 'labarchives',
recordType: 'labarchives',
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 = {
definition: {
name: 'Login',
loginLabel: 'Login',
userLoginError:'Please include your UTS email address',
usernameLabel: 'UTS email address',
userPasswordError: 'Please include your password token',
passwordLabel: 'LabArchives password token for external applications',
helpLoginLabel: 'To get your Lab Archives password token:',
helpLoginLabelList: [
......
......@@ -13,6 +13,8 @@ export class Config {
types: any;
workspaceFileName: string;
key: any;
location: string;
description: string;
constructor(workspaces) {
const workspaceConfig = workspaces;
......@@ -27,6 +29,8 @@ export class Config {
this.parentRecord = workspaceConfig.parentRecord;
this.provisionerUser = workspaceConfig.provisionerUser;
this.location = la.location;
this.description = la.description;
this.brandingAndPortalUrl = '';
this.redboxHeaders = {
......
......@@ -3,23 +3,10 @@ export class UserInfo {
id: string;
orcid: 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.orcid = orcid;
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 {
Observable.fromPromise(userInfo).flatMap(response => {
const userInfo = response['users'];
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);
} else {
//Doing this because if the password is incorrect labarchives returns a 404!
......@@ -142,8 +142,8 @@ export module Controllers {
rdmpOid: rdmp,
rdmpTitle: rdmpTitle,
title: nbName,
location: `https://au-mynotebook.labarchives.com`,
description: 'LabArchives Workspace',
location: this.config.location, //`https://au-mynotebook.labarchives.com`,
description: this.config.description, //'LabArchives Workspace',
type: this.config.recordType
};
return WorkspaceService.createWorkspaceRecord(
......
......@@ -40,6 +40,7 @@ export module Services {
}
}
async userInfo(key: any, userId: string) {
try {
if (key && key['akid'] && key['password']) {
......@@ -53,7 +54,6 @@ export module Services {
}
userInfoViaId
async insertNode(key: any, userId: string, nbId: string, displayText) {
try {
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