Skip to content

Commit cdd7d1d

Browse files
committed
Allow user registration w. local. Add qr code icon
1 parent 86f5022 commit cdd7d1d

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

OpenFlow/src/LoginProvider.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export class LoginProvider {
143143
var res2 = {
144144
wshost: _url,
145145
domain: Config.domain,
146+
allow_user_registration: Config.allow_user_registration,
146147
allow_personal_nodered: Config.allow_personal_nodered,
147148
namespace: Config.namespace,
148149
nodered_domain_schema: Config.nodered_domain_schema
@@ -293,10 +294,21 @@ export class LoginProvider {
293294
return done(null, tuser);
294295
}
295296
user = await User.FindByUsername(username);
296-
if (user === undefined || user === null) { return done(null, false); }
297-
if (!(await user.ValidatePassword(password))) {
298-
Audit.LoginFailed(username, "weblogin", "local", "");
299-
return done(null, false);
297+
if (user === undefined || user === null) {
298+
if (!Config.allow_user_registration) {
299+
return done(null, false);
300+
}
301+
user = new User(); user.name = username; user.username = username;
302+
await user.SetPassword(password);
303+
user = await Config.db.InsertOne(user, "users", 0, false, TokenUser.rootToken());
304+
var users: Role = await Role.FindByNameOrId("users", TokenUser.rootToken());
305+
users.AddMember(user);
306+
await users.Save(TokenUser.rootToken())
307+
} else {
308+
if (!(await user.ValidatePassword(password))) {
309+
Audit.LoginFailed(username, "weblogin", "local", "");
310+
return done(null, false);
311+
}
300312
}
301313
tuser = new TokenUser(user);
302314
Audit.LoginSuccess(tuser, "weblogin", "local", "");

OpenFlow/src/public/Controllers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ module openflow {
399399
public password: string = "";
400400
public message: string = "";
401401
public domain: string = "";
402+
public allow_user_registration: boolean = false;
402403
public static $inject = [
403404
"$scope",
404405
"$location",
@@ -415,6 +416,7 @@ module openflow {
415416
this.domain = window.location.hostname;
416417
WebSocketClient.getJSON("/loginproviders", async (error: any, data: any) => {
417418
this.providers = data;
419+
this.allow_user_registration = WebSocketClient.allow_user_registration;
418420
for (var i: number = this.providers.length - 1; i >= 0; i--) {
419421
if (this.providers[i].provider == "local") {
420422
this.providers.splice(i, 1);

OpenFlow/src/public/Login.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,26 @@ <h5 class="card-title text-center"><span translate lib="web">signin</span> {{ctr
2222
<button class="btn btn-lg btn-primary btn-block text-uppercase" type="submit" ng-show="ctrl.localenabled"
2323
translate lib="web">signin</button>
2424
<hr class="my-4" ng-show="ctrl.localenabled">
25-
<div class="form-label-group" ng-show="ctrl.qrcodescan">
26-
<button value="Scan now" ng-click="ctrl.Scan()" type="button">QRCode Scan</button>
27-
</div>
2825

2926
<a ng-href="/{{model.id}}" ng-repeat="model in ctrl.providers" class="btn btn-lg btn-block text-uppercase">
3027
<i class="fab {{model.logo}} mr-2"></i><span translate lib="web">{{model.name}}</span>
3128
</a>
29+
30+
<a href ng-click="ctrl.Scan()" ng-show="ctrl.qrcodescan" class="btn btn-lg btn-block text-uppercase">
31+
<i class="fas fa-qrcode mr-2"></i><span translate lib="web">QRCode Scan</span>
32+
</a>
33+
<div class="card-body" ng-show="ctrl.allow_user_registration==true">
34+
Select a provider or login using a local username and password.<br>
35+
A new user will automaticly be created if username is unknown.<br>
36+
Email validation will be requered to use the core functions.
37+
</div>
3238
</form>
3339
</div>
3440
</div>
3541
</div>
3642
</div>
3743
</div>
3844
<div class="cameraView" ng-show="ctrl.scanning==true">
39-
<button value="Scan now" ng-click="ctrl.Scan()" type="button" ng-show="ctrl.scanning==true">QRCode Scan</button>
45+
<a href ng-click="ctrl.Scan()" ng-show="ctrl.scanning==true" class="btn btn-lg btn-block text-uppercase">
46+
<i class="fas fa-qrcode mr-2"></i><span translate lib="web">QRCode Scan</span>
4047
</div>

OpenFlow/src/public/WebSocketClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ module openflow {
2626

2727
public domain: string = null;
2828
public allow_personal_nodered: boolean = false;
29+
public allow_user_registration: boolean = false;
30+
2931
public namespace: string = null;
3032
public nodered_domain_schema: string = null;
3133

@@ -206,6 +208,7 @@ module openflow {
206208
console.debug("WebSocketClient::onopen: connecting to " + data.wshost);
207209
this.domain = data.domain;
208210
this.allow_personal_nodered = data.allow_personal_nodered;
211+
this.allow_user_registration = data.allow_user_registration;
209212
this.namespace = data.namespace;
210213
this.nodered_domain_schema = data.nodered_domain_schema;
211214
this._socketObject = new ReconnectingWebSocket(data.wshost);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.250
1+
0.0.251

0 commit comments

Comments
 (0)