ui enhancements and song state
This commit is contained in:
1
src/app/services/delay.ts
Normal file
1
src/app/services/delay.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const delay = (ms: number): Promise<any> => new Promise(resolve => setTimeout(resolve, ms));
|
||||
@@ -1,8 +0,0 @@
|
||||
import {RoleDirective} from './role.directive';
|
||||
|
||||
describe('RoleDirective', () => {
|
||||
it('should create an instance', () => {
|
||||
const directive = new RoleDirective();
|
||||
expect(directive).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -33,10 +33,9 @@ export class RoleDirective implements OnInit {
|
||||
}
|
||||
|
||||
private updateView() {
|
||||
this.viewContainer.clear();
|
||||
if (this.loggedIn && this.checkPermission()) {
|
||||
this.viewContainer.createEmbeddedView(this.templateRef);
|
||||
} else {
|
||||
this.viewContainer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export type roles = 'none' | 'admin' | 'user' | 'leader' | 'presenter' | 'distributor';
|
||||
export const ROLE_TYPES: roles[] = ['admin', 'user', 'leader', 'presenter', 'distributor'];
|
||||
export type roles = 'none' | 'admin' | 'user' | 'leader' | 'presenter' | 'contributor';
|
||||
export const ROLE_TYPES: roles[] = ['admin', 'user', 'leader', 'presenter', 'contributor'];
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {AngularFireAuth} from '@angular/fire/auth';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {filter, switchMap} from 'rxjs/operators';
|
||||
import {filter, first, switchMap} from 'rxjs/operators';
|
||||
import {User} from './user';
|
||||
import {DbService} from '../db.service';
|
||||
import {environment} from '../../../environments/environment';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
constructor(private afAuth: AngularFireAuth, private db: DbService) {
|
||||
constructor(private afAuth: AngularFireAuth, private db: DbService, private router: Router) {
|
||||
this.afAuth.authState.pipe(
|
||||
filter(_ => !!_),
|
||||
switchMap(auth => this.db.doc$<User>('users/' + auth.uid)),
|
||||
switchMap(auth => this.readUser$(auth.uid)),
|
||||
).subscribe(_ => this._user$.next(_));
|
||||
}
|
||||
|
||||
public getUserbyId(userId: string): Promise<User> {
|
||||
return this.db.doc$<User>('users/' + userId).pipe(first()).toPromise();
|
||||
}
|
||||
|
||||
public async login(user: string, password: string): Promise<any> {
|
||||
const aUser = await this.afAuth.auth.signInWithEmailAndPassword(user, password);
|
||||
const dUser = await this.readUser(aUser.user.uid);
|
||||
this._user$.next(dUser);
|
||||
}
|
||||
|
||||
private _user$ = new BehaviorSubject<User>(null);
|
||||
|
||||
public get user$(): Observable<User> {
|
||||
@@ -26,23 +38,32 @@ export class UserService {
|
||||
|
||||
public list$ = (): Observable<User[]> => this.db.col$('users');
|
||||
|
||||
public getUserbyId$(userId: string): Observable<User> {
|
||||
return this.db.doc$<User>('users/' + userId);
|
||||
public async logout(): Promise<any> {
|
||||
await this.afAuth.auth.signOut();
|
||||
this._user$.next(null);
|
||||
}
|
||||
|
||||
public async update$(uid: string, data: Partial<User>): Promise<void> {
|
||||
await this.db.doc<User>('users/' + uid).update(data);
|
||||
}
|
||||
|
||||
public async login(user: string, password: string): Promise<any> {
|
||||
await this.afAuth.auth.signInWithEmailAndPassword(user, password);
|
||||
public async changePassword(user: string): Promise<any> {
|
||||
const url = environment.url;
|
||||
await this.afAuth.auth.sendPasswordResetEmail(user, {url});
|
||||
}
|
||||
|
||||
public async logout(): Promise<any> {
|
||||
await this.afAuth.auth.signOut();
|
||||
public async createNewUser(user: string, name: string, password: string): Promise<any> {
|
||||
const aUser = await this.afAuth.auth.createUserWithEmailAndPassword(user, password);
|
||||
const userId = aUser.user.uid;
|
||||
await this.db.doc('users/' + userId).set({name, chordMode: 'onlyFirst'});
|
||||
const dUser = await this.readUser(aUser.user.uid);
|
||||
this._user$.next(dUser);
|
||||
await this.router.navigateByUrl('/user/info');
|
||||
}
|
||||
|
||||
public async changePassword(email: string): Promise<any> {
|
||||
await this.afAuth.auth.sendPasswordResetEmail(email);
|
||||
private readUser$ = (uid) => this.db.doc$<User>('users/' + uid);
|
||||
|
||||
private async readUser(uid): Promise<User> {
|
||||
return await this.readUser$(uid).pipe(first()).toPromise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import {ChordMode} from '../../widget-modules/components/song-text/song-text.component';
|
||||
import {roles} from './roles';
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
name: string;
|
||||
role: string;
|
||||
role: roles;
|
||||
chordMode: ChordMode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user