Commit fb62d721 authored by Revant Nandgaonkar's avatar Revant Nandgaonkar

Add account chooser

Merge branch 'add-account-chooser' into 'develop'

See merge request castlecraft/building-blocks!279
parents f99d04d4 9e073c53
......@@ -291,7 +291,7 @@ export class AuthService {
}
async chooseUser(req, uuid: string) {
if (req.session.users.length === 0) {
if (!req.session.users) {
req.session.users = [];
}
......
......@@ -18,4 +18,20 @@ mat-card-content {
.spacer {
margin: 2em;
}
\ No newline at end of file
}
/* width */
::-webkit-scrollbar {
width: 2px;
}
/* Track */
::-webkit-scrollbar-track {
box-shadow: inset 0 0 2px grey;
border-radius: 1px;
}
/* Handle */
::-webkit-scrollbar-thumb {
border-radius: 1px;
}
......@@ -16,5 +16,10 @@
(click)="chooseUser(user.uuid)"
mat-stroked-button>{{ user.email }}</button>
</mat-card-content>
<mat-card-actions>
<button
(click)="addAccount()"
mat-stroked-button>Add Account</button>
</mat-card-actions>
</mat-card>
</div>
import { Component, OnInit } from '@angular/core';
import { ChooseAccountService } from './choose-account.service';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { stringify } from 'querystring';
import { environment } from '../../environments/environment.prod';
......@@ -15,6 +15,7 @@ export class ChooseAccountComponent implements OnInit {
constructor(
private activeRoute: ActivatedRoute,
private chooseAccountService: ChooseAccountService,
private router: Router,
) {}
ngOnInit() {
......@@ -32,4 +33,10 @@ export class ChooseAccountComponent implements OnInit {
error: error => {},
});
}
addAccount() {
const query = { ...this.activeRoute.snapshot.queryParams };
query.login_type = 'add_account';
this.router.navigate(['/login'], { queryParams: query });
}
}
......@@ -4,7 +4,7 @@ import { FormGroup, FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { map } from 'rxjs/operators';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { MatSnackBar } from '@angular/material';
import {
PLEASE_CHECK_EMAIL,
......@@ -63,6 +63,7 @@ export class LoginComponent implements OnInit {
private authService: AuthService,
private breakpointObserver: BreakpointObserver,
private route: ActivatedRoute,
private router: Router,
private snackBar: MatSnackBar,
) {}
......@@ -91,7 +92,12 @@ export class LoginComponent implements OnInit {
.subscribe({
next: (response: any) => {
this.submitOTPForm.controls.code.setErrors(null);
window.location.href = response.path;
const loginType = this.route.snapshot.queryParams.login_type;
if (!loginType) {
window.location.href = response.path;
} else if (loginType === 'add_account') {
this.chooseAccount();
}
},
error: err => {
this.serverError = err.error.message;
......@@ -109,7 +115,12 @@ export class LoginComponent implements OnInit {
.subscribe({
next: (response: any) => {
this.submitOTPForm.controls.code.setErrors(null);
window.location.href = response.path;
const loginType = this.route.snapshot.queryParams.login_type;
if (!loginType) {
window.location.href = response.path;
} else if (loginType === 'add_account') {
this.chooseAccount();
}
},
error: err => {
this.serverError = err.error.message;
......@@ -148,7 +159,12 @@ export class LoginComponent implements OnInit {
.subscribe({
next: (response: any) => {
this.loginUserForm.controls.password.setErrors(null);
window.location.href = response.path;
const loginType = this.route.snapshot.queryParams.login_type;
if (!loginType) {
window.location.href = response.path;
} else if (loginType === 'add_account') {
this.chooseAccount();
}
},
error: err => {
this.serverError = err.error.message;
......@@ -236,4 +252,10 @@ export class LoginComponent implements OnInit {
this.hideCode = false;
this.resendOTP();
}
chooseAccount() {
const query = { ...this.route.snapshot.queryParams };
delete query.login_type;
this.router.navigate(['/account/choose'], { queryParams: query });
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment