Skip to content

Commit

Permalink
Merge pull request #1770 from thebiggive/BG2-2745-register-without-tr…
Browse files Browse the repository at this point in the history
…ansfering-funds

BG2-2745: Allow registration via registration page without viewing do…
  • Loading branch information
bdsl authored Nov 26, 2024
2 parents 0b0beaa + a375ef1 commit 1352d8a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ <h2 mat-dialog-title>Reset Password</h2>
#frccaptcha
></div>
<hr style="margin: 20px auto;">
<a href="{{'/' + registerPath}}">Create new Donation Funds account</a>
<a href="{{registerLink}}">Create new donation account</a>
</biggive-page-section>
</div>
</main>
Expand Down
5 changes: 4 additions & 1 deletion src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class LoginComponent implements OnInit, AfterViewInit, OnDestroy{
/** Used to prevent displaying the page before all parts are ready **/
public pageInitialised = false;
private captchaCode: string | undefined;
protected registerLink: string;

constructor(
private readonly formBuilder: FormBuilder,
Expand Down Expand Up @@ -89,9 +90,11 @@ export class LoginComponent implements OnInit, AfterViewInit, OnDestroy{

// allowed chars in URL to redirect to: a-z, A-Z, 0-9, - _ /
if (redirectParam && isAllowableRedirectPath(redirectParam)) {
this.redirectPath = '/' + redirectParam;
this.redirectPath = '/' + redirectParam.replace(/^\/+/, ''); // strips any leading slashes
}

this.registerLink = `/${registerPath}?r=` + encodeURIComponent(this.redirectPath);

this.pageInitialised = true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/register/register.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Registering for a Donor Account is quick and easy.
</p>

@if (redirectPath === transferFundsPath) {
<p>
When you have registered, you will be shown the Transfer Funds page. Here, you can:
</p>
Expand All @@ -29,6 +30,7 @@

<li>Choose whether you would like to join Big Give’s mailing list</li>
</ul>
}

<form
[formGroup]="registrationForm"
Expand Down
16 changes: 14 additions & 2 deletions src/app/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from "@angular/
import {IdentityService} from "../identity.service";
import {environment} from "../../environments/environment";
import {EMAIL_REGEXP} from "../validators/patterns";
import {Router} from "@angular/router";
import {ActivatedRoute, Router} from "@angular/router";
import {MatAutocompleteModule} from "@angular/material/autocomplete";
import {DomSanitizer, SafeHtml} from "@angular/platform-browser";
import {transferFundsPath} from "../app-routing";
import {WidgetInstance} from "friendly-challenge";
import {flags} from "../featureFlags";
import {isAllowableRedirectPath} from "../login/login.component";

@Component({
selector: 'app-register',
Expand All @@ -28,6 +29,7 @@ export class RegisterComponent implements OnInit, OnDestroy, AfterViewInit {
@ViewChild('frccaptcha', { static: false })
protected friendlyCaptcha: ElementRef<HTMLElement>;
friendlyCaptchaSiteKey = environment.friendlyCaptchaSiteKey;
protected readonly transferFundsPath = transferFundsPath;


protected processing = false;
Expand All @@ -38,13 +40,15 @@ export class RegisterComponent implements OnInit, OnDestroy, AfterViewInit {
private friendlyCaptchaSolution: string|undefined;
protected readonly flags = flags;
private friendlyCaptchaWidget: WidgetInstance;
protected redirectPath: string = 'my-account';


constructor(
private readonly formBuilder: FormBuilder,
private readonly identityService: IdentityService,
private readonly router: Router,
private sanitizer: DomSanitizer,
private readonly activatedRoute: ActivatedRoute,
@Inject(PLATFORM_ID) private platformId: Object,
) {
}
Expand All @@ -69,6 +73,13 @@ export class RegisterComponent implements OnInit, OnDestroy, AfterViewInit {
Validators.pattern(EMAIL_REGEXP),
]],
});

const redirectParam = this.activatedRoute.snapshot.queryParams.r as string|undefined;

// allowed chars in URL to redirect to: a-z, A-Z, 0-9, - _ /
if (redirectParam && isAllowableRedirectPath(redirectParam)) {
this.redirectPath = redirectParam.replace(/^\/+/, ''); // strips any leading slashes;
}
}

async ngAfterViewInit() {
Expand Down Expand Up @@ -152,7 +163,8 @@ export class RegisterComponent implements OnInit, OnDestroy, AfterViewInit {
next: () => {
// We can't re-use a captcha code twice, so auto-login won't work right now. For now we just
// redirect to the login form
window.location.href = "/login";
const newPath = "/login" + '?r=' + encodeURIComponent(this.redirectPath);
window.location.href = newPath;
},
error: (error) => {
extractErrorMessage(error);
Expand Down

0 comments on commit 1352d8a

Please sign in to comment.