Skip to content

Commit

Permalink
Merge pull request #50 from ORCID/emailPage
Browse files Browse the repository at this point in the history
Email page
  • Loading branch information
rcpeters authored Apr 20, 2017
2 parents 024b6f0 + d9e6f2d commit 6f5d907
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 67 deletions.
12 changes: 7 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var orcidLogger = new console.Console(orcidOutput, orcidErrorOutput);
//Endpoints
var CONFIG = '/config';
var CREATE_SMID_AUTHORIZE = '/create-smid-authorize';
var CREATE_SMID_EMAIL = '/create-smid-email';
var CONFIG = '/config';
var CREATE_SMID_URI = '/create-smid-redirect';
var COLLECTION_DETAILS = '/:publicKey/details';
Expand Down Expand Up @@ -210,12 +211,13 @@ app.post(EMAIL_SMID, function(req, res) {
console.log(error);
if (body != null && body.message != null && body.message.includes("Great job"))
res.status(200).json({'email': data.email, 'redirect': create_smid_authorization_uri }); // using test credentials

else
res.status(400).json({'error':error, 'body': body});
} else {
console.log("mailgun body:");
console.log(body);
res.status(200).json({'email': data.email});
res.status(200).json({'email': data.email, 'redirect': create_smid_authorization_uri });
}
});
});
Expand Down Expand Up @@ -273,6 +275,10 @@ app.get([COLLECTION_EDIT], function(req, res) { // Index page
});
});

app.get([CREATE_SMID_EMAIL, '/'], function(req, res) { // Index page
res.status(200).sendFile(index_file);
});

app.get([COLLECTION_SHARE, ADD_ID_SUCCESS, ADD_ID_ERROR], function(req, res) { // Index page
smidManger.detailsExist(req.params.publicKey, function(err, bool) {
if (bool == true)
Expand All @@ -281,7 +287,3 @@ app.get([COLLECTION_SHARE, ADD_ID_SUCCESS, ADD_ID_ERROR], function(req, res) { /
res.sendFile(PAGE_404);
});
});

app.get('/', function(req, res) { // Index page
res.status(200).sendFile(index_file);
});
5 changes: 5 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Routes, RouterModule } from '@angular/router';
import { AddIdErrorComponent } from './add-id-error/add-id-error.component';
import { AddIdSuccessComponent } from './add-id-success/add-id-success.component';
import { CollectionEditComponent } from './collection-edit/collection-edit.component';
import { CollectionEmailComponent } from './collection-email/collection-email.component';
import { CollectionShareComponent } from './collection-share/collection-share.component';
import { PageHomeComponent } from './page-home/page-home.component';

Expand All @@ -12,6 +13,10 @@ const routes: Routes = [
component: PageHomeComponent, // Authenticate -> Redirects to editCollection
path: ''
},
{
component: CollectionEmailComponent,
path: 'create-smid-email'
},
/* Be sure to put urls with :dinamicParam after the ones that are static. Other way the evaluation will
redirect to them instead of the expected url. */
{
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { OrcidUtilService } from './shared/orcid-util/orcid-util.service';
import { FooterComponent } from './footer/footer.component';
import { HeaderComponent } from './header/header.component';
import { PageHomeComponent } from './page-home/page-home.component';
import { CollectionEmailComponent } from './collection-email/collection-email.component';


@NgModule({
Expand All @@ -30,7 +31,8 @@ import { PageHomeComponent } from './page-home/page-home.component';
CollectionShareComponent,
FooterComponent,
HeaderComponent,
PageHomeComponent
PageHomeComponent,
CollectionEmailComponent,
],
imports: [
Angular2FontAwesomeModule,
Expand Down
30 changes: 1 addition & 29 deletions src/app/collection-edit/collection-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,8 @@
<div class="card">
<div class="card-block">
<h2>Collection Links <small>Hold onto these!</small></h2>
<form class="form-inline"
#formRefEmail="ngForm"
(ngSubmit)="submitEmail(formRefEmail.value)"
novalidate>
<label class="sr-only" for="email">Email</label>
<input
[(ngModel)]="email"
#emailRef="ngModel"
autocomplete="off"
class="form-control col-lg-5 col-md-7 mb-2 mb-sm-0 mr-sm-2 "
id="email"
name="email"
placeholder="Email"
type="email"
required
>
<button

class="btn btn-primary mt-0"
type="submit"
role="button"
>
<fa name="envelope-o"></fa>
Send links
</button>
</form>
<p (click)="showEmailErrorMessage = !showEmailErrorMessage" *ngIf="showEmailErrorMessage && formEmailSubmitted" class="text-danger"><strong>Uh oh, email not sent!</strong> Check the address and try again.</p>
<p (click)="showEmailSuccessMessage = !showEmailSuccessMessage" *ngIf="showEmailSuccessMessage && formRefEmail.valid && formEmailSubmitted" class="text-success"><strong>Success!</strong> Links sent to {{email}}</p>
<div id="collection-links" class="float-left">
<h3>Administration Link</h3>
<h3 class="mt-0">Administration Link</h3>
<p>Use this link to edit collection details:</p>
<p><a href="{{windowLocationOrigin}}/{{publicKey}}/edit/{{privateKey}}">{{windowLocationOrigin}}/{{publicKey}}/edit/{{privateKey}} </a></p>
<h3>Share Link</h3>
Expand Down
27 changes: 0 additions & 27 deletions src/app/collection-edit/collection-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,6 @@ export class CollectionEditComponent implements OnInit, OnDestroy {
this.sub.unsubscribe();
}

submitEmail( form: any ): void {
this.formEmailSubmitted = true;
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (re.test(form.email) == false) {
console.log("invalid email");
this.showEmailErrorMessage = true;
this.showEmailSuccessMessage = false;
} else {
var formString = JSON.stringify(form);
this.collectionService.editEmail( formString, this.publicKey, this.privateKey ).subscribe(
(response) => {
this.response = response;
console.log(this.response);
this.showEmailErrorMessage = false;
this.showEmailSuccessMessage = true; // <- Update to change the status on the ajax call result
},
(err) => {
console.log(err);
this.showEmailErrorMessage = true;
this.showEmailSuccessMessage = false;

},
() => {}
);
}
}

submitForm( form: any ): void {
this.formSubmitted = true;
this.collectionService.editCollection( form, this.publicKey, this.privateKey ).subscribe(
Expand Down
58 changes: 58 additions & 0 deletions src/app/collection-email/collection-email.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<div class="row justify-content-center">
<div class="col col-lg-7 text-center">
<div class="card">
<div class="card-block">
<h2>Create a new iD collection</h2>
<p class="mb-0">To get started, we'll need your email address</p>
<p class="small mt-1 mb-3"><i>Used only to send collection editing instructions to you. We don't save or display this.</i></p>
<form
class
#formRefEmail="ngForm"
(ngSubmit)="submitEmail(formRefEmail.value)"
novalidate>
<div class="form-group row justify-content-center">
<label for="email" class="sr-only">Email</label>
<div class="col-8">
<input
[(ngModel)]="email"
#emailRef="ngModel"
autocomplete="off"
class="form-control text-center"
id="email"
name="email"
placeholder="[email protected]"
type="email"
required
>
</div>
</div>
<button *ngIf="!formEmailSubmitted || showEmailErrorMessage"
class="btn btn-primary"
type="submit"
role="button"
>
Continue & Sign into ORCID
</button>
</form>
<p (click)="showEmailErrorMessage = !showEmailErrorMessage" *ngIf="showEmailErrorMessage && formEmailSubmitted" class="text-danger mt-2"><strong>Oops, something went wrong.</strong> Check the address and try again.</p>
<p class="mt-3"><small><strong>Don't have an ORCID iD?</strong> Register for an iD and create your collection at the same time. Click 'Sign into ORCID' above, then 'Register now' on the next screen.</small></p>
<div
*ngIf="emailSubmitSuccess"
class="row justify-content-center"
>
<div class="card-block">
<p>Thanks! To finish creating your collection, sign into ORCID.</p>

<a href="{{orcid_oauth_url}}"><button
class="btn btn-primary"
role="button"
>
Sign into ORCID
</button></a>
<p class="mt-2"><small><strong>Don't have an ORCID iD?</strong> Register for an iD and create your collection at the same time. Click 'Sign into ORCID' above, then 'Register now' on the next screen.</small></p>
</div>
</div>
</div>
</div>
</div>
</div>
66 changes: 66 additions & 0 deletions src/app/collection-email/collection-email.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@import '../../variables';

form p {
margin-bottom: 2rem;

&.form-control-label {
margin-bottom: 0;
}
}

legend {
color: $title-h1-font-color;
font: bold 2.5rem $font-stack;
}

small{
font-style: italic;
line-height: .8rem;
}

.card .card {

background-color: $gray97;

h2 {
text-align: left;
}

h3 {
font: bold 1rem $font-stack;
margin: 1rem 0 0 0;
}

p {
margin: .1rem 0;
}

small{
font: italic 1rem $font-stack;
}

button {
float: left;
margin: 1rem 0 0 0;

fa {
color: $white;
}
}

.card-block {
padding-top: .5rem;
}

#collection-links{
a {
word-break: break-all;
}
}

div.text-success {
float: left;
margin: 1.5rem 0 0 1rem;
}

}
25 changes: 25 additions & 0 deletions src/app/collection-email/collection-email.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CollectionEmailComponent } from './collection-email.component';

describe('CollectionEmailComponent', () => {
let component: CollectionEmailComponent;
let fixture: ComponentFixture<CollectionEmailComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CollectionEmailComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CollectionEmailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
59 changes: 59 additions & 0 deletions src/app/collection-email/collection-email.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Component, OnInit } from '@angular/core';

import { Collection } from './../shared/collection/collection';
import { CollectionService } from './../shared/collection/collection.service';

@Component({
selector: 'app-collection-email',
templateUrl: './collection-email.component.html',
styleUrls: ['./collection-email.component.scss']
})
export class CollectionEmailComponent implements OnInit {
public publicKey: string;
public privateKey: string;
private response: any;

email: string;
formEmailSubmitted: boolean;
ngForm: any;
showEmailErrorMessage: boolean;
showEmailWarningMessage: boolean;

constructor(
private collectionService: CollectionService
) {
this.email = '';
this.formEmailSubmitted = false
this.showEmailErrorMessage = false;
this.showEmailWarningMessage = false;
}

ngOnInit() {
}

submitEmail( form: any ): void {
this.formEmailSubmitted = true;
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (re.test(form.email) == false) {
console.log("invalid email");
this.showEmailErrorMessage = true;
} else {
var formString = JSON.stringify(form);
this.collectionService.editEmail(formString).subscribe(
(response) => {
this.response = response;
console.log(this.response);
var response_parsed = JSON.parse(JSON.stringify(this.response, null, 2));
this.showEmailErrorMessage = false;
window.location.replace(response_parsed.redirect + '&email=' + response_parsed.email);
},
(err) => {
console.log(err);
this.showEmailErrorMessage = true;
},
() => {}
);
}
}

}
4 changes: 2 additions & 2 deletions src/app/page-home/page-home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<div class="card">
<div class="card-block">
<div class="text-center">
<button (click)="authenticate()" class="btn btn-primary lg-btn">Create a new iD collection</button>
<button routerLink="/create-smid-email" class="btn btn-primary lg-btn">Create a new iD collection</button>
</div>
<h2>Collect authenticated ORCID iDs, just by sending a link!</h2>
<p>Want to get ORCID iDs from attendees at your next conference or event? Or maybe from everyone in your research group/lab? Share My iD makes it simple!</p>
<ol>
<li><a href="" (click)="authenticate()">Create a new iD collection</a> (anyone with an ORCID iD can create a new collection!)</li>
<li><a routerLink="/create-smid-email">Create a new iD collection</a> (anyone with an ORCID iD can create a new collection!)</li>
<li>Share the collection URL with people whose ORCID iDs you want to get (or display the page on a laptop/tablet at your event).</li>
<li>Visit the collection URL to see and download iDs you've collected.</li>
</ol>
Expand Down
6 changes: 3 additions & 3 deletions src/app/shared/collection/collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export class CollectionService {
).map(( res: Response ) => res.json()).catch(this.handleError);
}

editEmail( data: any, publicKey, privateKey ): Observable<Collection[]> {
editEmail( data: any) {
const headers = new Headers({ 'Content-Type': 'application/json' });
const options = new RequestOptions({ headers: headers });
return this.http.put(
'/' + publicKey + '/details/' + privateKey + '/details/owner/email',
return this.http.post(
'/email-smid',
data,
options
).map(( res: Response ) => res.json()).catch(this.handleError);
Expand Down

0 comments on commit 6f5d907

Please sign in to comment.