Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Dec 17, 2023
1 parent 1395e22 commit 6427fc8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 170 deletions.
39 changes: 0 additions & 39 deletions backend/files/system/auth/email-taken.get.hl

This file was deleted.

24 changes: 0 additions & 24 deletions backend/files/system/auth/impersonate.get.hl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class UserService {
* @param filter Optional query filter deciding which items to return
*/
list(params: string) {

return this.httpService.get<User[]>('/magic/system/magic/users' + params);
}

Expand All @@ -45,6 +46,7 @@ export class UserService {
* @param filter Optional query filter deciding which items to count
*/
count(params: string) {

return this.httpService.get<Count>('/magic/system/magic/users-count' + params);
}

Expand All @@ -55,6 +57,7 @@ export class UserService {
* @param password Initial password for user
*/
create(username: string, password: string) {

return this.httpService.post<any>('/magic/system/magic/users', {
username,
password
Expand All @@ -67,6 +70,7 @@ export class UserService {
* @param user User to update
*/
update(user: User) {

return this.httpService.put<any>('/magic/system/magic/users', {
username: user.username,
password: user.password,
Expand All @@ -83,6 +87,7 @@ export class UserService {
* @param releaseDate Date and time for when user can access Magic again
*/
imprison(username: string, releaseDate: Date) {

return this.httpService.put<MagicResponse>('/magic/system/auth/imprison', {
username,
releaseDate,
Expand All @@ -95,6 +100,7 @@ export class UserService {
* @param username Username of user you want to delete
*/
delete(username: string) {

return this.httpService.delete<any>('/magic/system/magic/users?username=' + encodeURIComponent(username));
}

Expand All @@ -104,6 +110,7 @@ export class UserService {
* @param username Username of user to retrieve roles for
*/
getRoles(username: string) {

return this.httpService.get<UserRoles[]>('/magic/system/magic/users_roles?user.eq=' + encodeURIComponent(username));
}

Expand All @@ -114,6 +121,7 @@ export class UserService {
* @param role Name of role to add user to
*/
addRole(user: string, role: string) {

return this.httpService.post<Affected>('/magic/system/magic/users_roles', {
user,
role,
Expand All @@ -127,38 +135,20 @@ export class UserService {
* @param role Name of role to remove user from
*/
removeRole(user: string, role: string) {

return this.httpService.delete<Affected>('/magic/system/magic/users_roles?user=' +
encodeURIComponent(user) +
'&role=' +
encodeURIComponent(role));
}

/**
* Creates a login link that can be used to authenticate as user.
*
* @param username Username to generate login link on behalf of
*/
public generateLoginLink(username: string) {
return this.httpService.get<AuthenticateResponse>(
'/magic/system/auth/impersonate?username=' +
encodeURIComponent(username));
}

/**
* Creates a login link that can be used by user to reset his or her password (only!).
*
* @param username Username to generate login link on behalf of
*/
public generateResetPasswordLink(username: string) {
return this.httpService.get<AuthenticateResponse>('/magic/system/auth/reset-password?username=' + encodeURIComponent(username));
}

/**
* Retrieving extra details of each user.
*
* @param username Username of the user
*/
public getUserExtra(username: string) {

return this.httpService.get<User_Extra>('/magic/system/magic/users_extra?user.eq=' + encodeURIComponent(username));
}

Expand All @@ -169,6 +159,7 @@ export class UserService {
* @param username Username of the user
*/
public deleteExtra(type: string, username: string) {

return this.httpService.delete<any>('/magic/system/magic/users_extra?type=' + encodeURIComponent(type) + '&user=' + encodeURIComponent(username));
}

Expand All @@ -178,6 +169,7 @@ export class UserService {
* @param extra Extra information
*/
public editExtra(extra: User_Extra) {

return this.httpService.put<any>('/magic/system/magic/users_extra', extra);
}

Expand All @@ -187,6 +179,7 @@ export class UserService {
* @param extra Extra information
*/
public addExtra(extra: User_Extra) {

return this.httpService.post<any>('/magic/system/magic/users_extra', extra);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,6 @@

<td mat-cell *matCellDef="let element">
<div class="d-flex justify-content-between align-items-center">
<div>

<button
mat-button
color="primary"
(click)="editUser(element)">
Edit
</button>

<button
mat-button
color="primary"
(click)="changePassword(element)">
Change password
</button>

</div>

<button
mat-icon-button
Expand All @@ -86,20 +69,20 @@

<button
mat-menu-item
(click)="lockedChanged(element)">
{{element?.locked ? 'Unlock' : 'Lock'}}
(click)="editUser(element)">
Edit
</button>

<button
mat-menu-item
(click)="generateResetPasswordLink(element)">
Create reset password link
(click)="changePassword(element)">
Change password
</button>

<button
mat-menu-item
(click)="generateLoginLink(element)">
Login as {{element?.username}}
(click)="lockedChanged(element)">
{{element?.locked ? 'Unlock' : 'Lock'}}
</button>

<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
* Copyright (c) 2023 Thomas Hansen - For license inquiries you can contact thomas@ainiro.io.
*/

import { PlatformLocation } from '@angular/common';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { User } from 'src/app/_protected/pages/manage/user-and-roles/_models/user.model';
import { BackendService } from 'src/app/_general/services/backend.service';
import { AuthenticateResponse } from '../_models/authenticate-response.model';
import { UserService } from '../_services/user.service';
import { Clipboard } from '@angular/cdk/clipboard';
import { GeneralService } from 'src/app/_general/services/general.service';
import { MatDialog } from '@angular/material/dialog';
import { ConfirmationDialogComponent } from 'src/app/_general/components/confirmation-dialog/confirmation-dialog.component';
Expand Down Expand Up @@ -43,65 +39,8 @@ export class UsersListComponent {

constructor(
private dialog: MatDialog,
private clipboard: Clipboard,
private userService: UserService,
private generalService: GeneralService,
private backendService: BackendService,
private platformLocation: PlatformLocation) { }

generateResetPasswordLink(user: User) {

this.generalService.showLoading();
this.userService.generateResetPasswordLink(user.username).subscribe({
next: (result: AuthenticateResponse) => {

this.generalService.hideLoading();
const location: any = this.platformLocation;
const url = location.location.origin.toString() +
'/authentication/auto-auth?token=' +
encodeURIComponent(result.ticket) +
'&username=' +
encodeURIComponent(user.username) +
'&url=' +
encodeURIComponent(this.backendService.active.url);

this.clipboard.copy(url);
this.generalService.showFeedback('Reset password link is copied to your clipboard', 'successMessage');
},
error: (error: any) => {

this.generalService.hideLoading();
this.generalService.showFeedback(error?.error?.message ?? error, 'errorMessage');
}
});
}

generateLoginLink(user: User) {

this.generalService.showLoading();
this.userService.generateLoginLink(user.username).subscribe({
next: (result: AuthenticateResponse) => {

this.generalService.hideLoading();
const location: any = this.platformLocation;
const url = location.location.origin.toString() + '/authentication/auto-auth' +
'/?token=' +
encodeURIComponent(result.ticket) +
'&username=' +
encodeURIComponent(user.username) +
'&url=' +
encodeURIComponent(this.backendService.active.url);

this.clipboard.copy(url);
this.generalService.showFeedback('Login link is copied to your clipboard', 'successMessage');
},
error: (error: any) => {

this.generalService.hideLoading();
this.generalService.showFeedback(error?.error?.message ?? error, 'errorMessage');
}
});
}
private generalService: GeneralService) { }

lockedChanged(user: User) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export class CryptoService {
constructor(private httpService: HttpService) { }

/**
* Retrieves the long lasting JWT token and returns to caller.
* Retrieves JWT token and returns to caller.
*/
generateToken(username: string, role: string, expires: string) {
const param: string = `?username=${encodeURIComponent(username)}&role=${encodeURIComponent(role)}&expires=${encodeURIComponent(expires)}`
return this.httpService.get<any>('/magic/system/auth/generate-key' + param);
return this.httpService.get<any>('/magic/system/auth/generate-token' + param);
}
}

0 comments on commit 6427fc8

Please sign in to comment.