forked from hibernate/hibernate-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hibernate#8 from dreab8/message-board-demo
create account and other minor changes
- Loading branch information
Showing
11 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
other/openshift/message-board/message-board-web/src/app/account.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {Injectable} from '@angular/core'; | ||
import {HttpClient, HttpHeaders} from '@angular/common/http'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import {catchError, map, tap} from 'rxjs/operators'; | ||
import {of} from 'rxjs/observable/of'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
import {User} from './user'; | ||
|
||
const httpOptions = { | ||
headers: new HttpHeaders({'Content-Type': 'application/json'}) | ||
}; | ||
|
||
@Injectable() | ||
export class AccountService { | ||
private loginUrl = 'users'; | ||
|
||
private user: User; | ||
|
||
constructor( | ||
private http: HttpClient) { | ||
|
||
} | ||
|
||
createAccount(user: User): Observable<User> { | ||
const url = `http://web-message-board.192.168.42.57.nip.io/users}`; | ||
console.log(url); | ||
return this.http.post<User>(url, user, httpOptions).map( | ||
newUser => { | ||
console.log('user -> ' + newUser.id); | ||
if (newUser.id == null) { | ||
console.log('user is empty'); | ||
Observable.throw('Username or password is incorrect'); | ||
|
||
} else { | ||
console.log('a new user '); | ||
localStorage.setItem('currentUser', JSON.stringify(user)); | ||
} | ||
return newUser; | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
other/openshift/message-board/message-board-web/src/app/signin/signin.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
<p> | ||
signin works! | ||
</p> | ||
<form name="form" (ngSubmit)="f.form.valid && createAccount()" #f="ngForm" novalidate> | ||
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !username.valid }"> | ||
<label for="username">Username</label> | ||
<input type="text" class="form-control" name="username" [(ngModel)]="user.userName" | ||
#username="ngModel" required /> | ||
<div *ngIf="f.submitted && !username.valid" class="help-block">Username is required</div> | ||
</div> | ||
<div class="form-group"> | ||
<button [disabled]="createAccount" class="btn btn-primary">Create</button> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters