-
Notifications
You must be signed in to change notification settings - Fork 2
/
LoginVisitor.ts
51 lines (39 loc) · 1.27 KB
/
LoginVisitor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {DialogProxyTools} from "./DialogProxyTools";
import {JsonObjectVisitor} from "./JsonObjectVisitor";
/**
*
*/
export class LoginVisitor implements JsonObjectVisitor {
private _enclosedJsonObject: any;
constructor(value: string | object) {
if (!value) {
throw new Error('LoginVisitor -- null value exception')
}
if (typeof value === 'string') {
this._enclosedJsonObject = JSON.parse(value as string);
} else {
this._enclosedJsonObject = value;
}
if (!DialogProxyTools.isLoginModel(this._enclosedJsonObject)) {
throw new Error("Object passed to LoginVisitor is not a Login");
}
}
// --- State Management Helpers --- //
// --- State Import/Export --- //
public copyAsJsonObject(): object {
return JSON.parse(this.copyAsJsonString());
}
public copyAsJsonString(): string {
return JSON.stringify(this.enclosedJsonObject());
}
public enclosedJsonObject() {
return this._enclosedJsonObject;
}
// --- State Management --- //
public visitPassword(): string {
return this.enclosedJsonObject().password;
}
public visitUserId(): string {
return this.enclosedJsonObject().userId;
}
}