-
-
diff --git a/frontend/app/login/login.component.ts b/frontend/app/login/login.component.ts
index 776d7c1..5499abc 100644
--- a/frontend/app/login/login.component.ts
+++ b/frontend/app/login/login.component.ts
@@ -1,9 +1,9 @@
import {Component, OnInit} from "@angular/core";
import {LoginCredential} from "../../../common/entities/LoginCredential";
import {AuthenticationService} from "../model/network/authentication.service";
-import {Router} from "@angular/router";
import {ErrorCodes} from "../../../common/entities/Error";
import {Config} from "../../../common/config/public/Config";
+import {NavigationService} from "../model/navigation.service";
@Component({
selector: 'login',
@@ -15,14 +15,14 @@ export class LoginComponent implements OnInit {
loginError: any = null;
title: string;
- constructor(private _authService: AuthenticationService, private _router: Router) {
+ constructor(private _authService: AuthenticationService, private _navigation: NavigationService) {
this.loginCredential = new LoginCredential();
this.title = Config.Client.applicationTitle;
}
ngOnInit() {
if (this._authService.isAuthenticated()) {
- this._router.navigate(['gallery', "/"]);
+ this._navigation.toGallery();
}
}
diff --git a/frontend/app/model/navigation.service.ts b/frontend/app/model/navigation.service.ts
new file mode 100644
index 0000000..56ed2d7
--- /dev/null
+++ b/frontend/app/model/navigation.service.ts
@@ -0,0 +1,38 @@
+import {Injectable} from "@angular/core";
+
+import {Router} from "@angular/router";
+import {ShareService} from "../gallery/share.service";
+
+@Injectable()
+export class NavigationService {
+
+
+ constructor(private _router: Router,
+ private _shareService: ShareService) {
+
+ }
+
+ public isLoginPage() {
+ return this._router.isActive('login', true) || this._router.isActive('shareLogin', true);
+ }
+
+ public async toLogin() {
+ console.log("toLogin");
+ await this._shareService.wait();
+ if (this._shareService.isSharing()) {
+ return this._router.navigate(["shareLogin"], {queryParams: {sk: this._shareService.getSharingKey()}});
+ } else {
+ return this._router.navigate(["login"]);
+ }
+ }
+
+ public async toGallery() {
+ console.log("toGallery");
+ await this._shareService.wait();
+ if (this._shareService.isSharing()) {
+ return this._router.navigate(["gallery", ""], {queryParams: {sk: this._shareService.getSharingKey()}});
+ } else {
+ return this._router.navigate(["gallery", ""]);
+ }
+ }
+}
diff --git a/frontend/app/model/network/authentication.service.ts b/frontend/app/model/network/authentication.service.ts
index 5079f26..0c1f394 100644
--- a/frontend/app/model/network/authentication.service.ts
+++ b/frontend/app/model/network/authentication.service.ts
@@ -43,9 +43,16 @@ export class AuthenticationService {
public async login(credential: LoginCredential): Promise
{
- const user = await this._userService.login(credential);
- this.user.next(user);
- return user;
+ const user = await this._userService.login(credential);
+ this.user.next(user);
+ return user;
+ }
+
+
+ public async shareLogin(password: string): Promise {
+ const user = await this._userService.shareLogin(password);
+ this.user.next(user);
+ return user;
}
@@ -56,7 +63,9 @@ export class AuthenticationService {
return !!(this.user.value && this.user.value != null);
}
-
+ public isAuthorized(role: UserRoles) {
+ return this.user.value && this.user.value.role >= role;
+ }
public logout() {
this._userService.logout();
diff --git a/frontend/app/model/network/user.service.ts b/frontend/app/model/network/user.service.ts
index dd94bc2..4b5d842 100644
--- a/frontend/app/model/network/user.service.ts
+++ b/frontend/app/model/network/user.service.ts
@@ -18,7 +18,11 @@ export class UserService {
}
public login(credential: LoginCredential): Promise {
- return this._networkService.postJson("/user/login", {"loginCredential": credential});
+ return this._networkService.postJson("/user/login", {"loginCredential": credential});
+ }
+
+ public async shareLogin(password: string): Promise {
+ return this._networkService.postJson("/share/login?sk=" + this._shareService.getSharingKey(), {"password": password});
}
public async getSessionUser(): Promise {
diff --git a/frontend/app/settings/database/database.settings.service.ts b/frontend/app/settings/database/database.settings.service.ts
index 1af38f9..7be853e 100644
--- a/frontend/app/settings/database/database.settings.service.ts
+++ b/frontend/app/settings/database/database.settings.service.ts
@@ -1,12 +1,21 @@
import {Injectable} from "@angular/core";
import {NetworkService} from "../../model/network/network.service";
import {DataBaseConfig, IPrivateConfig} from "../../../../common/config/private/IPrivateConfig";
+import {NavigationService} from "../../model/navigation.service";
+import {UserRoles} from "../../../../common/entities/UserDTO";
+import {AuthenticationService} from "../../model/network/authentication.service";
@Injectable()
export class DatabaseSettingsService {
- constructor(private _networkService: NetworkService) {
+ constructor(private _networkService: NetworkService, private _authService: AuthenticationService, private _navigation: NavigationService) {
+
+ if (!this._authService.isAuthenticated() ||
+ this._authService.user.value.role < UserRoles.Admin) {
+ this._navigation.toLogin();
+ return;
+ }
}
public async getSettings(): Promise {
diff --git a/frontend/app/settings/usermanager/usermanager.settings.component.ts b/frontend/app/settings/usermanager/usermanager.settings.component.ts
index 0a12cb4..b805851 100644
--- a/frontend/app/settings/usermanager/usermanager.settings.component.ts
+++ b/frontend/app/settings/usermanager/usermanager.settings.component.ts
@@ -1,10 +1,10 @@
import {Component, OnInit, ViewChild} from "@angular/core";
import {AuthenticationService} from "../../model/network/authentication.service";
-import {Router} from "@angular/router";
import {UserDTO, UserRoles} from "../../../../common/entities/UserDTO";
import {Utils} from "../../../../common/Utils";
import {UserManagerSettingsService} from "./usermanager.settings.service";
import {ModalDirective} from "ngx-bootstrap/modal";
+import {NavigationService} from "../../model/navigation.service";
@Component({
selector: 'settings-usermanager',
@@ -18,16 +18,18 @@ export class UserMangerSettingsComponent implements OnInit {
public userRoles: Array = [];
public users: Array = [];
- constructor(private _authService: AuthenticationService, private _router: Router, private _userSettings: UserManagerSettingsService) {
+ constructor(private _authService: AuthenticationService, private _navigation: NavigationService, private _userSettings: UserManagerSettingsService) {
}
ngOnInit() {
- if (!this._authService.isAuthenticated() || this._authService.user.value.role < UserRoles.Admin) {
- this._router.navigate(['login']);
+ if (!this._authService.isAuthenticated() ||
+ this._authService.user.value.role < UserRoles.Admin) {
+ this._navigation.toLogin();
return;
}
this.userRoles = Utils
.enumToArray(UserRoles)
+ .filter(r => r.key != UserRoles.LimitedGuest)
.filter(r => r.key <= this._authService.user.value.role)
.sort((a, b) => a.key - b.key);
diff --git a/frontend/app/sharelogin/share-login.component.css b/frontend/app/sharelogin/share-login.component.css
index 4cd6829..a24ad1c 100644
--- a/frontend/app/sharelogin/share-login.component.css
+++ b/frontend/app/sharelogin/share-login.component.css
@@ -1,3 +1,57 @@
-body {
- background: #eee;
+.container {
+}
+
+.title h1 {
+ font-size: 80px;
+ font-weight: bold;
+ white-space: nowrap;
+}
+
+.title img {
+ height: 80px;
+}
+
+.title {
+ margin-top: 40px;
+ width: 100%;
+ text-align: center;
+}
+
+.card {
+ padding: 15px;
+ max-width: 350px;
+ width: 100% !important;
+ background-color: #F7F7F7;
+ margin: 0 auto;
+ border-radius: 2px;
+ box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
+ overflow: hidden;
+ height: 150px;
+ margin-top: 0px;
+}
+
+/*Margin by pixel:*/
+@media screen and ( min-height: 400px ) {
+ .card {
+ margin-top: calc((100vh - 120px - 150px) / 2 - 60px)
+ }
+}
+
+.has-margin {
+ margin-bottom: 10px;
+}
+
+.input-group .form-control, .checkbox {
+ padding: 10px;
+ font-size: 16px;
+
+}
+
+.error-message {
+ color: #d9534f;
+}
+
+button {
+ width: 100%;
+ font-size: 18px;
}
diff --git a/frontend/app/sharelogin/share-login.component.html b/frontend/app/sharelogin/share-login.component.html
index 2f90493..6e69055 100644
--- a/frontend/app/sharelogin/share-login.component.html
+++ b/frontend/app/sharelogin/share-login.component.html
@@ -1,15 +1,41 @@
-
-
+
+
+
{{title}}
-
+
+
+
+
diff --git a/frontend/app/sharelogin/share-login.component.ts b/frontend/app/sharelogin/share-login.component.ts
index 0c05559..64764d5 100644
--- a/frontend/app/sharelogin/share-login.component.ts
+++ b/frontend/app/sharelogin/share-login.component.ts
@@ -1,8 +1,8 @@
import {Component, OnInit} from "@angular/core";
-import {LoginCredential} from "../../../common/entities/LoginCredential";
import {AuthenticationService} from "../model/network/authentication.service";
-import {Router} from "@angular/router";
import {ErrorCodes} from "../../../common/entities/Error";
+import {Config} from "../../../common/config/public/Config";
+import {NavigationService} from "../model/navigation.service";
@Component({
selector: 'share-login',
@@ -10,16 +10,17 @@ import {ErrorCodes} from "../../../common/entities/Error";
styleUrls: ['./share-login.component.css'],
})
export class ShareLoginComponent implements OnInit {
- loginCredential: LoginCredential;
+ password: string;
loginError: any = null;
+ title: string;
- constructor(private _authService: AuthenticationService, private _router: Router) {
- this.loginCredential = new LoginCredential();
+ constructor(private _authService: AuthenticationService, private _navigation: NavigationService) {
+ this.title = Config.Client.applicationTitle;
}
ngOnInit() {
if (this._authService.isAuthenticated()) {
- this._router.navigate(['gallery', "/"]);
+ this._navigation.toGallery();
}
}
@@ -27,11 +28,11 @@ export class ShareLoginComponent implements OnInit {
this.loginError = null;
try {
- await this._authService.login(this.loginCredential);
+ await this._authService.shareLogin(this.password);
} catch (error) {
if (error && error.code === ErrorCodes.CREDENTIAL_NOT_FOUND) {
- this.loginError = "Wrong username or password";
+ this.loginError = "Wrong password";
}
}
}
diff --git a/package.json b/package.json
index 16fde9d..5ca8c40 100644
--- a/package.json
+++ b/package.json
@@ -85,6 +85,7 @@
"ng2-slim-loading-bar": "^4.0.0",
"ng2-toastr": "^4.1.2",
"ngx-bootstrap": "^1.7.1",
+ "ngx-clipboard": "^8.0.3",
"phantomjs-prebuilt": "^2.1.14",
"protractor": "^5.1.2",
"remap-istanbul": "^0.9.5",
diff --git a/test/backend/unit/middlewares/uesr/AuthenticationMWs.ts b/test/backend/unit/middlewares/uesr/AuthenticationMWs.ts
index 897db8b..dfe7ef7 100644
--- a/test/backend/unit/middlewares/uesr/AuthenticationMWs.ts
+++ b/test/backend/unit/middlewares/uesr/AuthenticationMWs.ts
@@ -86,7 +86,7 @@ describe('Authentication middleware', () => {
let req: any = {
session: {
user: {
- role: UserRoles.Guest
+ role: UserRoles.LimitedGuest
}
}
};
@@ -94,7 +94,7 @@ describe('Authentication middleware', () => {
expect(err).to.be.undefined;
done();
};
- AuthenticationMWs.authorise(UserRoles.Guest)(req, null, next);
+ AuthenticationMWs.authorise(UserRoles.LimitedGuest)(req, null, next);
});
@@ -102,7 +102,7 @@ describe('Authentication middleware', () => {
let req: any = {
session: {
user: {
- role: UserRoles.Guest
+ role: UserRoles.LimitedGuest
}
}
};
@@ -230,7 +230,7 @@ describe('Authentication middleware', () => {
let req: any = {
session: {
user: {
- role: UserRoles.Guest
+ role: UserRoles.LimitedGuest
}
}
};