mirror of https://github.com/abpframework/abp.git
committed by
GitHub
14 changed files with 178 additions and 61 deletions
@ -1,40 +1,50 @@ |
|||
import { ABP, SessionSetTenantId } from '@abp/ng.core'; |
|||
import { ToasterService } from '@abp/ng.theme.shared'; |
|||
import { Component, TemplateRef, ViewChild } from '@angular/core'; |
|||
import { FormBuilder, FormGroup } from '@angular/forms'; |
|||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; |
|||
import { ABP } from '@abp/ng.core'; |
|||
import { Store } from '@ngxs/store'; |
|||
import { throwError } from 'rxjs'; |
|||
import { catchError, take } from 'rxjs/operators'; |
|||
import snq from 'snq'; |
|||
import { AccountService } from '../../services/account.service'; |
|||
|
|||
@Component({ |
|||
selector: 'abp-tenant-box', |
|||
templateUrl: './tenant-box.component.html', |
|||
}) |
|||
export class TenantBoxComponent { |
|||
constructor(private modalService: NgbModal, private fb: FormBuilder) {} |
|||
constructor(private store: Store, private toasterService: ToasterService, private accountService: AccountService) {} |
|||
|
|||
form: FormGroup; |
|||
selected = {} as ABP.BasicItem; |
|||
|
|||
selected: ABP.BasicItem; |
|||
isModalVisible: boolean; |
|||
|
|||
@ViewChild('modalContent', { static: false }) |
|||
modalContent: TemplateRef<any>; |
|||
|
|||
createForm() { |
|||
this.form = this.fb.group({ |
|||
name: [this.selected.name], |
|||
}); |
|||
} |
|||
|
|||
openModal() { |
|||
this.createForm(); |
|||
this.modalService.open(this.modalContent); |
|||
} |
|||
|
|||
onSwitch() { |
|||
this.selected = {} as ABP.BasicItem; |
|||
this.openModal(); |
|||
this.isModalVisible = true; |
|||
} |
|||
|
|||
save() { |
|||
this.selected = this.form.value; |
|||
this.modalService.dismissAll(); |
|||
this.selected.name = this.selected.name || ''; |
|||
|
|||
this.accountService |
|||
.findTenant(this.selected.name) |
|||
.pipe( |
|||
take(1), |
|||
catchError(err => { |
|||
this.toasterService.error(snq(() => err.error.error_description, 'An error occured.'), 'Error'); |
|||
return throwError(err); |
|||
}), |
|||
) |
|||
.subscribe(({ success, tenantId }) => { |
|||
if (success) { |
|||
this.isModalVisible = false; |
|||
} else { |
|||
this.toasterService.error(`Given tenant is not available: ${this.selected.name}`, 'Error'); |
|||
this.selected = {} as ABP.BasicItem; |
|||
} |
|||
this.store.dispatch(new SessionSetTenantId(success ? tenantId : null)); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
@ -1 +1,3 @@ |
|||
export * from './options'; |
|||
export * from './user'; |
|||
export * from './tenant'; |
|||
|
|||
@ -0,0 +1,4 @@ |
|||
export interface Tenant { |
|||
success: boolean; |
|||
tenantId: string; |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
export interface RegisterRequest { |
|||
userName: string; |
|||
emailAddress: string; |
|||
password: string; |
|||
appName?: string; |
|||
} |
|||
|
|||
export interface RegisterResponse { |
|||
tenantId: string; |
|||
userName: string; |
|||
name: string; |
|||
surname: string; |
|||
email: string; |
|||
emailConfirmed: boolean; |
|||
phoneNumber: string; |
|||
phoneNumberConfirmed: boolean; |
|||
twoFactorEnabled: boolean; |
|||
lockoutEnabled: boolean; |
|||
lockoutEnd: string; |
|||
concurrencyStamp: string; |
|||
isDeleted: boolean; |
|||
deleterId: string; |
|||
deletionTime: string; |
|||
lastModificationTime: string; |
|||
lastModifierId: string; |
|||
creationTime: string; |
|||
creatorId: string; |
|||
id: string; |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
import { Injectable } from '@angular/core'; |
|||
import { Observable } from 'rxjs'; |
|||
import { RestService, Rest } from '@abp/ng.core'; |
|||
import { RegisterResponse, RegisterRequest, Tenant } from '../models'; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root', |
|||
}) |
|||
export class AccountService { |
|||
constructor(private rest: RestService) {} |
|||
|
|||
findTenant(tenantName: string): Observable<Tenant> { |
|||
const request: Rest.Request<null> = { |
|||
method: 'GET', |
|||
url: `/api/abp/multi-tenancy/find-tenant/${tenantName}`, |
|||
}; |
|||
|
|||
return this.rest.request<null, Tenant>(request); |
|||
} |
|||
|
|||
register(body: RegisterRequest): Observable<RegisterResponse> { |
|||
const request: Rest.Request<RegisterRequest> = { |
|||
method: 'POST', |
|||
url: `/api/account/register`, |
|||
body, |
|||
}; |
|||
|
|||
return this.rest.request<RegisterRequest, RegisterResponse>(request, { throwErr: true }); |
|||
} |
|||
} |
|||
@ -1,5 +1,6 @@ |
|||
export namespace Session { |
|||
export interface State { |
|||
language: string; |
|||
tenantId: string; |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue