diff options
28 files changed, 742 insertions, 100 deletions
diff --git a/backend/api/.gitignore b/backend/api/.gitignore new file mode 100644 index 00000000..a4d6d9c6 --- /dev/null +++ b/backend/api/.gitignore @@ -0,0 +1 @@ +.vs/
\ No newline at end of file diff --git a/backend/api/api.sln b/backend/api/api.sln new file mode 100644 index 00000000..0d70ced2 --- /dev/null +++ b/backend/api/api.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31912.275 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "api", "api\api.csproj", "{D28778A6-7C1C-4DC7-966B-238F89418B68}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D28778A6-7C1C-4DC7-966B-238F89418B68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D28778A6-7C1C-4DC7-966B-238F89418B68}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D28778A6-7C1C-4DC7-966B-238F89418B68}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D28778A6-7C1C-4DC7-966B-238F89418B68}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B78DE00E-6559-4B22-9396-F35CA1E90F70} + EndGlobalSection +EndGlobal diff --git a/backend/api/api/.gitignore b/backend/api/api/.gitignore new file mode 100644 index 00000000..8afdcb63 --- /dev/null +++ b/backend/api/api/.gitignore @@ -0,0 +1,454 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json diff --git a/backend/api/api/Controllers/.gitkeep b/backend/api/api/Controllers/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/backend/api/api/Controllers/.gitkeep diff --git a/backend/api/api/Program.cs b/backend/api/api/Program.cs new file mode 100644 index 00000000..478b7052 --- /dev/null +++ b/backend/api/api/Program.cs @@ -0,0 +1,15 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/backend/api/api/Properties/launchSettings.json b/backend/api/api/Properties/launchSettings.json new file mode 100644 index 00000000..5c9dd2a8 --- /dev/null +++ b/backend/api/api/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:61918", + "sslPort": 0 + } + }, + "profiles": { + "api": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "launchUrl": "", + "applicationUrl": "http://localhost:5283", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": false, + "launchUrl": "", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/backend/api/api/api.csproj b/backend/api/api/api.csproj new file mode 100644 index 00000000..f278c90a --- /dev/null +++ b/backend/api/api/api.csproj @@ -0,0 +1,13 @@ +<Project Sdk="Microsoft.NET.Sdk.Web"> + + <PropertyGroup> + <TargetFramework>net6.0</TargetFramework> + <Nullable>enable</Nullable> + <ImplicitUsings>enable</ImplicitUsings> + </PropertyGroup> + + <ItemGroup> + <Folder Include="Controllers\" /> + </ItemGroup> + +</Project> diff --git a/backend/api/api/appsettings.Development.json b/backend/api/api/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/backend/api/api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/backend/api/api/appsettings.json b/backend/api/api/appsettings.json new file mode 100644 index 00000000..10f68b8c --- /dev/null +++ b/backend/api/api/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/docs/Istraživanje_za_čuvanje_podataka_ANN.pdf b/docs/Istraživanje_za_čuvanje_podataka_ANN.pdf Binary files differnew file mode 100644 index 00000000..8cfc636f --- /dev/null +++ b/docs/Istraživanje_za_čuvanje_podataka_ANN.pdf diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 5c12257a..2bc6994f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -17,9 +17,11 @@ "@angular/platform-browser": "~13.2.0", "@angular/platform-browser-dynamic": "~13.2.0", "@angular/router": "~13.2.0", + "@auth0/angular-jwt": "^5.0.2", "@ng-bootstrap/ng-bootstrap": "^12.0.0", "@popperjs/core": "^2.10.2", "bootstrap": "^5.1.3", + "ngx-cookie-service": "^13.1.2", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" @@ -689,6 +691,17 @@ "integrity": "sha512-H71nDOOL8Y7kWRLqf6Sums+01Q5msqBW2KhDUTemh1tvY04eSkSXrK0uj/4mmY0Xr16/3zyZmsrxN7CKuRbNRg==", "dev": true }, + "node_modules/@auth0/angular-jwt": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@auth0/angular-jwt/-/angular-jwt-5.0.2.tgz", + "integrity": "sha512-rSamC9mu+gUxoR86AXcIo+KD7xRIro+/iu1F2Ld85YAZEVKlpB5vYG+g0yGaEOqjtQWP/i0H6fi6XMGPVHSYYQ==", + "dependencies": { + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@angular/common": ">=9.0.0" + } + }, "node_modules/@babel/code-frame": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz", @@ -7844,6 +7857,18 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node_modules/ngx-cookie-service": { + "version": "13.1.2", + "resolved": "https://registry.npmjs.org/ngx-cookie-service/-/ngx-cookie-service-13.1.2.tgz", + "integrity": "sha512-CInzm1xjI51QA1gCJEnqfDFLnN7w/SzqM5+kGdpI+UiCeHKgYEXpKG1s7lFz4jbLDrL/jHKtrf92t7RGsm66Cg==", + "dependencies": { + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@angular/common": "^13.0.0", + "@angular/core": "^13.0.0" + } + }, "node_modules/nice-napi": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nice-napi/-/nice-napi-1.0.2.tgz", @@ -11811,6 +11836,14 @@ "integrity": "sha512-H71nDOOL8Y7kWRLqf6Sums+01Q5msqBW2KhDUTemh1tvY04eSkSXrK0uj/4mmY0Xr16/3zyZmsrxN7CKuRbNRg==", "dev": true }, + "@auth0/angular-jwt": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@auth0/angular-jwt/-/angular-jwt-5.0.2.tgz", + "integrity": "sha512-rSamC9mu+gUxoR86AXcIo+KD7xRIro+/iu1F2Ld85YAZEVKlpB5vYG+g0yGaEOqjtQWP/i0H6fi6XMGPVHSYYQ==", + "requires": { + "tslib": "^2.0.0" + } + }, "@babel/code-frame": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz", @@ -17088,6 +17121,14 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "ngx-cookie-service": { + "version": "13.1.2", + "resolved": "https://registry.npmjs.org/ngx-cookie-service/-/ngx-cookie-service-13.1.2.tgz", + "integrity": "sha512-CInzm1xjI51QA1gCJEnqfDFLnN7w/SzqM5+kGdpI+UiCeHKgYEXpKG1s7lFz4jbLDrL/jHKtrf92t7RGsm66Cg==", + "requires": { + "tslib": "^2.0.0" + } + }, "nice-napi": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nice-napi/-/nice-napi-1.0.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index 0c32b85f..5d3ab5e3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -19,6 +19,8 @@ "@angular/platform-browser": "~13.2.0", "@angular/platform-browser-dynamic": "~13.2.0", "@angular/router": "~13.2.0", + "@auth0/angular-jwt": "^5.0.2", + "ngx-cookie-service": "^13.1.2", "@ng-bootstrap/ng-bootstrap": "^12.0.0", "@popperjs/core": "^2.10.2", "bootstrap": "^5.1.3", diff --git a/frontend/src/app/_pages/login-page/login-page.component.html b/frontend/src/app/_pages/login-page/login-page.component.html index b8620e2f..906eaba6 100644 --- a/frontend/src/app/_pages/login-page/login-page.component.html +++ b/frontend/src/app/_pages/login-page/login-page.component.html @@ -1,39 +1,43 @@ -<div *ngIf="pageLoaded" style="min-height: 100vh; position: relative;"> - +<div style="min-height: 100vh; position: relative;"> + <!-- TODO : <app-navbar [activeNav]="'login'"></app-navbar>--> - + <div class="container p-5 rounded-3 shadow-sm border" style="max-width: 50em; margin-top: 50px;"> <h3 class="text-center pb-5">Prijavite se</h3> <form> <!-- Email input --> <div class="form-outline mb-4"> <label class="form-label" for="email">Email adresa</label> - <input [(ngModel)]="email" name="email" type="email" id="email" class="form-control form-control-lg" placeholder="Unesite email adresu..." /> + <input [(ngModel)]="email" name="email" type="email" id="email" class="form-control form-control-lg" + placeholder="Unesite email adresu..." /> </div> - + <!-- Password input --> <div class="form-outline mb-3"> <label class="form-label" for="password">Lozinka</label> - <input [(ngModel)]="password" name="password" type="password" id="password" class="form-control form-control-lg" placeholder="Unesite lozinku..." /> + <input [(ngModel)]="password" name="password" type="password" id="password" + class="form-control form-control-lg" placeholder="Unesite lozinku..." /> </div> - + <div class="text-center text-lg-start mt-4 pt-2"> <!-- Pogresna lozinka --> - <p *ngIf="wrongCreds" class="small fw-bold mt-2 pt-1 mb-0 text-danger">Lozinka ili e-mail su pogrešni</p> + <p *ngIf="wrongCreds" class="small fw-bold mt-2 pt-1 mb-0 text-danger">Lozinka ili e-mail su pogrešni + </p> <!-- Nepotvrdjena registracija <p *ngIf="notApproved" class="small fw-bold mt-2 pt-1 mb-0 text-danger">Vaša registracija još uvek nije potvrđena</p>--> <br> - - <button type="button" class="btn btn-primary btn-lg" style="padding-left: 2.5rem; padding-right: 2.5rem;" - (click)="onSubmit()">Prijava + + <button type="button" class="btn btn-primary btn-lg" + style="padding-left: 2.5rem; padding-right: 2.5rem;" (click)="onSubmit()">Prijava </button> - - <p class="small fw-bold mt-2 pt-1 mb-0">Još uvek nemate nalog? - <a routerLink="/register" class="link-danger">Registrujte se</a></p> + + <p class="small fw-bold mt-2 pt-1 mb-0">Još uvek nemate nalog? + <a routerLink="/register" class="link-danger">Registrujte se</a> + </p> </div> </form> </div> - + <!-- TODO: <app-footer></app-footer>--> </div>
\ No newline at end of file diff --git a/frontend/src/app/_pages/login-page/login-page.component.ts b/frontend/src/app/_pages/login-page/login-page.component.ts index c041003d..fec5e16e 100644 --- a/frontend/src/app/_pages/login-page/login-page.component.ts +++ b/frontend/src/app/_pages/login-page/login-page.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; +import { response } from 'express'; import { AuthService } from 'src/app/_services/auth.service'; //import { LoginService } from 'src/app/_services/login.service'; @@ -9,8 +10,6 @@ import { AuthService } from 'src/app/_services/auth.service'; styleUrls: ['./login-page.component.css'] }) export class LoginPageComponent implements OnInit { - - public pageLoaded: boolean = false; //ako korisnik ne sme da ima pristup stranici (vec je ulogovan itd), ona ne sme ni da se ucita email: string = ''; password: string = ''; @@ -20,26 +19,21 @@ export class LoginPageComponent implements OnInit { pattEmail: RegExp = /^[a-zA-Z0-9]+([\.\-\+][a-zA-Z0-9]+)*\@([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}$/; constructor( - private activatedRoute: ActivatedRoute, private authService: AuthService - //private loginService: LoginService ) { } ngOnInit(): void { - /*this.authService.checkAccess(this.activatedRoute, this, - (self: any) => self.pageLoaded = true; - );*/ } onSubmit() { - //this.wrongCreds = false; - //this.notApproved = false; RAZMOTRITI - - if (this.pattEmail.test(this.email)) { - //this.loginService.login(this.email, this.password); + if (!this.pattEmail.test(this.email)) { + console.warn('Bad email!'); + return; } else { - //this.wrongCreds = true; + this.authService.login(this.email, this.password).subscribe((response) => { + console.log(response) + }) } } diff --git a/frontend/src/app/_pages/only-authorized/only-authorized.component.css b/frontend/src/app/_pages/only-authorized/only-authorized.component.css new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/frontend/src/app/_pages/only-authorized/only-authorized.component.css diff --git a/frontend/src/app/_pages/only-authorized/only-authorized.component.html b/frontend/src/app/_pages/only-authorized/only-authorized.component.html new file mode 100644 index 00000000..27bbcf09 --- /dev/null +++ b/frontend/src/app/_pages/only-authorized/only-authorized.component.html @@ -0,0 +1 @@ +<p>only-authorized works!</p> diff --git a/frontend/src/app/_pages/only-authorized/only-authorized.component.spec.ts b/frontend/src/app/_pages/only-authorized/only-authorized.component.spec.ts new file mode 100644 index 00000000..82a01f63 --- /dev/null +++ b/frontend/src/app/_pages/only-authorized/only-authorized.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { OnlyAuthorizedComponent } from './only-authorized.component'; + +describe('OnlyAuthorizedComponent', () => { + let component: OnlyAuthorizedComponent; + let fixture: ComponentFixture<OnlyAuthorizedComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ OnlyAuthorizedComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(OnlyAuthorizedComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/_pages/only-authorized/only-authorized.component.ts b/frontend/src/app/_pages/only-authorized/only-authorized.component.ts new file mode 100644 index 00000000..be88365f --- /dev/null +++ b/frontend/src/app/_pages/only-authorized/only-authorized.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-only-authorized', + templateUrl: './only-authorized.component.html', + styleUrls: ['./only-authorized.component.css'] +}) +export class OnlyAuthorizedComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/frontend/src/app/_pages/register-page/register-page.component.ts b/frontend/src/app/_pages/register-page/register-page.component.ts index d51358de..e8d4c036 100644 --- a/frontend/src/app/_pages/register-page/register-page.component.ts +++ b/frontend/src/app/_pages/register-page/register-page.component.ts @@ -1,8 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; import { Router } from '@angular/router'; import { AuthService } from 'src/app/_services/auth.service'; -import { RegisterService } from 'src/app/_services/register.service'; @Component({ selector: 'app-register-page', @@ -10,9 +8,6 @@ import { RegisterService } from 'src/app/_services/register.service'; styleUrls: ['./register-page.component.css'] }) export class RegisterPageComponent implements OnInit { - - public pageLoaded: boolean = false; - firstName: string = ''; lastName: string = ''; nickName: string = ''; @@ -33,19 +28,11 @@ export class RegisterPageComponent implements OnInit { pattPassword: RegExp = /.{6,30}$/; constructor( - private activatedRoute: ActivatedRoute, private router: Router, private authService: AuthService, - private registerService: RegisterService ) { } ngOnInit(): void { - /*this.authService.checkAccess(this.activatedRoute, this, - (self: any) => - { - self.pageLoaded = true; - } - );*/ } isCorrectName(element: string): boolean { @@ -124,25 +111,25 @@ export class RegisterPageComponent implements OnInit { if (!(this.wrongFirstNameBool || this.wrongLastNameBool || this.wrongNickNameBool || this.wrongEmailBool || this.wrongPass1Bool || this.wrongPass2Bool)) { //sve ok, registruj ga - let user = { - firstName: this.firstName, - lastName: this.lastName, - nickName: this.nickName, - email: this.email, - password: this.pass1 - } - - /*this.registerService.createUser(user, this) - .subscribe( - (response) => { - if () - this.router.navigate(['/login']); //registracija uspesna, idi na login - else if () - alert('Nalog sa unetim email-om već postoji!'); - } - ); - */ + let user = { + firstName: this.firstName, + lastName: this.lastName, + nickName: this.nickName, + email: this.email, + password: this.pass1 } + + this.authService.register(user) + .subscribe( + (response) => { + console.log(response); + /*if () + this.router.navigate(['/login']); //registracija uspesna, idi na login + else if () + alert('Nalog sa unetim email-om već postoji!');*/ + } + ); + } } diff --git a/frontend/src/app/_services/register.service.spec.ts b/frontend/src/app/_services/auth-guard.service.spec.ts index 2ba39608..35afd377 100644 --- a/frontend/src/app/_services/register.service.spec.ts +++ b/frontend/src/app/_services/auth-guard.service.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@angular/core/testing'; -import { RegisterService } from './register.service'; +import { AuthGuardService } from './auth-guard.service'; -describe('RegisterService', () => { - let service: RegisterService; +describe('AuthGuardService', () => { + let service: AuthGuardService; beforeEach(() => { TestBed.configureTestingModule({}); - service = TestBed.inject(RegisterService); + service = TestBed.inject(AuthGuardService); }); it('should be created', () => { diff --git a/frontend/src/app/_services/auth-guard.service.ts b/frontend/src/app/_services/auth-guard.service.ts new file mode 100644 index 00000000..b6d3678d --- /dev/null +++ b/frontend/src/app/_services/auth-guard.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { Observable } from 'rxjs'; +import { AuthService } from './auth.service'; + + +@Injectable({ + providedIn: 'root' +}) +export class AuthGuardService implements CanActivate { + + constructor(private auth: AuthService, private router: Router) { } + + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> { + if (this.auth.isAuthenticated()) { + return true; + } + this.router.navigate(['login']); + return false; + } +} diff --git a/frontend/src/app/_services/auth.service.ts b/frontend/src/app/_services/auth.service.ts index af27fdec..d1012d37 100644 --- a/frontend/src/app/_services/auth.service.ts +++ b/frontend/src/app/_services/auth.service.ts @@ -1,9 +1,31 @@ import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { JwtHelperService } from '@auth0/angular-jwt'; +import { CookieService } from 'ngx-cookie-service'; +import { API_SETTINGS } from 'src/config'; + +const jwtHelper = new JwtHelperService(); @Injectable({ providedIn: 'root' }) export class AuthService { - constructor() { } + constructor(private http: HttpClient, private cookie: CookieService) { } + + login(username: string, password: string) { + return this.http.post(`${API_SETTINGS.apiURL}/login`, { username, password }); + } + + register(user: any) { + return this.http.post(`${API_SETTINGS.apiURL}/register`, user); + } + + isAuthenticated(): boolean { + if (this.cookie.check('token')) { + var token = this.cookie.get('token'); + return !jwtHelper.isTokenExpired(token); + } + return false; + } } diff --git a/frontend/src/app/_services/register.service.ts b/frontend/src/app/_services/register.service.ts deleted file mode 100644 index 93074c06..00000000 --- a/frontend/src/app/_services/register.service.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Injectable } from '@angular/core'; - -@Injectable({ - providedIn: 'root' -}) -export class RegisterService { - - constructor() { } -} diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index 3fe2bc13..1868e56c 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -2,11 +2,14 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { LoginPageComponent } from './_pages/login-page/login-page.component'; +import { OnlyAuthorizedComponent } from './_pages/only-authorized/only-authorized.component'; import { RegisterPageComponent } from './_pages/register-page/register-page.component'; +import { AuthGuardService } from './_services/auth-guard.service'; const routes: Routes = [ { path: 'login', component: LoginPageComponent }, - { path: 'register', component: RegisterPageComponent } + { path: 'register', component: RegisterPageComponent }, + { path: 'only-authorized', component: OnlyAuthorizedComponent, canActivate: [AuthGuardService] } ]; @NgModule({ diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 39d75e89..9ccd7ddb 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -8,12 +8,14 @@ import { AppComponent } from './app.component'; import { LoginPageComponent } from './_pages/login-page/login-page.component'; import { RegisterPageComponent } from './_pages/register-page/register-page.component'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; +import { OnlyAuthorizedComponent } from './_pages/only-authorized/only-authorized.component'; @NgModule({ declarations: [ AppComponent, LoginPageComponent, - RegisterPageComponent + RegisterPageComponent, + OnlyAuthorizedComponent ], imports: [ BrowserModule, diff --git a/frontend/src/app/auth.service.spec.ts b/frontend/src/app/auth.service.spec.ts deleted file mode 100644 index f1251cac..00000000 --- a/frontend/src/app/auth.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { AuthService } from './auth.service'; - -describe('AuthService', () => { - let service: AuthService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(AuthService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); diff --git a/frontend/src/app/auth.service.ts b/frontend/src/app/auth.service.ts deleted file mode 100644 index af27fdec..00000000 --- a/frontend/src/app/auth.service.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Injectable } from '@angular/core'; - -@Injectable({ - providedIn: 'root' -}) -export class AuthService { - - constructor() { } -} diff --git a/frontend/src/config.ts b/frontend/src/config.ts new file mode 100644 index 00000000..b14670ea --- /dev/null +++ b/frontend/src/config.ts @@ -0,0 +1,3 @@ +export const API_SETTINGS = { + apiURL: 'http://localhost:5000/api' +}
\ No newline at end of file |