Skip to content

Commit 82a1f12

Browse files
committed
Logon no Authentication
1 parent c2100ab commit 82a1f12

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

src/app/configure/configure.component.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ export class ConfigureComponent implements OnInit {
6969
configObservable = this.entityApiService.getConfiguration();
7070
sslFiles: string[] = [];
7171
sub: Subscription;
72-
toUrl: string | undefined = undefined;
7372
mqttConnectIcon: string = "cast";
7473
mqttConnectClass: string = "redIcon";
7574
mqttConnectMessage: string = "unknown";
7675

7776
configureMqttFormGroup = this._formBuilder.group({
7877
mqttserverurl: [null as string | null, Validators.required],
79-
mqttuser: [null as string | null, Validators.required],
80-
mqttpassword: [null as string | null, Validators.required],
78+
mqttuser: [null as string | null],
79+
mqttpassword: [null as string | null],
8180
mqttkeyfile: [null as string | null],
8281
mqttcafile: [null as string | null],
8382
});
@@ -110,9 +109,7 @@ export class ConfigureComponent implements OnInit {
110109
this.entityApiService.getSslFiles().subscribe((rc) => {
111110
this.sslFiles = rc;
112111
});
113-
this.sub = this.route.paramMap.subscribe((params) => {
114-
this.toUrl = params.get("toUrl") || "";
115-
});
112+
116113
this.mqttValidate();
117114
if (config.githubPersonalToken)
118115
this.ghPersonalAccessToken.setValue(config.githubPersonalToken);
@@ -130,9 +127,7 @@ export class ConfigureComponent implements OnInit {
130127
mqttserverurl &&
131128
mqttuser &&
132129
mqttpassword &&
133-
mqttserverurl.value &&
134-
mqttuser.value &&
135-
mqttpassword.value
130+
mqttserverurl.value
136131
) {
137132
{
138133
if (!config.mqttconnect) config.mqttconnect = {};
@@ -158,9 +153,7 @@ export class ConfigureComponent implements OnInit {
158153
}
159154

160155
onChangekMqttConfig() {
161-
if (this.configureMqttFormGroup.touched) {
162156
this.mqttValidate();
163-
}
164157
}
165158
getSslFiles(): Observable<string[]> {
166159
return this.entityApiService.getSslFiles();
@@ -181,8 +174,7 @@ export class ConfigureComponent implements OnInit {
181174
}
182175

183176
close() {
184-
if (this.toUrl && this.toUrl.length > 0) this.router.navigate([this.toUrl]);
185-
else this.router.navigate(["/"]);
177+
this.router.navigate(["/"]);
186178
}
187179

188180
hasConfigChanges(): boolean {
@@ -202,7 +194,7 @@ export class ConfigureComponent implements OnInit {
202194
if (result && result.valid) {
203195
this.mqttConnectIcon = "cast_connected";
204196
this.mqttConnectClass = "greenIcon";
205-
this.mqttConnectMessage = "connected";
197+
this.mqttConnectMessage = "connected";
206198
} else {
207199
this.mqttConnectIcon = "cast";
208200
this.mqttConnectClass = "redIcon";

src/app/login/login.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ <h3 mat-dialog-title>{{ (isRegisterMode?'Register User':'Login') }}</h3>
44
</div>
55
<mat-form-field class="width250pt, center">
66
<mat-label>Username</mat-label>
7-
<input id="username" matInput class="width150pt"
7+
<input tabindex="0" id="username" matInput class="width150pt"
88
formControlName="username" >
99
<mat-error *ngIf="form.get('username')!.hasError('required') != null">
1010
Username is a required field
1111
</mat-error>
1212
</mat-form-field >
1313
<mat-form-field class="small-width right" class="width250pt, center">
1414
<mat-label>Password</mat-label>
15-
<input #password matInput
15+
<input tabindex="1" matInput
1616
formControlName="password" [type]="hide ? 'password' : 'text'">
1717
<mat-icon matSuffix (click)="hide = !hide">{{hide ? 'visibility_off' : 'visibility'}}</mat-icon>
1818
<mat-error *ngIf="form.get('password')!.hasError('required') != null">
1919
Password is a required field
2020
</mat-error>
2121
</mat-form-field>
2222
<mat-card-actions class="width250pt, center">
23-
<button mat-raised-button type="submit" color="primary">{{ (isRegisterMode?'REGISTER and LOGIN':'LOGIN') }}</button>
24-
<button *ngIf="isRegisterMode" mat-raised-button type="submit" value="noAuthentication" color="primary">No Authorization required</button>
23+
<button tabindex="2" *ngIf="isRegisterMode" mat-raised-button type="submit" value="noAuthentication" >No Authorization required</button>
24+
<button tabindex="3" mat-raised-button type="submit" value="authentication" color="primary">{{ (isRegisterMode?'REGISTER and LOGIN':'LOGIN') }}</button>
2525
</mat-card-actions>
2626
</form>

src/app/login/login.component.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
Validators,
66
FormsModule,
77
ReactiveFormsModule,
8+
ValidatorFn,
9+
AbstractControl,
10+
ValidationErrors,
811
} from "@angular/forms";
912
import { ApiService } from "../services/api-service";
1013
import { SessionStorage } from "../services/SessionStorage";
@@ -55,28 +58,24 @@ export class LoginComponent implements OnInit, AfterViewInit {
5558
private route: ActivatedRoute,
5659
) {}
5760
ngAfterViewInit(): void {
58-
let posRegister = this.router.url.indexOf("register");
59-
// If the url part of the URL and not the parameter contains register, we are in register mode
60-
this.isRegisterMode = posRegister >= 0;
6161
this.sub = this.route.paramMap.subscribe((params) => {
6262
this.toUrl = params.get("toUrl") || "";
6363
});
6464
}
6565

6666
ngOnInit(): void {
67-
this.form = this._formBuilder.group({
68-
username: ["", Validators.required],
69-
password: ["", Validators.required],
70-
});
67+
let posRegister = this.router.url.indexOf("register");
68+
// If the url part of the URL and not the parameter contains register, we are in register mode
69+
this.isRegisterMode = posRegister >= 0;
70+
this.form = this._formBuilder.group({
71+
username: ["", this.usernamePasswordRequired],
72+
password: ["", this.usernamePasswordRequired],
73+
});
7174
}
72-
private login(username: string, password: string) {
75+
private login(username: string, password: string, toUrl:string) {
7376
this.api.getUserLogin(username, password).subscribe((token) => {
7477
new SessionStorage().setAuthToken(token);
75-
var u = new URLSearchParams(this.router.url.replace(/^[^?]*\?/, ""));
76-
var toUrl = u.get("toUrl");
77-
if (u && toUrl) this.toUrl = toUrl;
78-
else this.toUrl = "";
79-
this.router.navigate([this.toUrl], {
78+
this.router.navigate([toUrl], {
8079
queryParams: { tokenWasExpired: true },
8180
});
8281
});
@@ -86,11 +85,26 @@ export class LoginComponent implements OnInit, AfterViewInit {
8685
let password = this.form.get("password")!.value;
8786
if (this.isRegisterMode) {
8887
let noAuthentication = (event.submitter as HTMLButtonElement).value == 'noAuthentication'
88+
if(!noAuthentication && !username)
89+
alert("Please enter a username")
90+
else if(!noAuthentication && !password)
91+
alert("Please enter a password")
92+
else
8993
this.api.postUserRegister(username, password, noAuthentication) .subscribe(() => {
9094
if(!noAuthentication)
91-
this.login(username, password);
95+
this.login(username, password, '/');
9296
else this.router.navigate(['/'], {});
9397
});
94-
} else this.login(username, password);
98+
} else this.login(username, password, '/');
9599
}
100+
usernamePasswordRequired(): ValidatorFn {
101+
return (control:AbstractControl) : ValidationErrors | null => {
102+
if( !this.isRegisterMode)
103+
return Validators.required(control)
104+
else{
105+
return null;
106+
}
107+
}
108+
}
109+
96110
}

0 commit comments

Comments
 (0)