Skip to content

Commit b39d3b3

Browse files
committed
add account and security component
1 parent 5c176fe commit b39d3b3

File tree

8 files changed

+147
-1
lines changed

8 files changed

+147
-1
lines changed

projects/fusio-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-fusio-sdk",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "SDK to integrate Fusio into an Angular app",
55
"keywords": [
66
"Fusio",

projects/fusio-sdk/src/lib/component/account/account.component.css

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
<fusio-message [response]="response"></fusio-message>
3+
<div class="row">
4+
<div class="col-md-6">
5+
<form *ngIf="user" (ngSubmit)="doSave()">
6+
<div class="mb-3">
7+
<label for="name" class="form-label">Username</label>
8+
<input type="text" class="form-control" id="name" name="name" [ngModel]="user.name" disabled readonly>
9+
</div>
10+
<div class="mb-3">
11+
<label for="email" class="form-label">Email</label>
12+
<input type="email" class="form-control" id="email" name="email" [(ngModel)]="user.email">
13+
</div>
14+
<div class="mb-3">
15+
<label for="points" class="form-label">Points</label>
16+
<input type="number" class="form-control" id="points" name="points" [ngModel]="user.points" disabled readonly>
17+
</div>
18+
<div class="mb-3">
19+
<label for="scopes" class="form-label">Scopes</label>
20+
<input type="text" class="form-control" id="scopes" name="scopes" [ngModel]="user.scopes" disabled readonly>
21+
</div>
22+
<button type="submit" class="btn btn-primary">Update</button>
23+
</form>
24+
</div>
25+
<div class="col-md-6" *ngIf="email">
26+
<img ngxGravatar [email]="email" [size]="128" class="ms-4" />
27+
</div>
28+
</div>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import {ConsumerService} from "../../service/consumer.service";
3+
import {Message} from "fusio-sdk/dist/src/generated/consumer/Message";
4+
import {UserAccount} from "fusio-sdk/dist/src/generated/consumer/UserAccount";
5+
import {ErrorConverter} from "../../util/error-converter";
6+
7+
@Component({
8+
selector: 'fusio-account',
9+
templateUrl: './account.component.html',
10+
styleUrls: ['./account.component.css']
11+
})
12+
export class AccountComponent implements OnInit {
13+
14+
user?: UserAccount;
15+
response?: Message;
16+
email: string = '';
17+
18+
constructor(private consumer: ConsumerService) { }
19+
20+
async ngOnInit(): Promise<void> {
21+
try {
22+
const account = await this.consumer.getClient().getConsumerAccount();
23+
const response = await account.consumerActionUserGet();
24+
25+
this.user = response.data;
26+
this.email = this.user.email || '';
27+
this.response = undefined;
28+
} catch (error) {
29+
this.response = ErrorConverter.convert(error);
30+
}
31+
}
32+
33+
async doSave() {
34+
try {
35+
if (!this.user) {
36+
return;
37+
}
38+
39+
const account = await this.consumer.getClient().getConsumerAccount();
40+
const response = await account.consumerActionUserUpdate(this.user);
41+
42+
this.response = response.data;
43+
} catch (error) {
44+
this.response = ErrorConverter.convert(error);
45+
}
46+
}
47+
48+
}

projects/fusio-sdk/src/lib/component/security/security.component.css

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
<fusio-message [response]="response"></fusio-message>
3+
<div class="row">
4+
<div class="col-md-6">
5+
<form *ngIf="credentials" (ngSubmit)="doSave()">
6+
<div class="mb-3">
7+
<label for="name" class="form-label">Old password</label>
8+
<input type="password" class="form-control" id="name" name="name" [(ngModel)]="credentials.oldPassword">
9+
</div>
10+
<div class="mb-3">
11+
<label for="email" class="form-label">New password</label>
12+
<input type="password" class="form-control" id="email" name="email" [(ngModel)]="credentials.newPassword">
13+
</div>
14+
<div class="mb-3">
15+
<label for="points" class="form-label">Verify password</label>
16+
<input type="password" class="form-control" id="points" name="points" [(ngModel)]="credentials.verifyPassword">
17+
</div>
18+
<button type="submit" class="btn btn-primary">Change password</button>
19+
</form>
20+
</div>
21+
<div class="col-md-6">
22+
</div>
23+
</div>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import {ConsumerService} from "../../service/consumer.service";
3+
import {AccountChangePassword} from "fusio-sdk/dist/src/generated/consumer/AccountChangePassword";
4+
import {Message} from "fusio-sdk/dist/src/generated/consumer/Message";
5+
import {ErrorConverter} from "../../util/error-converter";
6+
7+
@Component({
8+
selector: 'fusio-security',
9+
templateUrl: './security.component.html',
10+
styleUrls: ['./security.component.css']
11+
})
12+
export class SecurityComponent implements OnInit {
13+
14+
credentials: AccountChangePassword = {
15+
oldPassword: '',
16+
newPassword: '',
17+
verifyPassword: '',
18+
};
19+
response?: Message;
20+
21+
constructor(private consumer: ConsumerService) { }
22+
23+
ngOnInit(): void {
24+
}
25+
26+
async doSave() {
27+
try {
28+
if (!this.credentials) {
29+
return;
30+
}
31+
32+
const password = await this.consumer.getClient().getConsumerAccountChangePassword();
33+
const response = await password.consumerActionUserChangePassword(this.credentials);
34+
35+
this.response = response.data;
36+
} catch (error) {
37+
this.response = ErrorConverter.convert(error);
38+
}
39+
}
40+
41+
}

projects/fusio-sdk/src/lib/fusio-sdk.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ import {ConfirmComponent} from "./component/password/confirm/confirm.component";
1717
import {ResetComponent} from "./component/password/reset/reset.component";
1818
import {RegisterComponent} from "./component/register/register.component";
1919
import {ActivateComponent} from "./component/register/activate/activate.component";
20+
import {AccountComponent} from './component/account/account.component';
21+
import {SecurityComponent} from './component/security/security.component';
2022
import {Config, FUSIO_CONFIG} from "./config/config";
2123
import {NgxCaptchaModule} from "ngx-captcha";
24+
import {GravatarModule} from "ngx-gravatar";
2225

2326
@NgModule({
2427
declarations: [
@@ -35,6 +38,8 @@ import {NgxCaptchaModule} from "ngx-captcha";
3538
ScopesComponent,
3639
SearchComponent,
3740
SidebarComponent,
41+
AccountComponent,
42+
SecurityComponent,
3843
],
3944
imports: [
4045
BrowserModule,
@@ -43,6 +48,7 @@ import {NgxCaptchaModule} from "ngx-captcha";
4348
RouterModule,
4449
NgbModule,
4550
NgxCaptchaModule,
51+
GravatarModule,
4652
],
4753
exports: [
4854
EmptyComponent,

0 commit comments

Comments
 (0)