исправил кр код при авторизации

This commit is contained in:
gofnnp 2023-09-05 15:04:50 +04:00
parent 29f8ca5230
commit 756a033504
3 changed files with 90 additions and 50 deletions

View File

@ -3,70 +3,83 @@
<div class="guest-card">
<div class="top-info">
<div class="top-info__level">
<p id="level">Уровень {{ authService.error ? '--' : authService.userInfo?.current_level_and_cashback?.current_level }}</p>
<p id="level-percent">Кэшбек {{ authService.error ? '--' : authService.currentLvlPeriod.percent }}%</p>
<p id="level">
Уровень
{{
authService.error
? "--"
: authService.userInfo?.current_level_and_cashback?.current_level
}}
</p>
<p id="level-percent">
Кэшбек
{{ authService.error ? "--" : authService.currentLvlPeriod.percent }}%
</p>
</div>
<ng-container *ngIf="!authService.error && authService.userInfo!.walletBalances < 0">
<p class="top-info__bonus">
Отрицательный баланс бонусов, свяжитесь с техподдержкой
</p>
<ng-container
*ngIf="!authService.error && authService.userInfo!.walletBalances < 0"
>
<p class="top-info__bonus">
Отрицательный баланс бонусов, свяжитесь с техподдержкой
</p>
</ng-container>
<ng-container *ngIf="authService.error || authService.userInfo!.walletBalances >= 0">
<p class="top-info__bonus">
{{ authService.error ? '--' : Math.floor(authService.userInfo!.walletBalances) }}
<ng-container
*ngIf="authService.error || authService.userInfo!.walletBalances >= 0"
>
<p class="top-info__bonus">
{{
authService.error
? "--"
: Math.floor(authService.userInfo!.walletBalances)
}}
бонусов
</p>
</ng-container>
</p>
</ng-container>
</div>
<div class="guest-card__qr" (click)="qrCodeClick()">
<div class="guest-card__qr" (click)="qrCodeClick()">
<div class="qr-code-wrapper">
<qr-code
[value]="phone || 'Данные не найдены'"
[margin]="0"
[size]="qrCodeSize"
errorCorrectionLevel="H"
></qr-code>
<span class="material-icons zoom">
zoom_in
</span>
[value]="phone || 'Данные не найдены'"
[margin]="0"
[size]="qrCodeSize"
errorCorrectionLevel="H"
></qr-code>
<span class="material-icons zoom"> zoom_in </span>
</div>
<span>Покажи бариста</span>
<span>Покажи бариста</span>
</div>
<ng-container *ngIf="!authService.error">
<div class="guest-card__user-description">
<p [innerHtml]="getLevelDescription() | safeHtml"></p>
</div>
</ng-container>
<ng-container *ngIf="!authService.error">
<div class="guest-card__user-description">
<p [innerHtml]="getLevelDescription() | safeHtml"></p>
</div>
</ng-container>
<ng-container *ngIf="!authService.error">
<span id="bonuses-condition"></span>
<app-last-order
[lastOrder]="authService.userInfo?.last_purchase"
[loading]="authService.loading"
></app-last-order>
</ng-container>
<ng-container *ngIf="authService.error">
<div class="broken">
<img src="./assets/broken.jpg" alt="" />
<p>
Упс, что-то пошло не так..
Мы уже работаем над этой проблемой.
Попробуйте обновить страницу или зайти попозже.
Приносим извинения за неудобства.
</p>
</div>
[lastOrder]="authService.userInfo?.last_purchase"
[loading]="authService.loading"
></app-last-order>
</ng-container>
<ng-container *ngIf="authService.error">
<div class="broken">
<img src="./assets/broken.jpg" alt="" />
<p>
Упс, что-то пошло не так.. Мы уже работаем над этой проблемой.
Попробуйте обновить страницу или зайти попозже. Приносим извинения за
неудобства.
</p>
</div>
</ng-container>
<app-footer></app-footer>
</div>
</ng-container>
<ng-container *ngIf="authService.loading">
</div>
</ng-container>
<ng-container *ngIf="authService.loading">
<ng-container
*ngTemplateOutlet="spinner; context: { $implicit: 85 }"
></ng-container>
></ng-container>
</ng-container>
<ng-template #spinner let-diameter>
<ng-template #spinner let-diameter>
<div class="center wrapper">
<mat-spinner [strokeWidth]="3" [diameter]="diameter"></mat-spinner>
</div>

View File

@ -54,13 +54,21 @@ export class GuestCardComponent implements OnInit {
) {}
ngOnInit(): void {
this.phone =
this.cookiesService.getItem('phone-number') ||
this.authService.userInfo?.phone;
this.getUserPhone()
this.requestPermission();
}
getUserPhone() {
if (this.cookiesService.getItem('phone-number')) {
this.phone = this.cookiesService.getItem('phone-number');
return
}
this.authService.getUserPhone()?.subscribe((phone) => {
this.phone = this.cookiesService.getItem('phone-number') || phone;
});
}
requestPermission() {
const userAgent = window.navigator.userAgent.toLowerCase();
const ios = /iphone|ipod|ipad/.test(userAgent);

View File

@ -13,6 +13,7 @@ import {
import { lvlPeriods } from 'src/app/app.constants';
import moment from 'moment-timezone';
import { Router } from '@angular/router';
import { Observable, map } from 'rxjs';
@Injectable({
providedIn: 'root',
@ -51,6 +52,24 @@ export class AuthService {
return !!this.token;
}
getUserPhone() {
const token = this.cookiesService.getItem('token');
if (!token) {
return;
}
return this.wpJsonService.getCustomerInfo(
environment.systemId,
token,
environment.icardProxy
).pipe(
map((value) => {
return value.customer_info.phone;
})
)
}
getUserInfo() {
const token = this.cookiesService.getItem('token');