Skip to content
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
eae35f7
Login, reset forms
femastro Oct 9, 2020
1421a4f
....check
femastro Oct 10, 2020
8b340de
--amend
femastro Oct 10, 2020
172ffa8
control de version.
femastro Oct 10, 2020
035f983
Update after add
femastro Oct 10, 2020
c87632b
Se paso el cierre del sidebar al auth.service para no repetir codigo
femastro Oct 10, 2020
dc0c684
In the user.service when creating a new user it returns error.
femastro Oct 10, 2020
67f6c23
Se agrego Swal en Update, New y Delete
femastro Oct 10, 2020
fc5a2c6
... update
femastro Oct 10, 2020
663cc8b
... se corrigio error de tipeo en users.service
femastro Oct 10, 2020
90c3e2f
encontre el error, estaba en la API userController.ts devolvia res.…
femastro Oct 11, 2020
2d4ebaf
...Update 11 Octubre
femastro Oct 11, 2020
d293856
--amend
femastro Oct 11, 2020
77ce3c3
--amend
femastro Oct 11, 2020
ffc6fd8
--amend
femastro Oct 11, 2020
e6b7ffd
-a
femastro Oct 11, 2020
aa31fba
--amend
femastro Oct 12, 2020
66605d5
--amend
femastro Oct 12, 2020
47ba9c6
--amend
femastro Oct 12, 2020
0f06f9c
--amend
femastro Oct 12, 2020
96d8e46
--amend
femastro Oct 12, 2020
9978f4e
--amend
femastro Oct 12, 2020
cfc6ae1
--amend
femastro Oct 12, 2020
931bf43
UPDATE: UserController.ts error return error in new. Modal.componen…
femastro Oct 13, 2020
1ce88da
--amend
femastro Oct 13, 2020
ee1c69f
--amend
femastro Oct 13, 2020
453a822
--amend
femastro Oct 22, 2020
4402def
--amend
femastro Oct 22, 2020
88ea9cb
Merge branch 'femastro' of https://github.com/femastro/mysql_node_ang…
femastro Oct 22, 2020
cf4d9e0
update 22/oct
femastro Oct 23, 2020
9261bf3
The user was put in the header next to the logout, I corrected the lo…
femastro Oct 23, 2020
1988c74
Merge branch 'femastro' of https://github.com/femastro/mysql_node_ang…
femastro Oct 24, 2020
b33ed6c
update 25Oct.
femastro Oct 24, 2020
e18ee41
Se Agrego forgot password en la Api
femastro Nov 29, 2020
b1bec03
--amend
Nov 29, 2020
288795a
--amend
Nov 29, 2020
59de6f3
--amend
femastro Dec 1, 2020
e957d75
--amend
femastro Dec 1, 2020
1635118
--amend
femastro Dec 1, 2020
7da35e2
--amend
femastro Dec 1, 2020
6d84c59
--amend
femastro Dec 1, 2020
3ea6803
--amend
femastro Dec 1, 2020
a5453bc
--amend
femastro Dec 1, 2020
872ea52
--amend
femastro Dec 1, 2020
a8a8af4
--amend
femastro Dec 1, 2020
df67eef
Se agrego el Forgot password en la API
femastro Dec 1, 2020
bce1156
--amend
femastro Dec 3, 2020
2dca55f
hay error en la ejecucion del nodemailer
femastro Dec 3, 2020
d4bbc07
--amend
Dec 3, 2020
88102c2
Se creo RefreshToken
Dec 5, 2020
eefa2d7
Se Aggrego componente forgot password
Dec 5, 2020
94a7b95
--amend
femastro Dec 7, 2020
edd1b99
--amend
femastro Dec 7, 2020
46de154
Merge branch 'femastro' of https://github.com/femastro/mysql_node_ang…
femastro Dec 7, 2020
db4c08d
--amend
femastro Dec 7, 2020
4bfd468
--amend
femastro Dec 7, 2020
ff50dfc
se corrigio bd
femastro Dec 8, 2020
9394c8d
Merge branch 'femastro' of https://github.com/femastro/mysql_node_ang…
femastro Dec 8, 2020
c4ebcf7
--amend
femastro Dec 9, 2020
aeac30d
--amend
femastro Dec 11, 2020
c27367c
--amend
femastro Dec 11, 2020
4e73fe4
Delete gmail.ts
femastro Dec 11, 2020
0227340
Delete ormconfig.json
femastro Dec 11, 2020
55bf38b
--amend
femastro Dec 11, 2020
eef845d
Se corrigeron algunos errores.
femastro Dec 11, 2020
93a6ebd
Delete package-lock.json
femastro Dec 12, 2020
1e3e2c1
Update README.md
femastro Dec 12, 2020
d71def6
--amend
femastro Dec 15, 2020
ba3dbd7
--amend
femastro Dec 15, 2020
072a382
--amend
femastro Dec 15, 2020
a78bd49
Merge branch 'femastro' of https://github.com/femastro/mysql_node_ang…
femastro Jun 24, 2021
77c0f49
--amend
femastro Jun 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# Base de Datos
API/ormconfig.json

# compiled output
/dist
/tmp
Expand Down
8 changes: 4 additions & 4 deletions API/ormconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"type": "mysql",
"host": "XXXXXXXXX",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Te recomiendo que NO subas este fichero

"host": "localhost",
"port": 3306,
"username": "XXXXXX",
"password": "XXXXXX",
"database": "XXXXXXXX",
"username": "root",
"password": "",
"database": "casa",
"synchronize": true,
"logging": false,
"entities": ["src/entity/**/*.ts"],
Expand Down
4 changes: 2 additions & 2 deletions API/src/controller/AuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AuthController {

// Check password
if (!user.checkPassword(password)) {
return res.status(400).json({ message: 'Username or Password are incorrect!' });
return res.status(400).json({ message: 'Username or Password are incorrect!' });
}

const token = jwt.sign({ userId: user.id, username: user.username }, config.jwtSecret, { expiresIn: '1h' });
Expand All @@ -50,7 +50,7 @@ class AuthController {
}

if (!user.checkPassword(oldPassword)) {
return res.status(401).json({ message: 'Check your old Password' });
return res.status(401).json({ message: 'Check your old Password' });
}

user.password = newPassword;
Expand Down
5 changes: 3 additions & 2 deletions API/src/controller/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export class UserController {
return res.status(409).json({ message: 'Username already exist' });
}
// All ok
res.send('User created');
//res.send('User created'); this line change by line 61.
res.status(201).json({ message : 'User Created !'});
};

static edit = async (req: Request, res: Response) => {
Expand Down Expand Up @@ -88,7 +89,7 @@ export class UserController {
return res.status(409).json({ message: 'Username already in use' });
}

res.status(201).json({ message: 'User update' });
res.status(201).json({ message: 'User update !' });
};

static delete = async (req: Request, res: Response) => {
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@auth0/angular-jwt": "^5.0.1",
"concurrently": "^5.2.0",
"rxjs": "~6.5.5",
"sweetalert2": "^10.4.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.3"
},
Expand Down
5 changes: 5 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const routes: Routes = [
loadChildren: () =>
import('./pages/home/home.module').then((m) => m.HomeModule),
},
{
path: 'home',
loadChildren: () =>
import('./pages/home/home.module').then((m) => m.HomeModule),
},
{
path: 'notFound',
loadChildren: () =>
Expand Down
9 changes: 8 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<mat-sidenav-container>
<mat-sidenav #sidenav mode="side" [(opened)]="opened">
<mat-toolbar color="primary">Menu</mat-toolbar>
<mat-toolbar color="primary">
<span>
<button mat-icon-button (click)="closeMenu()">
<mat-icon>close</mat-icon>
</button>&nbsp;
</span>
Menu
</mat-toolbar>
<app-sidebar></app-sidebar>
</mat-sidenav>
<mat-sidenav-content>
Expand Down
14 changes: 12 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Router } from '@angular/router';
import { takeUntil } from 'rxjs/operators';
import { UtilsService } from './shared/services/utils.service';
import { UtilsService } from '@shared/services/utils.service';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';

Expand All @@ -10,16 +11,25 @@ import { Subject } from 'rxjs';
})
export class AppComponent implements OnInit, OnDestroy {
opened = false;

private destroy$ = new Subject<any>();

constructor(private utilsSvc: UtilsService, private router: Router) {}

closeMenu(): void{
this.utilsSvc.openSidebar(false);
this.router.navigate(['/home']);
}

constructor(private utilsSvc: UtilsService) {}

ngOnInit(): void {
this.utilsSvc.sidebarOpened$
.pipe(takeUntil(this.destroy$))
.subscribe((res: boolean) => (this.opened = res));
}



ngOnDestroy(): void {
this.destroy$.next({});
this.destroy$.complete();
Expand Down
37 changes: 28 additions & 9 deletions src/app/pages/admin/components/modal/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,66 @@ enum Action {
EDIT = 'edit',
NEW = 'new',
}
import Swal from 'sweetalert2';

@Component({
selector: 'app-modal',
templateUrl: './modal.component.html',
styleUrls: ['./modal.component.scss'],
})
export class ModalComponent implements OnInit {

actionTODO = Action.NEW;
showPasswordField = true;
hide = true;

constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
public userForm: BaseFormUser,
private userSvc: UsersService
) {}

ngOnInit(): void {

this.userForm.baseForm.reset(); // Clear Form , left the inputs loaded

if (this.data?.user.hasOwnProperty('id')) {

this.actionTODO = Action.EDIT;
this.showPasswordField = false;
this.userForm.baseForm.get('password').setValidators(null);
this.userForm.baseForm.updateValueAndValidity();
this.data.title = 'Edit user';
this.pathFormData();

}
}

onSave(): void {
const formValue = this.userForm.baseForm.value;
if (this.actionTODO === Action.NEW) {
this.userSvc.new(formValue).subscribe((res) => {
console.log('New ', res);
});
} else {

const formValue = this.userForm.baseForm.value;
if ( this.actionTODO === Action.NEW ) {
this.userSvc.new(formValue).subscribe((res) =>
this.swal(res['message'])
);
}else{
const userId = this.data?.user?.id;
this.userSvc.update(userId, formValue).subscribe((res) => {
console.log('Update', res);
});
this.userSvc.update(userId, formValue).subscribe( (res) =>
this.swal(res['message'])
);
}
}

swal(title: string){
Swal.fire({
position: 'top',
icon: 'success',
title: title,
showConfirmButton: false,
timer: 1500
})
}

checkField(field: string): boolean {
return this.userForm.isValidField(field);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/admin/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class UsersService {

new(user: User): Observable<User> {
return this.http
.post<User>(`${environment.API_URL}/users`, user)
.post<User>(`${environment.API_URL}/users/`, user)
.pipe(catchError(this.handlerError));
}

Expand All @@ -44,9 +44,9 @@ export class UsersService {
handlerError(error): Observable<never> {
let errorMessage = 'Error unknown';
if (error) {
errorMessage = `Error ${error.message}`;
errorMessage = `Error ::: ${error.message}`;
}
window.alert(errorMessage);
//////window.alert(errorMessage); /// Devuelve un Error !
return throwError(errorMessage);
}
}
48 changes: 39 additions & 9 deletions src/app/pages/admin/users/users.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { MatSort } from '@angular/material/sort';
import { MatDialog } from '@angular/material/dialog';
import { ModalComponent } from './../components/modal/modal.component';
import { Subject } from 'rxjs';
import Swal from 'sweetalert2';

@Component({
selector: 'app-users',
templateUrl: './users.component.html',
Expand All @@ -35,25 +37,53 @@ export class UsersComponent implements AfterViewInit, OnInit, OnDestroy {
ngAfterViewInit(): void {
this.dataSource.sort = this.sort;
}

onDelete(userId: number): void {
if (window.confirm('Do you really want remove this user')) {
this.userSvc
.delete(userId)
.pipe(takeUntil(this.destroy$))
.subscribe((res) => {
window.alert(res);

Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
this.userSvc
.delete(userId)
.pipe(takeUntil(this.destroy$))
.subscribe((res) => {
console.log("Del ->", res)
// Update result after deleting the user.
this.userSvc.getAll().subscribe((users) => {
this.dataSource.data = users;
});
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success',
)
});
}
}
});
}

onOpenModal(user = {}): void {
console.log('User->', user);
this.dialog.open(ModalComponent, {
console.log('User ->', user);
let dialogRef = this.dialog.open(ModalComponent, {
height: '400px',
width: '600px',
hasBackdrop: false,
data: { title: 'New user', user },
});
dialogRef.afterClosed().subscribe(result => {
console.log(`Dialog result: ${result}`, typeof result);
// Update result after adding new user.
this.userSvc.getAll().subscribe((users) => {
this.dataSource.data = users;
});
});
}

ngOnDestroy(): void {
Expand Down
19 changes: 17 additions & 2 deletions src/app/pages/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { UtilsService } from './../../shared/services/utils.service';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import { Injectable } from '@angular/core';
import { environment } from '@env/environment';
import { Observable, throwError, BehaviorSubject } from 'rxjs';

import { UserResponse, User, Roles } from '@shared/models/user.interface';
import { UserResponse, User } from '@shared/models/user.interface';
import { catchError, map } from 'rxjs/operators';
import { JwtHelperService } from '@auth0/angular-jwt';

Expand All @@ -14,9 +15,16 @@ const helper = new JwtHelperService();
providedIn: 'root',
})
export class AuthService {

private user = new BehaviorSubject<UserResponse>(null);

constructor(private http: HttpClient, private router: Router) {
constructor(

private http: HttpClient,
private router: Router,
private utilsSvc: UtilsService

) {
this.checkToken();
}
get user$(): Observable<UserResponse> {
Expand All @@ -26,6 +34,7 @@ export class AuthService {
get userValue(): UserResponse {
return this.user.getValue();
}

login(authData: User): Observable<UserResponse | void> {
return this.http
.post<UserResponse>(`${environment.API_URL}/auth/login`, authData)
Expand All @@ -40,12 +49,17 @@ export class AuthService {
}

logout(): void {

localStorage.removeItem('user');
this.user.next(null);

this.utilsSvc.openSidebar(false);
this.router.navigate(['/login']);

}

private checkToken(): void {

const user = JSON.parse(localStorage.getItem('user')) || null;

if (user) {
Expand All @@ -56,6 +70,7 @@ export class AuthService {
} else {
this.user.next(user);
}

}
}

Expand Down
1 change: 1 addition & 0 deletions src/app/pages/auth/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class LoginComponent implements OnInit, OnDestroy {
) {}

ngOnInit(): void {
this.loginForm.baseForm.reset();
this.loginForm.baseForm.get('role').setValidators(null);
this.loginForm.baseForm.get('role').updateValueAndValidity();
}
Expand Down
3 changes: 0 additions & 3 deletions src/app/pages/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
<h1 *ngIf="(authSvc.user$ | async) as user">
Welcome, {{ user?.username || 'User' }}.
</h1>
<p>home works!</p>
Loading