Skip to content

Commit c8b6c7c

Browse files
committed
Merge branch 'fix/no-tld-emails-5410' into 'master'
Improve error handling around email during registration for edge-cases #5410 See merge request minds/front!1842
2 parents fdbd2b1 + 49041d1 commit c8b6c7c

File tree

3 files changed

+82
-4
lines changed

3 files changed

+82
-4
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { TestBed } from '@angular/core/testing';
2+
import { RegexService } from './regex.service';
3+
4+
describe('RegexService', () => {
5+
let service: RegexService;
6+
7+
beforeEach(() => {
8+
jasmine.clock().uninstall();
9+
jasmine.clock().install();
10+
11+
TestBed.configureTestingModule({
12+
providers: [],
13+
});
14+
15+
service = new RegexService();
16+
});
17+
18+
afterEach(() => {
19+
jasmine.clock().uninstall();
20+
});
21+
22+
it('should be instantiated', () => {
23+
expect(service).toBeTruthy();
24+
});
25+
26+
// Email
27+
28+
it('should validate email with just alphabetic characters', () => {
29+
expect(service.getRegex('mail').test('[email protected]')).toBeTruthy();
30+
});
31+
32+
it('should validate email with numbers', () => {
33+
expect(service.getRegex('mail').test('[email protected]')).toBeTruthy();
34+
});
35+
36+
it('should validate email with multiple numbers in domain', () => {
37+
expect(service.getRegex('mail').test('[email protected]')).toBeTruthy();
38+
});
39+
40+
it('should validate email with a mix of numbers and and alphabetic chars', () => {
41+
expect(service.getRegex('mail').test('[email protected]')).toBeTruthy();
42+
});
43+
44+
it('should validate email with a mix of numbers and valid alphabetic chars', () => {
45+
expect(service.getRegex('mail').test('[email protected]')).toBeTruthy();
46+
});
47+
48+
it('should validate email with a mix of special chars in username', () => {
49+
expect(
50+
service.getRegex('mail').test('t#e!s$t%1.&[email protected]')
51+
).toBeTruthy();
52+
});
53+
54+
it('should NOT validate an email without a domain name', () => {
55+
expect(service.getRegex('mail').test('[email protected]')).toBeFalsy();
56+
});
57+
58+
it('should NOT validate an email without a domain name OR TDL', () => {
59+
expect(service.getRegex('mail').test('test@')).toBeFalsy();
60+
});
61+
62+
it('should NOT validate an email without a username', () => {
63+
expect(service.getRegex('mail').test('@minds.com')).toBeFalsy();
64+
});
65+
66+
it('should NOT validate an email without a TLD', () => {
67+
expect(service.getRegex('mail').test('test@minds')).toBeFalsy();
68+
});
69+
70+
it('should NOT validate @ as an email', () => {
71+
expect(service.getRegex('mail').test('@')).toBeFalsy();
72+
});
73+
});

src/app/modules/forms/register/register.ng.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
}
9292

9393
.m-register__formError {
94-
margin-top: 20px;
94+
margin: 10px 0 10px 0;
9595
}
9696

9797
.m-register__error {

src/app/modules/forms/register/register.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616

1717
import { Client } from '../../../services/api';
1818
import { Session } from '../../../services/session';
19-
import { ExperimentsService } from '../../experiments/experiments.service';
2019
import { RouterHistoryService } from '../../../common/services/router-history.service';
2120
import {
2221
PopoverComponent,
@@ -70,7 +69,6 @@ export class RegisterForm {
7069
public client: Client,
7170
fb: FormBuilder,
7271
public zone: NgZone,
73-
private experiments: ExperimentsService,
7472
private routerHistoryService: RouterHistoryService,
7573
private usernameValidator: UsernameValidator
7674
) {
@@ -183,7 +181,14 @@ export class RegisterForm {
183181
this.session.logout();
184182
} else if (e.status === 'error') {
185183
// two factor?
186-
this.errorMessage = e.message;
184+
switch (e?.message) {
185+
case 'registration:notemail':
186+
this.errorMessage = 'Invalid Email';
187+
break;
188+
default:
189+
this.errorMessage = e.message ?? 'An unknown error has occurred';
190+
}
191+
187192
this.session.logout();
188193
} else {
189194
this.errorMessage = 'Sorry, there was an error. Please try again.';

0 commit comments

Comments
 (0)