Commit 4b2572dd authored by dev0tion's avatar dev0tion

Add basic login component

parent 96933470
{
"status":
"create":
{
"success": "true",
"mnemonic": "foo bar buz"
},
"load":
{
"success": "true"
},
"status":
{
"success": "false",
"connectedNodeCount": "7",
"maxConnextedNodeCount": "8",
"headerChainHeight": "1048",
......
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login/login.component';
const routes: Routes = [
{ path: 'login', component: LoginComponent}
];
@NgModule({
......
......@@ -28,9 +28,9 @@ export class AppComponent implements OnInit {
error => this.errorMessage = <any>error
);
if (this.response = "true") {
if (this.response === "true") {
// remote.dialog.showMessageBox({message: remote.app.getPath('userData')})
this.router.navigate(['/wallet'])
this.router.navigate(['/login'])
} else {
this.router.navigate(['/setup'])
}
......
......@@ -9,12 +9,14 @@ import { SharedModule } from './shared/shared.module';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { ApiService } from './shared/api/api.service';
@NgModule({
imports: [
AppRoutingModule,
BrowserModule,
HttpModule,
......@@ -23,7 +25,8 @@ import { ApiService } from './shared/api/api.service';
SharedModule.forRoot()
],
declarations: [
AppComponent
AppComponent,
LoginComponent
],
providers: [ ApiService ],
bootstrap: [ AppComponent ]
......
<h1>Welcome back</h1>
<p>Please enter your password to decrypt your wallet</p>
<form (ngSubmit)="onSubmit()" #passwordForm="ngForm">
<div class="form-group">
<label for="password">Your password: </label>
<input type="password" class="form-control" id="password" required name="password">
</div>
<button type="submit" class="btn btn-success">Decrypt</button>
</form>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LoginComponent } from './login.component';
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ApiService } from '../shared/api/api.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
constructor(private apiService: ApiService, private router: Router) { }
private response: any;
private errorMessage: string;
ngOnInit() {
}
private onSubmit() {
this.apiService.loadWallet("123")
.subscribe(
response => this.response = response,
error => this.errorMessage = error,
() => this.loadWallet()
);
}
private loadWallet() {
if (this.response.success === "true") {
this.router.navigate(['/wallet/send']);
} else {
alert("Something went wrong.")
}
}
}
......@@ -18,6 +18,26 @@ export class ApiService {
private webApiUrl = 'http://localhost:3000/api/v1';
private headers = new Headers({'Content-Type': 'application/json'});
/**
* Create a new wallet.
*/
createWallet(data: SafeCreation): Observable<any> {
console.log(JSON.stringify(data));
return this.http
.post(this.webApiUrl + 'api/safe', JSON.stringify(data), {headers: this.headers})
.map(response => response.json());
}
/**
* Load a wallet
*/
loadWallet(password: string): Observable<any> {
return this.http
.get(this.webApiUrl + '/wallet/load/', {headers: this.headers, body: JSON.stringify(password)})
.map(response => response.json())
.catch(this.handleError);
}
/**
* Get wallet status info from the API.
*/
......@@ -57,16 +77,6 @@ export class ApiService {
.map((response:Response) => response.json())
.catch(this.handleError);
}
/**
* Create a new wallet.
*/
createWallet(data: SafeCreation): Observable<any> {
console.log(JSON.stringify(data));
return this.http
.post(this.webApiUrl + 'api/safe', JSON.stringify(data), {headers: this.headers})
.map(response => response.json());
}
/**
* Handle errors from the API.
......
<div class="content-wrapper">
<h1>Send</h1>
<form (ngSubmit)="onSubmit()" #sendForm="ngForm">
<h1>Send</h1>
<form (ngSubmit)="onSubmit()" #sendForm="ngForm">
<div class="form-group">
<label for="toAddress">Pay To: </label>
<input type="text" class="form-control" id="name" required name="toAddress">
......@@ -10,5 +10,5 @@
<input type="text" class="form-control" id="amount" required name="amount">
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</form>
</div>
\ No newline at end of file
......@@ -27,7 +27,7 @@ import { WalletRoutingModule } from './wallet-routing.module';
DashboardComponent,
ReceiveComponent,
SendComponent,
HistoryComponent,
HistoryComponent
],
exports: [
WalletComponent
......
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