├── .gitignore ├── API ├── API.csproj ├── Controllers │ ├── IdentityController.cs │ ├── UserController.cs │ └── ValueController.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── ViewModels │ ├── ConfirmEmailViewModel.cs │ ├── LoginModel.cs │ └── RegisterModel.cs └── appsettings.Development.json ├── ASP.NET Core & Angular Collection.postman_collection.json ├── Core ├── Core.csproj ├── Data │ ├── ApplicationDBContext.cs │ ├── Entities │ │ ├── User.cs │ │ └── Value.cs │ └── Migrations │ │ ├── 20200914152240_Init.Designer.cs │ │ ├── 20200914152240_Init.cs │ │ └── ApplicationDBContextModelSnapshot.cs └── Services │ ├── Email │ ├── EmailSender.cs │ └── IEmailSender.cs │ └── Token │ ├── IJWTTokenGenerator.cs │ └── JWTTokenGenerator.cs ├── README.md ├── SPA ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.scss │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── modules │ │ │ └── auth │ │ │ │ ├── auth-buttons │ │ │ │ ├── auth-buttons.component.html │ │ │ │ ├── auth-buttons.component.scss │ │ │ │ ├── auth-buttons.component.spec.ts │ │ │ │ └── auth-buttons.component.ts │ │ │ │ ├── auth-links │ │ │ │ ├── auth-links.component.html │ │ │ │ ├── auth-links.component.scss │ │ │ │ ├── auth-links.component.spec.ts │ │ │ │ └── auth-links.component.ts │ │ │ │ ├── auth-routing.module.ts │ │ │ │ ├── auth.module.ts │ │ │ │ ├── confirm-email │ │ │ │ ├── confirm-email.component.html │ │ │ │ ├── confirm-email.component.scss │ │ │ │ ├── confirm-email.component.spec.ts │ │ │ │ └── confirm-email.component.ts │ │ │ │ ├── login │ │ │ │ ├── login.component.html │ │ │ │ ├── login.component.scss │ │ │ │ ├── login.component.spec.ts │ │ │ │ └── login.component.ts │ │ │ │ ├── register │ │ │ │ ├── register.component.html │ │ │ │ ├── register.component.scss │ │ │ │ ├── register.component.spec.ts │ │ │ │ └── register.component.ts │ │ │ │ └── resources │ │ │ │ ├── IResponse.ts │ │ │ │ ├── IUser.ts │ │ │ │ ├── auth.service.spec.ts │ │ │ │ └── auth.service.ts │ │ ├── pages │ │ │ ├── admin │ │ │ │ ├── admin.component.html │ │ │ │ ├── admin.component.scss │ │ │ │ ├── admin.component.spec.ts │ │ │ │ └── admin.component.ts │ │ │ ├── home │ │ │ │ ├── home.component.html │ │ │ │ ├── home.component.scss │ │ │ │ ├── home.component.spec.ts │ │ │ │ └── home.component.ts │ │ │ ├── manager │ │ │ │ ├── manager.component.html │ │ │ │ ├── manager.component.scss │ │ │ │ ├── manager.component.spec.ts │ │ │ │ └── manager.component.ts │ │ │ └── public │ │ │ │ ├── public.component.html │ │ │ │ ├── public.component.scss │ │ │ │ ├── public.component.spec.ts │ │ │ │ └── public.component.ts │ │ └── shared │ │ │ ├── components │ │ │ ├── course-list │ │ │ │ ├── course-list.component.html │ │ │ │ ├── course-list.component.scss │ │ │ │ ├── course-list.component.spec.ts │ │ │ │ └── course-list.component.ts │ │ │ ├── footer │ │ │ │ ├── footer.component.html │ │ │ │ ├── footer.component.scss │ │ │ │ ├── footer.component.spec.ts │ │ │ │ └── footer.component.ts │ │ │ └── header │ │ │ │ ├── header.component.html │ │ │ │ ├── header.component.scss │ │ │ │ ├── header.component.spec.ts │ │ │ │ └── header.component.ts │ │ │ └── services │ │ │ ├── progressbar.service.ts │ │ │ ├── secret.service.spec.ts │ │ │ └── secret.service.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.scss │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json └── diagram.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | app.db 2 | appsettings.json 3 | # Logs and databases # 4 | ###################### 5 | *.log 6 | *.sql 7 | *.sqlite 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.userosscache 15 | *.sln.docstates 16 | 17 | # User-specific files (MonoDevelop/Xamarin Studio) 18 | *.userprefs 19 | 20 | # Build results 21 | [Dd]ebug/ 22 | [Dd]ebugPublic/ 23 | [Rr]elease/ 24 | [Rr]eleases/ 25 | x64/ 26 | x86/ 27 | build/ 28 | bld/ 29 | bin/ 30 | Bin/ 31 | obj/ 32 | Obj/ 33 | 34 | # Visual Studio 2015 cache/options directory 35 | .vs/ 36 | .vscode/ 37 | # MSTest test Results 38 | [Tt]est[Rr]esult*/ 39 | [Bb]uild[Ll]og.* 40 | 41 | # NUNIT 42 | *.VisualState.xml 43 | TestResult.xml 44 | 45 | # Build Results of an ATL Project 46 | [Dd]ebugPS/ 47 | [Rr]eleasePS/ 48 | dlldata.c 49 | 50 | *_i.c 51 | *_p.c 52 | *_i.h 53 | *.ilk 54 | *.meta 55 | *.obj 56 | *.pch 57 | *.pdb 58 | *.pgc 59 | *.pgd 60 | *.rsp 61 | *.sbr 62 | *.tlb 63 | *.tli 64 | *.tlh 65 | *.tmp 66 | *.tmp_proj 67 | *.log 68 | *.vspscc 69 | *.vssscc 70 | .builds 71 | *.pidb 72 | *.svclog 73 | *.scc 74 | 75 | # Chutzpah Test files 76 | _Chutzpah* 77 | 78 | # Visual C++ cache files 79 | ipch/ 80 | *.aps 81 | *.ncb 82 | *.opendb 83 | *.opensdf 84 | *.sdf 85 | *.cachefile 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | *.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | 158 | # Microsoft Azure Build Output 159 | csx/ 160 | *.build.csdef 161 | 162 | # Microsoft Azure Emulator 163 | ecf/ 164 | rcf/ 165 | 166 | # Microsoft Azure ApplicationInsights config file 167 | ApplicationInsights.config 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | ~$* 182 | *~ 183 | *.dbmdl 184 | *.dbproj.schemaview 185 | *.pfx 186 | *.publishsettings 187 | orleans.codegen.cs 188 | 189 | /node_modules 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # Paket dependency manager 235 | .paket/paket.exe 236 | 237 | # FAKE - F# Make 238 | .fake/ -------------------------------------------------------------------------------- /API/API.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | netcoreapp3.1 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /API/Controllers/IdentityController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Threading.Tasks; 6 | using System.Web; 7 | using API.ViewModels; 8 | using Core.Services.Email; 9 | using Core.Services.Token; 10 | using Microsoft.AspNetCore.Identity; 11 | using Microsoft.AspNetCore.Mvc; 12 | using Microsoft.Extensions.Configuration; 13 | using Microsoft.Extensions.Logging; 14 | 15 | namespace API.Controllers 16 | { 17 | [ApiController] 18 | [Route("[controller]")] 19 | public class IdentityController : ControllerBase 20 | { 21 | 22 | private readonly UserManager _userManager; 23 | private readonly SignInManager _signInManager; 24 | private readonly IJWTTokenGenerator _jwtToken; 25 | private readonly RoleManager _roleManager; 26 | private readonly IConfiguration _config; 27 | private readonly IEmailSender _emailSender; 28 | 29 | public IdentityController( 30 | UserManager userManager, 31 | SignInManager signInManager, 32 | IJWTTokenGenerator jwtToken, 33 | RoleManager roleManager, 34 | IConfiguration config, 35 | IEmailSender emailSender) 36 | { 37 | _jwtToken = jwtToken; 38 | _roleManager = roleManager; 39 | _config = config; 40 | _emailSender = emailSender; 41 | _signInManager = signInManager; 42 | _userManager = userManager; 43 | 44 | } 45 | 46 | [HttpPost("login")] 47 | public async Task Login(LoginModel model) 48 | { 49 | 50 | var userFromDb = await _userManager.FindByNameAsync(model.Username); 51 | 52 | if (userFromDb == null) 53 | { 54 | return BadRequest(); 55 | } 56 | 57 | var result = await _signInManager.CheckPasswordSignInAsync(userFromDb, model.Password, false); 58 | 59 | 60 | if (!result.Succeeded) 61 | { 62 | return BadRequest(); 63 | } 64 | 65 | var roles = await _userManager.GetRolesAsync(userFromDb); 66 | 67 | IList claims = await _userManager.GetClaimsAsync(userFromDb); 68 | return Ok(new 69 | { 70 | result = result, 71 | username = userFromDb.UserName, 72 | email = userFromDb.Email, 73 | token = _jwtToken.GenerateToken(userFromDb, roles, claims) 74 | }); 75 | } 76 | 77 | [HttpPost("register")] 78 | public async Task Register(RegisterModel model) 79 | { 80 | 81 | if (!(await _roleManager.RoleExistsAsync(model.Role))) 82 | { 83 | await _roleManager.CreateAsync(new IdentityRole(model.Role)); 84 | } 85 | 86 | var userToCreate = new IdentityUser 87 | { 88 | Email = model.Email, 89 | UserName = model.Username 90 | }; 91 | 92 | //Create User 93 | var result = await _userManager.CreateAsync(userToCreate, model.Password); 94 | 95 | if (result.Succeeded) 96 | { 97 | 98 | var userFromDb = await _userManager.FindByNameAsync(userToCreate.UserName); 99 | 100 | var token = await _userManager.GenerateEmailConfirmationTokenAsync(userFromDb); 101 | 102 | var uriBuilder = new UriBuilder(_config["ReturnPaths:ConfirmEmail"]); 103 | var query = HttpUtility.ParseQueryString(uriBuilder.Query); 104 | query["token"] = token; 105 | query["userid"] = userFromDb.Id; 106 | uriBuilder.Query = query.ToString(); 107 | var urlString = uriBuilder.ToString(); 108 | 109 | var senderEmail = _config["ReturnPaths:SenderEmail"]; 110 | 111 | await _emailSender.SendEmailAsync(senderEmail, userFromDb.Email, "Confirm your email address", urlString); 112 | 113 | //Add role to user 114 | await _userManager.AddToRoleAsync(userFromDb, model.Role); 115 | 116 | var claim = new Claim("JobTitle", model.JobTitle); 117 | 118 | await _userManager.AddClaimAsync(userFromDb, claim); 119 | 120 | return Ok(result); 121 | } 122 | 123 | return BadRequest(result); 124 | } 125 | 126 | [HttpPost("confirmemail")] 127 | public async Task ConfirmEmail(ConfirmEmailViewModel model) 128 | { 129 | 130 | var user = await _userManager.FindByIdAsync(model.UserId); 131 | 132 | var result = await _userManager.ConfirmEmailAsync(user, model.Token); 133 | 134 | if (result.Succeeded) 135 | { 136 | return Ok(); 137 | } 138 | return BadRequest(); 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /API/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace API.Controllers 10 | { 11 | [ApiController] 12 | [Route("[controller]")] 13 | public class UserController : ControllerBase 14 | { 15 | 16 | 17 | public UserController() 18 | { 19 | 20 | } 21 | 22 | //Only admins should be able to get all admins 23 | //For testing roles 24 | [HttpGet] 25 | [Authorize(Roles = "Administrator")] 26 | public IActionResult GetAllAdmins() 27 | { 28 | return Ok(); 29 | } 30 | //Only admins should be able to get all managers 31 | //For testing roles 32 | [HttpGet("managers")] 33 | [Authorize(Roles = "Manager")] 34 | public IActionResult GetAllManagers() 35 | { 36 | return Ok(); 37 | } 38 | //Only admins and managers should get all non admin and users 39 | //For testing roles 40 | [HttpGet("users")] 41 | public IActionResult GetAllUsers() 42 | { 43 | return Ok(); 44 | } 45 | //For testing claims and policies 46 | [HttpGet("managerdevelopers")] 47 | [Authorize(Policy = "ManagerDevelopers")] 48 | public IActionResult AdminDesigners() 49 | { 50 | return Ok(new 51 | { 52 | role = "This user ROLE is Manager", 53 | claim = "User using this Api claims to be DEVELOPER" 54 | }); 55 | } 56 | 57 | //For testing claims and policies 58 | [HttpGet("admindevelopers")] 59 | [Authorize(Policy = "AdminDevelopers")] 60 | public IActionResult AdminDevelopers() 61 | { 62 | return Ok(new 63 | { 64 | role = "This user ROLE is Admin", 65 | claim = "User using this Api claims to be DEVELOPER" 66 | }); 67 | } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /API/Controllers/ValueController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace API.Controllers 10 | { 11 | [ApiController] 12 | [Route("[controller]")] 13 | public class ValueController : ControllerBase 14 | { 15 | 16 | 17 | public ValueController() 18 | { 19 | 20 | } 21 | [Authorize] 22 | [HttpGet] 23 | public ActionResult> Get() 24 | { 25 | return new string[] { "value1", "value2" }; 26 | } 27 | 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /API/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace API 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:54606", 8 | "sslPort": 44387 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": false, 15 | "launchUrl": "value", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "API": { 21 | "commandName": "Project", 22 | "launchBrowser": false, 23 | "launchUrl": "value", 24 | "applicationUrl": "http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /API/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Core.Data; 7 | using Core.Services.Email; 8 | using Core.Services.Token; 9 | using Microsoft.AspNetCore.Authentication.JwtBearer; 10 | using Microsoft.AspNetCore.Builder; 11 | using Microsoft.AspNetCore.Hosting; 12 | using Microsoft.AspNetCore.HttpsPolicy; 13 | using Microsoft.AspNetCore.Identity; 14 | using Microsoft.AspNetCore.Mvc; 15 | using Microsoft.EntityFrameworkCore; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using Microsoft.Extensions.Hosting; 19 | using Microsoft.Extensions.Logging; 20 | using Microsoft.IdentityModel.Tokens; 21 | 22 | namespace API 23 | { 24 | public class Startup 25 | { 26 | public Startup(IConfiguration configuration) 27 | { 28 | Configuration = configuration; 29 | } 30 | 31 | public IConfiguration Configuration { get; } 32 | 33 | // This method gets called by the runtime. Use this method to add services to the container. 34 | public void ConfigureServices(IServiceCollection services) 35 | { 36 | services.AddControllers(); 37 | 38 | services.AddScoped(); 39 | services.AddSingleton(); 40 | 41 | 42 | services.AddDbContext(x => x.UseSqlite(Configuration.GetConnectionString("Default"))); 43 | //If you are using sqlServer 44 | //services.AddDbContext(x => x.UseSqlServer(Configuration.GetConnectionString("Default"))); 45 | 46 | services.AddIdentity(opt => 47 | { 48 | opt.Password.RequireDigit = false; 49 | opt.Password.RequireLowercase = false; 50 | opt.Password.RequireNonAlphanumeric = false; 51 | opt.Password.RequireUppercase = false; 52 | opt.Password.RequiredLength = 4; 53 | 54 | opt.User.RequireUniqueEmail = true; 55 | opt.SignIn.RequireConfirmedEmail = true; 56 | } 57 | ).AddEntityFrameworkStores().AddDefaultTokenProviders(); 58 | 59 | 60 | services.AddAuthentication(cfg => 61 | { 62 | cfg.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 63 | cfg.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 64 | }).AddJwtBearer(options => 65 | { 66 | 67 | options.RequireHttpsMetadata = false; 68 | options.TokenValidationParameters = new TokenValidationParameters 69 | { 70 | ValidateIssuerSigningKey = true, 71 | IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Token:Key"])), 72 | ValidIssuer = Configuration["Token:Issuer"], 73 | ValidateIssuer = true, 74 | ValidateAudience = false, 75 | }; 76 | }); 77 | 78 | services.AddAuthorization(options => 79 | { 80 | options.AddPolicy("ManagerDevelopers", md => 81 | { 82 | md.RequireClaim("jobtitle", "Developer"); 83 | md.RequireRole("Manager"); 84 | }); 85 | options.AddPolicy("AdminDevelopers", ad => 86 | { 87 | ad.RequireClaim("jobtitle", "Developer"); 88 | ad.RequireRole("Administrator"); 89 | }); 90 | }); 91 | 92 | } 93 | 94 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 95 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 96 | { 97 | if (env.IsDevelopment()) 98 | { 99 | app.UseDeveloperExceptionPage(); 100 | } 101 | 102 | app.UseHttpsRedirection(); 103 | 104 | app.UseRouting(); 105 | 106 | app.UseCors(builder => 107 | { 108 | builder.WithOrigins("http://localhost:4200"); 109 | builder.AllowAnyMethod(); 110 | builder.AllowAnyHeader(); 111 | }); 112 | app.UseAuthentication(); 113 | app.UseAuthorization(); 114 | 115 | app.UseEndpoints(endpoints => 116 | { 117 | endpoints.MapControllers(); 118 | }); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /API/ViewModels/ConfirmEmailViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace API.ViewModels 4 | { 5 | public class ConfirmEmailViewModel 6 | { 7 | [Required] 8 | public string Token { get; set; } 9 | [Required] 10 | public string UserId { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /API/ViewModels/LoginModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | namespace API.ViewModels 3 | { 4 | public class LoginModel 5 | { 6 | [Required] 7 | public string Username { get; set; } 8 | [Required] 9 | public string Password { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /API/ViewModels/RegisterModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace API.ViewModels 4 | { 5 | public class RegisterModel 6 | { 7 | [Required] 8 | public string Username { get; set; } 9 | [Required] 10 | public string Email { get; set; } 11 | [Required] 12 | public string Password { get; set; } 13 | [Required] 14 | public string Role { get; set; } 15 | [Required] 16 | public string JobTitle { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /API/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "ConnectionStrings": { 10 | "Default": "Data source=app.db" 11 | }, 12 | "Token": { 13 | "Issuer": "http://localhost:5000", 14 | "Key": "secretkeythiskeyshouldneverleavetheserver" 15 | }, 16 | "SMTPDEV": { 17 | "Host": "in-v3.mailjet.com", 18 | "Username": "", 19 | "Password": "", 20 | "Port": "587" 21 | }, 22 | "ReturnPaths": { 23 | "ConfirmEmail": "http://localhost:4200/confirmemail", 24 | "SenderEmail": "Your email goes here" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ASP.NET Core & Angular Collection.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "6c5cf2e9-404a-4e91-b361-83409fd14e45", 4 | "name": "ASP.NET Core & Angular Collection", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 6 | }, 7 | "item": [ 8 | { 9 | "name": "http://localhost:5000/value", 10 | "request": { 11 | "method": "GET", 12 | "header": [ 13 | { 14 | "key": "Authorization", 15 | "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJnaXZlbl9uYW1lIjoibWlrZSIsImVtYWlsIjoidGVzdEB0ZXN0LmNvbSIsIm5iZiI6MTYwMDQzMjc5NiwiZXhwIjoxNjAxMDM3NTk2LCJpYXQiOjE2MDA0MzI3OTYsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NTAwMCJ9.I0q1T46Te1nnT49tMhbg-TSEUTHZMXlj_N0R8XXGQqA", 16 | "type": "text" 17 | } 18 | ], 19 | "url": { 20 | "raw": "http://localhost:5000/value", 21 | "protocol": "http", 22 | "host": [ 23 | "localhost" 24 | ], 25 | "port": "5000", 26 | "path": [ 27 | "value" 28 | ] 29 | } 30 | }, 31 | "response": [] 32 | }, 33 | { 34 | "name": "http://localhost:5000/identity/register", 35 | "request": { 36 | "method": "POST", 37 | "header": [], 38 | "body": { 39 | "mode": "raw", 40 | "raw": "{\r\n \"email\": \"test101@test.com\",\r\n \"username\": \"mike101\",\r\n \"password\": \"1234\",\r\n \"role\": \"Manager\",\r\n \"jobtitle\": \"Developer\"\r\n}", 41 | "options": { 42 | "raw": { 43 | "language": "json" 44 | } 45 | } 46 | }, 47 | "url": { 48 | "raw": "http://localhost:5000/identity/register", 49 | "protocol": "http", 50 | "host": [ 51 | "localhost" 52 | ], 53 | "port": "5000", 54 | "path": [ 55 | "identity", 56 | "register" 57 | ] 58 | } 59 | }, 60 | "response": [] 61 | }, 62 | { 63 | "name": "http://localhost:5000/identity/login", 64 | "request": { 65 | "method": "POST", 66 | "header": [], 67 | "body": { 68 | "mode": "raw", 69 | "raw": "{\r\n \"username\": \"mike101\",\r\n \"password\": \"1234\"\r\n}", 70 | "options": { 71 | "raw": { 72 | "language": "json" 73 | } 74 | } 75 | }, 76 | "url": { 77 | "raw": "http://localhost:5000/identity/login", 78 | "protocol": "http", 79 | "host": [ 80 | "localhost" 81 | ], 82 | "port": "5000", 83 | "path": [ 84 | "identity", 85 | "login" 86 | ] 87 | } 88 | }, 89 | "response": [] 90 | }, 91 | { 92 | "name": "http://localhost:5000/user/admins", 93 | "request": { 94 | "method": "GET", 95 | "header": [ 96 | { 97 | "key": "Authorization", 98 | "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJnaXZlbl9uYW1lIjoidGVzdDMiLCJlbWFpbCI6InRlc3QzQHRlc3QuY29tIiwibmJmIjoxNTk5NzQ0NTI2LCJleHAiOjE2MDAzNDkzMjYsImlhdCI6MTU5OTc0NDUyNiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAwIn0.xVoNJbjSSgTEw5ibKAehFaD33TLSzteH35YEsmjSSTM", 99 | "type": "text" 100 | } 101 | ], 102 | "url": { 103 | "raw": "http://localhost:5000/user/admins", 104 | "protocol": "http", 105 | "host": [ 106 | "localhost" 107 | ], 108 | "port": "5000", 109 | "path": [ 110 | "user", 111 | "admins" 112 | ] 113 | }, 114 | "description": "You must have a role of administrator to use this api" 115 | }, 116 | "response": [] 117 | }, 118 | { 119 | "name": "http://localhost:5000/user/managers", 120 | "request": { 121 | "method": "GET", 122 | "header": [ 123 | { 124 | "key": "Authorization", 125 | "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJnaXZlbl9uYW1lIjoidGVzdDMiLCJlbWFpbCI6InRlc3QzQHRlc3QuY29tIiwicm9sZSI6Ik1hbmFnZXIiLCJuYmYiOjE1OTk3NDY0NjAsImV4cCI6MTYwMDM1MTI2MCwiaWF0IjoxNTk5NzQ2NDYwLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjUwMDAifQ.tPkf8E_3-VY-eZycsKU5PQVFqmWZrooy8fs49TKW36Y", 126 | "type": "text" 127 | } 128 | ], 129 | "url": { 130 | "raw": "http://localhost:5000/user/managers", 131 | "protocol": "http", 132 | "host": [ 133 | "localhost" 134 | ], 135 | "port": "5000", 136 | "path": [ 137 | "user", 138 | "managers" 139 | ] 140 | } 141 | }, 142 | "response": [] 143 | }, 144 | { 145 | "name": "http://localhost:5000/user/users", 146 | "request": { 147 | "method": "GET", 148 | "header": [ 149 | { 150 | "key": "Authorization", 151 | "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJnaXZlbl9uYW1lIjoidGVzdDMiLCJlbWFpbCI6InRlc3QzQHRlc3QuY29tIiwibmJmIjoxNTk5NzQ0NTI2LCJleHAiOjE2MDAzNDkzMjYsImlhdCI6MTU5OTc0NDUyNiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAwIn0.xVoNJbjSSgTEw5ibKAehFaD33TLSzteH35YEsmjSSTM", 152 | "type": "text" 153 | } 154 | ], 155 | "url": { 156 | "raw": "http://localhost:5000/user/users", 157 | "protocol": "http", 158 | "host": [ 159 | "localhost" 160 | ], 161 | "port": "5000", 162 | "path": [ 163 | "user", 164 | "users" 165 | ] 166 | } 167 | }, 168 | "response": [] 169 | }, 170 | { 171 | "name": "http://localhost:5000/user/managerdevelopers", 172 | "request": { 173 | "method": "GET", 174 | "header": [ 175 | { 176 | "key": "Authorization", 177 | "type": "text", 178 | "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJKb2JUaXRsZSI6IkRldmVsb3BlciIsImdpdmVuX25hbWUiOiJ0ZXN0NSIsImVtYWlsIjoidGVzdDVAdGVzdC5jb20iLCJyb2xlIjoiTWFuYWdlciIsIm5iZiI6MTU5OTgyNjUyNSwiZXhwIjoxNjAwNDMxMzI1LCJpYXQiOjE1OTk4MjY1MjUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NTAwMCJ9.xLCe37_sQWd-QLOND8-pkZnLoRqGfpCbSQWNqG4mIbo" 179 | } 180 | ], 181 | "url": { 182 | "raw": "http://localhost:5000/user/managerdevelopers", 183 | "protocol": "http", 184 | "host": [ 185 | "localhost" 186 | ], 187 | "port": "5000", 188 | "path": [ 189 | "user", 190 | "managerdevelopers" 191 | ] 192 | } 193 | }, 194 | "response": [] 195 | }, 196 | { 197 | "name": "http://localhost:5000/user/admindevelopers", 198 | "request": { 199 | "method": "GET", 200 | "header": [ 201 | { 202 | "key": "Authorization", 203 | "type": "text", 204 | "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJKb2JUaXRsZSI6IkRldmVsb3BlciIsImdpdmVuX25hbWUiOiJ0ZXN0NiIsImVtYWlsIjoidGVzdDZAdGVzdC5jb20iLCJyb2xlIjoiQWRtaW5pc3RyYXRvciIsIm5iZiI6MTU5OTgyNjAzOCwiZXhwIjoxNjAwNDMwODM4LCJpYXQiOjE1OTk4MjYwMzgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NTAwMCJ9.x1mav-T7kemjwDCDNtdMhGkXuTRGkpXiBPFVx1wRZ6Q" 205 | } 206 | ], 207 | "url": { 208 | "raw": "http://localhost:5000/user/admindevelopers", 209 | "protocol": "http", 210 | "host": [ 211 | "localhost" 212 | ], 213 | "port": "5000", 214 | "path": [ 215 | "user", 216 | "admindevelopers" 217 | ] 218 | } 219 | }, 220 | "response": [] 221 | } 222 | ], 223 | "protocolProfileBehavior": {} 224 | } -------------------------------------------------------------------------------- /Core/Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Core/Data/ApplicationDBContext.cs: -------------------------------------------------------------------------------- 1 | using Core.Data.Entities; 2 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore; 4 | 5 | namespace Core.Data 6 | { 7 | public class ApplicationDBContext : IdentityDbContext 8 | { 9 | public ApplicationDBContext(DbContextOptions options) : base(options) 10 | { 11 | } 12 | 13 | public DbSet Values { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /Core/Data/Entities/User.cs: -------------------------------------------------------------------------------- 1 | namespace Core.Data.Entities 2 | { 3 | public class User 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Core/Data/Entities/Value.cs: -------------------------------------------------------------------------------- 1 | namespace Core.Data.Entities 2 | { 3 | public class Value 4 | { 5 | public int Id { get; set; } 6 | public string Title { get; set; } 7 | public string Description { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Core/Data/Migrations/20200914152240_Init.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Core.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Migrations; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | namespace Core.Data.Migrations 10 | { 11 | [DbContext(typeof(ApplicationDBContext))] 12 | [Migration("20200914152240_Init")] 13 | partial class Init 14 | { 15 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 16 | { 17 | #pragma warning disable 612, 618 18 | modelBuilder 19 | .HasAnnotation("ProductVersion", "3.1.3"); 20 | 21 | modelBuilder.Entity("Core.Data.Entities.Value", b => 22 | { 23 | b.Property("Id") 24 | .ValueGeneratedOnAdd() 25 | .HasColumnType("INTEGER"); 26 | 27 | b.Property("Description") 28 | .HasColumnType("TEXT"); 29 | 30 | b.Property("Title") 31 | .HasColumnType("TEXT"); 32 | 33 | b.HasKey("Id"); 34 | 35 | b.ToTable("Values"); 36 | }); 37 | 38 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 39 | { 40 | b.Property("Id") 41 | .HasColumnType("TEXT"); 42 | 43 | b.Property("ConcurrencyStamp") 44 | .IsConcurrencyToken() 45 | .HasColumnType("TEXT"); 46 | 47 | b.Property("Name") 48 | .HasColumnType("TEXT") 49 | .HasMaxLength(256); 50 | 51 | b.Property("NormalizedName") 52 | .HasColumnType("TEXT") 53 | .HasMaxLength(256); 54 | 55 | b.HasKey("Id"); 56 | 57 | b.HasIndex("NormalizedName") 58 | .IsUnique() 59 | .HasName("RoleNameIndex"); 60 | 61 | b.ToTable("AspNetRoles"); 62 | }); 63 | 64 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 65 | { 66 | b.Property("Id") 67 | .ValueGeneratedOnAdd() 68 | .HasColumnType("INTEGER"); 69 | 70 | b.Property("ClaimType") 71 | .HasColumnType("TEXT"); 72 | 73 | b.Property("ClaimValue") 74 | .HasColumnType("TEXT"); 75 | 76 | b.Property("RoleId") 77 | .IsRequired() 78 | .HasColumnType("TEXT"); 79 | 80 | b.HasKey("Id"); 81 | 82 | b.HasIndex("RoleId"); 83 | 84 | b.ToTable("AspNetRoleClaims"); 85 | }); 86 | 87 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => 88 | { 89 | b.Property("Id") 90 | .HasColumnType("TEXT"); 91 | 92 | b.Property("AccessFailedCount") 93 | .HasColumnType("INTEGER"); 94 | 95 | b.Property("ConcurrencyStamp") 96 | .IsConcurrencyToken() 97 | .HasColumnType("TEXT"); 98 | 99 | b.Property("Email") 100 | .HasColumnType("TEXT") 101 | .HasMaxLength(256); 102 | 103 | b.Property("EmailConfirmed") 104 | .HasColumnType("INTEGER"); 105 | 106 | b.Property("LockoutEnabled") 107 | .HasColumnType("INTEGER"); 108 | 109 | b.Property("LockoutEnd") 110 | .HasColumnType("TEXT"); 111 | 112 | b.Property("NormalizedEmail") 113 | .HasColumnType("TEXT") 114 | .HasMaxLength(256); 115 | 116 | b.Property("NormalizedUserName") 117 | .HasColumnType("TEXT") 118 | .HasMaxLength(256); 119 | 120 | b.Property("PasswordHash") 121 | .HasColumnType("TEXT"); 122 | 123 | b.Property("PhoneNumber") 124 | .HasColumnType("TEXT"); 125 | 126 | b.Property("PhoneNumberConfirmed") 127 | .HasColumnType("INTEGER"); 128 | 129 | b.Property("SecurityStamp") 130 | .HasColumnType("TEXT"); 131 | 132 | b.Property("TwoFactorEnabled") 133 | .HasColumnType("INTEGER"); 134 | 135 | b.Property("UserName") 136 | .HasColumnType("TEXT") 137 | .HasMaxLength(256); 138 | 139 | b.HasKey("Id"); 140 | 141 | b.HasIndex("NormalizedEmail") 142 | .HasName("EmailIndex"); 143 | 144 | b.HasIndex("NormalizedUserName") 145 | .IsUnique() 146 | .HasName("UserNameIndex"); 147 | 148 | b.ToTable("AspNetUsers"); 149 | }); 150 | 151 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 152 | { 153 | b.Property("Id") 154 | .ValueGeneratedOnAdd() 155 | .HasColumnType("INTEGER"); 156 | 157 | b.Property("ClaimType") 158 | .HasColumnType("TEXT"); 159 | 160 | b.Property("ClaimValue") 161 | .HasColumnType("TEXT"); 162 | 163 | b.Property("UserId") 164 | .IsRequired() 165 | .HasColumnType("TEXT"); 166 | 167 | b.HasKey("Id"); 168 | 169 | b.HasIndex("UserId"); 170 | 171 | b.ToTable("AspNetUserClaims"); 172 | }); 173 | 174 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 175 | { 176 | b.Property("LoginProvider") 177 | .HasColumnType("TEXT"); 178 | 179 | b.Property("ProviderKey") 180 | .HasColumnType("TEXT"); 181 | 182 | b.Property("ProviderDisplayName") 183 | .HasColumnType("TEXT"); 184 | 185 | b.Property("UserId") 186 | .IsRequired() 187 | .HasColumnType("TEXT"); 188 | 189 | b.HasKey("LoginProvider", "ProviderKey"); 190 | 191 | b.HasIndex("UserId"); 192 | 193 | b.ToTable("AspNetUserLogins"); 194 | }); 195 | 196 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 197 | { 198 | b.Property("UserId") 199 | .HasColumnType("TEXT"); 200 | 201 | b.Property("RoleId") 202 | .HasColumnType("TEXT"); 203 | 204 | b.HasKey("UserId", "RoleId"); 205 | 206 | b.HasIndex("RoleId"); 207 | 208 | b.ToTable("AspNetUserRoles"); 209 | }); 210 | 211 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 212 | { 213 | b.Property("UserId") 214 | .HasColumnType("TEXT"); 215 | 216 | b.Property("LoginProvider") 217 | .HasColumnType("TEXT"); 218 | 219 | b.Property("Name") 220 | .HasColumnType("TEXT"); 221 | 222 | b.Property("Value") 223 | .HasColumnType("TEXT"); 224 | 225 | b.HasKey("UserId", "LoginProvider", "Name"); 226 | 227 | b.ToTable("AspNetUserTokens"); 228 | }); 229 | 230 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 231 | { 232 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 233 | .WithMany() 234 | .HasForeignKey("RoleId") 235 | .OnDelete(DeleteBehavior.Cascade) 236 | .IsRequired(); 237 | }); 238 | 239 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 240 | { 241 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 242 | .WithMany() 243 | .HasForeignKey("UserId") 244 | .OnDelete(DeleteBehavior.Cascade) 245 | .IsRequired(); 246 | }); 247 | 248 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 249 | { 250 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 251 | .WithMany() 252 | .HasForeignKey("UserId") 253 | .OnDelete(DeleteBehavior.Cascade) 254 | .IsRequired(); 255 | }); 256 | 257 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 258 | { 259 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 260 | .WithMany() 261 | .HasForeignKey("RoleId") 262 | .OnDelete(DeleteBehavior.Cascade) 263 | .IsRequired(); 264 | 265 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 266 | .WithMany() 267 | .HasForeignKey("UserId") 268 | .OnDelete(DeleteBehavior.Cascade) 269 | .IsRequired(); 270 | }); 271 | 272 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 273 | { 274 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 275 | .WithMany() 276 | .HasForeignKey("UserId") 277 | .OnDelete(DeleteBehavior.Cascade) 278 | .IsRequired(); 279 | }); 280 | #pragma warning restore 612, 618 281 | } 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /Core/Data/Migrations/20200914152240_Init.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace Core.Data.Migrations 5 | { 6 | public partial class Init : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "AspNetRoles", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false), 15 | Name = table.Column(maxLength: 256, nullable: true), 16 | NormalizedName = table.Column(maxLength: 256, nullable: true), 17 | ConcurrencyStamp = table.Column(nullable: true) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_AspNetRoles", x => x.Id); 22 | }); 23 | 24 | migrationBuilder.CreateTable( 25 | name: "AspNetUsers", 26 | columns: table => new 27 | { 28 | Id = table.Column(nullable: false), 29 | UserName = table.Column(maxLength: 256, nullable: true), 30 | NormalizedUserName = table.Column(maxLength: 256, nullable: true), 31 | Email = table.Column(maxLength: 256, nullable: true), 32 | NormalizedEmail = table.Column(maxLength: 256, nullable: true), 33 | EmailConfirmed = table.Column(nullable: false), 34 | PasswordHash = table.Column(nullable: true), 35 | SecurityStamp = table.Column(nullable: true), 36 | ConcurrencyStamp = table.Column(nullable: true), 37 | PhoneNumber = table.Column(nullable: true), 38 | PhoneNumberConfirmed = table.Column(nullable: false), 39 | TwoFactorEnabled = table.Column(nullable: false), 40 | LockoutEnd = table.Column(nullable: true), 41 | LockoutEnabled = table.Column(nullable: false), 42 | AccessFailedCount = table.Column(nullable: false) 43 | }, 44 | constraints: table => 45 | { 46 | table.PrimaryKey("PK_AspNetUsers", x => x.Id); 47 | }); 48 | 49 | migrationBuilder.CreateTable( 50 | name: "Values", 51 | columns: table => new 52 | { 53 | Id = table.Column(nullable: false) 54 | .Annotation("Sqlite:Autoincrement", true), 55 | Title = table.Column(nullable: true), 56 | Description = table.Column(nullable: true) 57 | }, 58 | constraints: table => 59 | { 60 | table.PrimaryKey("PK_Values", x => x.Id); 61 | }); 62 | 63 | migrationBuilder.CreateTable( 64 | name: "AspNetRoleClaims", 65 | columns: table => new 66 | { 67 | Id = table.Column(nullable: false) 68 | .Annotation("Sqlite:Autoincrement", true), 69 | RoleId = table.Column(nullable: false), 70 | ClaimType = table.Column(nullable: true), 71 | ClaimValue = table.Column(nullable: true) 72 | }, 73 | constraints: table => 74 | { 75 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); 76 | table.ForeignKey( 77 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", 78 | column: x => x.RoleId, 79 | principalTable: "AspNetRoles", 80 | principalColumn: "Id", 81 | onDelete: ReferentialAction.Cascade); 82 | }); 83 | 84 | migrationBuilder.CreateTable( 85 | name: "AspNetUserClaims", 86 | columns: table => new 87 | { 88 | Id = table.Column(nullable: false) 89 | .Annotation("Sqlite:Autoincrement", true), 90 | UserId = table.Column(nullable: false), 91 | ClaimType = table.Column(nullable: true), 92 | ClaimValue = table.Column(nullable: true) 93 | }, 94 | constraints: table => 95 | { 96 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); 97 | table.ForeignKey( 98 | name: "FK_AspNetUserClaims_AspNetUsers_UserId", 99 | column: x => x.UserId, 100 | principalTable: "AspNetUsers", 101 | principalColumn: "Id", 102 | onDelete: ReferentialAction.Cascade); 103 | }); 104 | 105 | migrationBuilder.CreateTable( 106 | name: "AspNetUserLogins", 107 | columns: table => new 108 | { 109 | LoginProvider = table.Column(nullable: false), 110 | ProviderKey = table.Column(nullable: false), 111 | ProviderDisplayName = table.Column(nullable: true), 112 | UserId = table.Column(nullable: false) 113 | }, 114 | constraints: table => 115 | { 116 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); 117 | table.ForeignKey( 118 | name: "FK_AspNetUserLogins_AspNetUsers_UserId", 119 | column: x => x.UserId, 120 | principalTable: "AspNetUsers", 121 | principalColumn: "Id", 122 | onDelete: ReferentialAction.Cascade); 123 | }); 124 | 125 | migrationBuilder.CreateTable( 126 | name: "AspNetUserRoles", 127 | columns: table => new 128 | { 129 | UserId = table.Column(nullable: false), 130 | RoleId = table.Column(nullable: false) 131 | }, 132 | constraints: table => 133 | { 134 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); 135 | table.ForeignKey( 136 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId", 137 | column: x => x.RoleId, 138 | principalTable: "AspNetRoles", 139 | principalColumn: "Id", 140 | onDelete: ReferentialAction.Cascade); 141 | table.ForeignKey( 142 | name: "FK_AspNetUserRoles_AspNetUsers_UserId", 143 | column: x => x.UserId, 144 | principalTable: "AspNetUsers", 145 | principalColumn: "Id", 146 | onDelete: ReferentialAction.Cascade); 147 | }); 148 | 149 | migrationBuilder.CreateTable( 150 | name: "AspNetUserTokens", 151 | columns: table => new 152 | { 153 | UserId = table.Column(nullable: false), 154 | LoginProvider = table.Column(nullable: false), 155 | Name = table.Column(nullable: false), 156 | Value = table.Column(nullable: true) 157 | }, 158 | constraints: table => 159 | { 160 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); 161 | table.ForeignKey( 162 | name: "FK_AspNetUserTokens_AspNetUsers_UserId", 163 | column: x => x.UserId, 164 | principalTable: "AspNetUsers", 165 | principalColumn: "Id", 166 | onDelete: ReferentialAction.Cascade); 167 | }); 168 | 169 | migrationBuilder.CreateIndex( 170 | name: "IX_AspNetRoleClaims_RoleId", 171 | table: "AspNetRoleClaims", 172 | column: "RoleId"); 173 | 174 | migrationBuilder.CreateIndex( 175 | name: "RoleNameIndex", 176 | table: "AspNetRoles", 177 | column: "NormalizedName", 178 | unique: true); 179 | 180 | migrationBuilder.CreateIndex( 181 | name: "IX_AspNetUserClaims_UserId", 182 | table: "AspNetUserClaims", 183 | column: "UserId"); 184 | 185 | migrationBuilder.CreateIndex( 186 | name: "IX_AspNetUserLogins_UserId", 187 | table: "AspNetUserLogins", 188 | column: "UserId"); 189 | 190 | migrationBuilder.CreateIndex( 191 | name: "IX_AspNetUserRoles_RoleId", 192 | table: "AspNetUserRoles", 193 | column: "RoleId"); 194 | 195 | migrationBuilder.CreateIndex( 196 | name: "EmailIndex", 197 | table: "AspNetUsers", 198 | column: "NormalizedEmail"); 199 | 200 | migrationBuilder.CreateIndex( 201 | name: "UserNameIndex", 202 | table: "AspNetUsers", 203 | column: "NormalizedUserName", 204 | unique: true); 205 | } 206 | 207 | protected override void Down(MigrationBuilder migrationBuilder) 208 | { 209 | migrationBuilder.DropTable( 210 | name: "AspNetRoleClaims"); 211 | 212 | migrationBuilder.DropTable( 213 | name: "AspNetUserClaims"); 214 | 215 | migrationBuilder.DropTable( 216 | name: "AspNetUserLogins"); 217 | 218 | migrationBuilder.DropTable( 219 | name: "AspNetUserRoles"); 220 | 221 | migrationBuilder.DropTable( 222 | name: "AspNetUserTokens"); 223 | 224 | migrationBuilder.DropTable( 225 | name: "Values"); 226 | 227 | migrationBuilder.DropTable( 228 | name: "AspNetRoles"); 229 | 230 | migrationBuilder.DropTable( 231 | name: "AspNetUsers"); 232 | } 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /Core/Data/Migrations/ApplicationDBContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Core.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | 8 | namespace Core.Data.Migrations 9 | { 10 | [DbContext(typeof(ApplicationDBContext))] 11 | partial class ApplicationDBContextModelSnapshot : ModelSnapshot 12 | { 13 | protected override void BuildModel(ModelBuilder modelBuilder) 14 | { 15 | #pragma warning disable 612, 618 16 | modelBuilder 17 | .HasAnnotation("ProductVersion", "3.1.3"); 18 | 19 | modelBuilder.Entity("Core.Data.Entities.Value", b => 20 | { 21 | b.Property("Id") 22 | .ValueGeneratedOnAdd() 23 | .HasColumnType("INTEGER"); 24 | 25 | b.Property("Description") 26 | .HasColumnType("TEXT"); 27 | 28 | b.Property("Title") 29 | .HasColumnType("TEXT"); 30 | 31 | b.HasKey("Id"); 32 | 33 | b.ToTable("Values"); 34 | }); 35 | 36 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 37 | { 38 | b.Property("Id") 39 | .HasColumnType("TEXT"); 40 | 41 | b.Property("ConcurrencyStamp") 42 | .IsConcurrencyToken() 43 | .HasColumnType("TEXT"); 44 | 45 | b.Property("Name") 46 | .HasColumnType("TEXT") 47 | .HasMaxLength(256); 48 | 49 | b.Property("NormalizedName") 50 | .HasColumnType("TEXT") 51 | .HasMaxLength(256); 52 | 53 | b.HasKey("Id"); 54 | 55 | b.HasIndex("NormalizedName") 56 | .IsUnique() 57 | .HasName("RoleNameIndex"); 58 | 59 | b.ToTable("AspNetRoles"); 60 | }); 61 | 62 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 63 | { 64 | b.Property("Id") 65 | .ValueGeneratedOnAdd() 66 | .HasColumnType("INTEGER"); 67 | 68 | b.Property("ClaimType") 69 | .HasColumnType("TEXT"); 70 | 71 | b.Property("ClaimValue") 72 | .HasColumnType("TEXT"); 73 | 74 | b.Property("RoleId") 75 | .IsRequired() 76 | .HasColumnType("TEXT"); 77 | 78 | b.HasKey("Id"); 79 | 80 | b.HasIndex("RoleId"); 81 | 82 | b.ToTable("AspNetRoleClaims"); 83 | }); 84 | 85 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => 86 | { 87 | b.Property("Id") 88 | .HasColumnType("TEXT"); 89 | 90 | b.Property("AccessFailedCount") 91 | .HasColumnType("INTEGER"); 92 | 93 | b.Property("ConcurrencyStamp") 94 | .IsConcurrencyToken() 95 | .HasColumnType("TEXT"); 96 | 97 | b.Property("Email") 98 | .HasColumnType("TEXT") 99 | .HasMaxLength(256); 100 | 101 | b.Property("EmailConfirmed") 102 | .HasColumnType("INTEGER"); 103 | 104 | b.Property("LockoutEnabled") 105 | .HasColumnType("INTEGER"); 106 | 107 | b.Property("LockoutEnd") 108 | .HasColumnType("TEXT"); 109 | 110 | b.Property("NormalizedEmail") 111 | .HasColumnType("TEXT") 112 | .HasMaxLength(256); 113 | 114 | b.Property("NormalizedUserName") 115 | .HasColumnType("TEXT") 116 | .HasMaxLength(256); 117 | 118 | b.Property("PasswordHash") 119 | .HasColumnType("TEXT"); 120 | 121 | b.Property("PhoneNumber") 122 | .HasColumnType("TEXT"); 123 | 124 | b.Property("PhoneNumberConfirmed") 125 | .HasColumnType("INTEGER"); 126 | 127 | b.Property("SecurityStamp") 128 | .HasColumnType("TEXT"); 129 | 130 | b.Property("TwoFactorEnabled") 131 | .HasColumnType("INTEGER"); 132 | 133 | b.Property("UserName") 134 | .HasColumnType("TEXT") 135 | .HasMaxLength(256); 136 | 137 | b.HasKey("Id"); 138 | 139 | b.HasIndex("NormalizedEmail") 140 | .HasName("EmailIndex"); 141 | 142 | b.HasIndex("NormalizedUserName") 143 | .IsUnique() 144 | .HasName("UserNameIndex"); 145 | 146 | b.ToTable("AspNetUsers"); 147 | }); 148 | 149 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 150 | { 151 | b.Property("Id") 152 | .ValueGeneratedOnAdd() 153 | .HasColumnType("INTEGER"); 154 | 155 | b.Property("ClaimType") 156 | .HasColumnType("TEXT"); 157 | 158 | b.Property("ClaimValue") 159 | .HasColumnType("TEXT"); 160 | 161 | b.Property("UserId") 162 | .IsRequired() 163 | .HasColumnType("TEXT"); 164 | 165 | b.HasKey("Id"); 166 | 167 | b.HasIndex("UserId"); 168 | 169 | b.ToTable("AspNetUserClaims"); 170 | }); 171 | 172 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 173 | { 174 | b.Property("LoginProvider") 175 | .HasColumnType("TEXT"); 176 | 177 | b.Property("ProviderKey") 178 | .HasColumnType("TEXT"); 179 | 180 | b.Property("ProviderDisplayName") 181 | .HasColumnType("TEXT"); 182 | 183 | b.Property("UserId") 184 | .IsRequired() 185 | .HasColumnType("TEXT"); 186 | 187 | b.HasKey("LoginProvider", "ProviderKey"); 188 | 189 | b.HasIndex("UserId"); 190 | 191 | b.ToTable("AspNetUserLogins"); 192 | }); 193 | 194 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 195 | { 196 | b.Property("UserId") 197 | .HasColumnType("TEXT"); 198 | 199 | b.Property("RoleId") 200 | .HasColumnType("TEXT"); 201 | 202 | b.HasKey("UserId", "RoleId"); 203 | 204 | b.HasIndex("RoleId"); 205 | 206 | b.ToTable("AspNetUserRoles"); 207 | }); 208 | 209 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 210 | { 211 | b.Property("UserId") 212 | .HasColumnType("TEXT"); 213 | 214 | b.Property("LoginProvider") 215 | .HasColumnType("TEXT"); 216 | 217 | b.Property("Name") 218 | .HasColumnType("TEXT"); 219 | 220 | b.Property("Value") 221 | .HasColumnType("TEXT"); 222 | 223 | b.HasKey("UserId", "LoginProvider", "Name"); 224 | 225 | b.ToTable("AspNetUserTokens"); 226 | }); 227 | 228 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 229 | { 230 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 231 | .WithMany() 232 | .HasForeignKey("RoleId") 233 | .OnDelete(DeleteBehavior.Cascade) 234 | .IsRequired(); 235 | }); 236 | 237 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 238 | { 239 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 240 | .WithMany() 241 | .HasForeignKey("UserId") 242 | .OnDelete(DeleteBehavior.Cascade) 243 | .IsRequired(); 244 | }); 245 | 246 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 247 | { 248 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 249 | .WithMany() 250 | .HasForeignKey("UserId") 251 | .OnDelete(DeleteBehavior.Cascade) 252 | .IsRequired(); 253 | }); 254 | 255 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 256 | { 257 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 258 | .WithMany() 259 | .HasForeignKey("RoleId") 260 | .OnDelete(DeleteBehavior.Cascade) 261 | .IsRequired(); 262 | 263 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 264 | .WithMany() 265 | .HasForeignKey("UserId") 266 | .OnDelete(DeleteBehavior.Cascade) 267 | .IsRequired(); 268 | }); 269 | 270 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 271 | { 272 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 273 | .WithMany() 274 | .HasForeignKey("UserId") 275 | .OnDelete(DeleteBehavior.Cascade) 276 | .IsRequired(); 277 | }); 278 | #pragma warning restore 612, 618 279 | } 280 | } 281 | } 282 | -------------------------------------------------------------------------------- /Core/Services/Email/EmailSender.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Net.Mail; 3 | using System.Threading.Tasks; 4 | using Microsoft.Extensions.Configuration; 5 | 6 | namespace Core.Services.Email 7 | { 8 | public class EmailSender : IEmailSender 9 | { 10 | 11 | private readonly IConfiguration _config; 12 | 13 | public EmailSender(IConfiguration config) 14 | { 15 | _config = config; 16 | 17 | } 18 | public async Task SendEmailAsync(string fromAddress, string toAddress, string subject, string message) 19 | { 20 | var mailMessage = new MailMessage(fromAddress, toAddress, subject, message); 21 | 22 | using (var client = new SmtpClient(_config["SMTP:Host"], int.Parse(_config["SMTP:Port"])) 23 | { 24 | Credentials = new NetworkCredential(_config["SMTP:Username"], _config["SMTP:Password"]) 25 | }) 26 | { 27 | await client.SendMailAsync(mailMessage); 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Core/Services/Email/IEmailSender.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | namespace Core.Services.Email 3 | { 4 | public interface IEmailSender 5 | { 6 | Task SendEmailAsync(string fromAddress, string toAddress, string subject, string message); 7 | } 8 | } -------------------------------------------------------------------------------- /Core/Services/Token/IJWTTokenGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Security.Claims; 3 | using Microsoft.AspNetCore.Identity; 4 | 5 | namespace Core.Services.Token 6 | { 7 | public interface IJWTTokenGenerator 8 | { 9 | string GenerateToken(IdentityUser user, IList roles, IList claims); 10 | } 11 | } -------------------------------------------------------------------------------- /Core/Services/Token/JWTTokenGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IdentityModel.Tokens.Jwt; 4 | using System.Security.Claims; 5 | using System.Text; 6 | using Microsoft.AspNetCore.Identity; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.IdentityModel.Tokens; 9 | 10 | namespace Core.Services.Token 11 | { 12 | public class JWTTokenGenerator : IJWTTokenGenerator 13 | { 14 | private readonly IConfiguration _config; 15 | 16 | public JWTTokenGenerator(IConfiguration config) 17 | { 18 | _config = config; 19 | 20 | } 21 | public string GenerateToken(IdentityUser user, IList roles, IList claims) 22 | { 23 | // var claims = new List 24 | // { 25 | // new Claim(JwtRegisteredClaimNames.GivenName , user.UserName), 26 | // new Claim(JwtRegisteredClaimNames.Email , user.Email), 27 | // }; 28 | 29 | claims.Add(new Claim(JwtRegisteredClaimNames.GivenName, user.UserName)); 30 | claims.Add(new Claim(JwtRegisteredClaimNames.Email, user.Email)); 31 | 32 | foreach (var role in roles) 33 | { 34 | claims.Add(new Claim(ClaimTypes.Role, role)); 35 | } 36 | 37 | var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Token:Key"])); 38 | 39 | var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature); 40 | 41 | var tokenDescriptor = new SecurityTokenDescriptor 42 | { 43 | Subject = new ClaimsIdentity(claims), 44 | Expires = DateTime.Now.AddDays(7), 45 | SigningCredentials = creds, 46 | Issuer = _config["Token:Issuer"], 47 | }; 48 | 49 | var tokenHandler = new JwtSecurityTokenHandler(); 50 | 51 | var token = tokenHandler.CreateToken(tokenDescriptor); 52 | 53 | return tokenHandler.WriteToken(token); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SPA 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.0. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /SPA/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /SPA/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /SPA/README.md: -------------------------------------------------------------------------------- 1 | # SPA 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.0. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /SPA/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "SPA": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/SPA", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": true, 26 | "assets": ["src/favicon.ico", "src/assets"], 27 | "styles": [ 28 | "./node_modules/@fortawesome/fontawesome-free/scss/fontawesome.scss", 29 | "./node_modules/@fortawesome/fontawesome-free/scss/brands.scss", 30 | "./node_modules/@fortawesome/fontawesome-free/scss/solid.scss", 31 | "src/styles.scss" 32 | ], 33 | "scripts": [] 34 | }, 35 | "configurations": { 36 | "production": { 37 | "fileReplacements": [ 38 | { 39 | "replace": "src/environments/environment.ts", 40 | "with": "src/environments/environment.prod.ts" 41 | } 42 | ], 43 | "optimization": true, 44 | "outputHashing": "all", 45 | "sourceMap": false, 46 | "extractCss": true, 47 | "namedChunks": false, 48 | "extractLicenses": true, 49 | "vendorChunk": false, 50 | "buildOptimizer": true, 51 | "budgets": [ 52 | { 53 | "type": "initial", 54 | "maximumWarning": "2mb", 55 | "maximumError": "5mb" 56 | }, 57 | { 58 | "type": "anyComponentStyle", 59 | "maximumWarning": "6kb", 60 | "maximumError": "10kb" 61 | } 62 | ] 63 | } 64 | } 65 | }, 66 | "serve": { 67 | "builder": "@angular-devkit/build-angular:dev-server", 68 | "options": { 69 | "browserTarget": "SPA:build" 70 | }, 71 | "configurations": { 72 | "production": { 73 | "browserTarget": "SPA:build:production" 74 | } 75 | } 76 | }, 77 | "extract-i18n": { 78 | "builder": "@angular-devkit/build-angular:extract-i18n", 79 | "options": { 80 | "browserTarget": "SPA:build" 81 | } 82 | }, 83 | "test": { 84 | "builder": "@angular-devkit/build-angular:karma", 85 | "options": { 86 | "main": "src/test.ts", 87 | "polyfills": "src/polyfills.ts", 88 | "tsConfig": "tsconfig.spec.json", 89 | "karmaConfig": "karma.conf.js", 90 | "assets": ["src/favicon.ico", "src/assets"], 91 | "styles": ["src/styles.scss"], 92 | "scripts": [] 93 | } 94 | }, 95 | "lint": { 96 | "builder": "@angular-devkit/build-angular:tslint", 97 | "options": { 98 | "tsConfig": [ 99 | "tsconfig.app.json", 100 | "tsconfig.spec.json", 101 | "e2e/tsconfig.json" 102 | ], 103 | "exclude": ["**/node_modules/**"] 104 | } 105 | }, 106 | "e2e": { 107 | "builder": "@angular-devkit/build-angular:protractor", 108 | "options": { 109 | "protractorConfig": "e2e/protractor.conf.js", 110 | "devServerTarget": "SPA:serve" 111 | }, 112 | "configurations": { 113 | "production": { 114 | "devServerTarget": "SPA:serve:production" 115 | } 116 | } 117 | } 118 | } 119 | } 120 | }, 121 | "defaultProject": "SPA", 122 | "cli": { 123 | "analytics": "380bc2b3-f80a-4521-b894-dca62bccbe06" 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /SPA/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /SPA/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /SPA/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('SPA app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /SPA/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /SPA/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SPA/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/SPA'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /SPA/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spa", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~9.1.0", 15 | "@angular/common": "~9.1.0", 16 | "@angular/compiler": "~9.1.0", 17 | "@angular/core": "~9.1.0", 18 | "@angular/forms": "~9.1.0", 19 | "@angular/platform-browser": "~9.1.0", 20 | "@angular/platform-browser-dynamic": "~9.1.0", 21 | "@angular/router": "~9.1.0", 22 | "@auth0/angular-jwt": "^5.0.1", 23 | "@fortawesome/fontawesome-free": "^5.14.0", 24 | "bootstrap": "^4.5.2", 25 | "bootswatch": "^4.5.2", 26 | "ngx-alerts": "^10.0.0", 27 | "ngx-progressbar": "^6.0.3", 28 | "rxjs": "~6.5.4", 29 | "tslib": "^1.10.0", 30 | "zone.js": "~0.10.2" 31 | }, 32 | "devDependencies": { 33 | "@angular-devkit/build-angular": "~0.901.0", 34 | "@angular/cli": "~9.1.0", 35 | "@angular/compiler-cli": "~9.1.0", 36 | "@angular/language-service": "~9.1.0", 37 | "@types/node": "^12.11.1", 38 | "@types/jasmine": "~3.5.0", 39 | "@types/jasminewd2": "~2.0.3", 40 | "codelyzer": "^5.1.2", 41 | "jasmine-core": "~3.5.0", 42 | "jasmine-spec-reporter": "~4.2.1", 43 | "karma": "~4.4.1", 44 | "karma-chrome-launcher": "~3.1.0", 45 | "karma-coverage-istanbul-reporter": "~2.1.0", 46 | "karma-jasmine": "~3.0.1", 47 | "karma-jasmine-html-reporter": "^1.4.2", 48 | "protractor": "~5.4.3", 49 | "ts-node": "~8.3.0", 50 | "tslint": "~6.1.0", 51 | "typescript": "~3.8.3" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /SPA/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { HomeComponent } from './pages/home/home.component'; 4 | import { AdminComponent } from './pages/admin/admin.component'; 5 | import { ManagerComponent } from './pages/manager/manager.component'; 6 | import { PublicComponent } from './pages/public/public.component'; 7 | 8 | const routes: Routes = [ 9 | { path: '', component: HomeComponent }, 10 | { path: 'admin', component: AdminComponent }, 11 | { path: 'manager', component: ManagerComponent }, 12 | { path: 'public', component: PublicComponent }, 13 | ]; 14 | 15 | @NgModule({ 16 | imports: [RouterModule.forRoot(routes)], 17 | exports: [RouterModule], 18 | }) 19 | export class AppRoutingModule {} 20 | -------------------------------------------------------------------------------- /SPA/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
-------------------------------------------------------------------------------- /SPA/src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/app.component.scss -------------------------------------------------------------------------------- /SPA/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'SPA'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('SPA'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('SPA app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /SPA/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.scss'] 7 | }) 8 | export class AppComponent { 9 | title = 'SPA'; 10 | } 11 | -------------------------------------------------------------------------------- /SPA/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import { HomeComponent } from './pages/home/home.component'; 7 | import { AdminComponent } from './pages/admin/admin.component'; 8 | import { ManagerComponent } from './pages/manager/manager.component'; 9 | import { PublicComponent } from './pages/public/public.component'; 10 | import { HeaderComponent } from './shared/components/header/header.component'; 11 | import { FooterComponent } from './shared/components/footer/footer.component'; 12 | import { CourseListComponent } from './shared/components/course-list/course-list.component'; 13 | import { AuthModule } from './modules/auth/auth.module'; 14 | import { NgProgressModule } from 'ngx-progressbar'; 15 | 16 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 17 | import { AlertModule } from 'ngx-alerts'; 18 | 19 | @NgModule({ 20 | declarations: [ 21 | AppComponent, 22 | HomeComponent, 23 | AdminComponent, 24 | ManagerComponent, 25 | PublicComponent, 26 | HeaderComponent, 27 | FooterComponent, 28 | CourseListComponent, 29 | ], 30 | imports: [ 31 | BrowserModule, 32 | AppRoutingModule, 33 | AuthModule, 34 | NgProgressModule, 35 | BrowserAnimationsModule, 36 | AlertModule.forRoot({ maxMessages: 5, timeout: 5000, position: 'right' }), 37 | ], 38 | providers: [], 39 | bootstrap: [AppComponent], 40 | }) 41 | export class AppModule {} 42 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-buttons/auth-buttons.component.html: -------------------------------------------------------------------------------- 1 | 2 | Login 3 | 4 | 5 | Register 6 | 7 | Logout 8 | 9 | Profile -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-buttons/auth-buttons.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/modules/auth/auth-buttons/auth-buttons.component.scss -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-buttons/auth-buttons.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AuthButtonsComponent } from './auth-buttons.component'; 4 | 5 | describe('AuthButtonsComponent', () => { 6 | let component: AuthButtonsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AuthButtonsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AuthButtonsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-buttons/auth-buttons.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AuthService } from '../resources/auth.service'; 3 | 4 | @Component({ 5 | selector: 'app-auth-buttons', 6 | templateUrl: './auth-buttons.component.html', 7 | styleUrls: ['./auth-buttons.component.scss'], 8 | }) 9 | export class AuthButtonsComponent implements OnInit { 10 | constructor(public authService: AuthService) {} 11 | 12 | ngOnInit(): void {} 13 | 14 | logout() { 15 | console.log('working'); 16 | this.authService.logout(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-links/auth-links.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-links/auth-links.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/modules/auth/auth-links/auth-links.component.scss -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-links/auth-links.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AuthLinksComponent } from './auth-links.component'; 4 | 5 | describe('AuthLinksComponent', () => { 6 | let component: AuthLinksComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AuthLinksComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AuthLinksComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-links/auth-links.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AuthService } from '../resources/auth.service'; 3 | 4 | @Component({ 5 | selector: 'app-auth-links', 6 | templateUrl: './auth-links.component.html', 7 | styleUrls: ['./auth-links.component.scss'], 8 | }) 9 | export class AuthLinksComponent implements OnInit { 10 | constructor(public authService: AuthService) {} 11 | 12 | ngOnInit(): void {} 13 | 14 | logout() { 15 | this.authService.logout(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { ConfirmEmailComponent } from './confirm-email/confirm-email.component'; 4 | import { LoginComponent } from './login/login.component'; 5 | import { RegisterComponent } from './register/register.component'; 6 | 7 | const routes: Routes = [ 8 | { path: 'login', component: LoginComponent }, 9 | { path: 'register', component: RegisterComponent }, 10 | { path: 'confirmemail', component: ConfirmEmailComponent }, 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [RouterModule.forChild(routes)], 15 | exports: [RouterModule], 16 | }) 17 | export class AuthRoutingModule {} 18 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/auth.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpClientModule } from '@angular/common/http'; 5 | 6 | import { AuthRoutingModule } from './auth-routing.module'; 7 | import { LoginComponent } from './login/login.component'; 8 | import { RegisterComponent } from './register/register.component'; 9 | import { AuthLinksComponent } from './auth-links/auth-links.component'; 10 | import { AuthButtonsComponent } from './auth-buttons/auth-buttons.component'; 11 | import { ConfirmEmailComponent } from './confirm-email/confirm-email.component'; 12 | 13 | @NgModule({ 14 | declarations: [ 15 | LoginComponent, 16 | RegisterComponent, 17 | AuthLinksComponent, 18 | AuthButtonsComponent, 19 | ConfirmEmailComponent, 20 | ], 21 | imports: [CommonModule, AuthRoutingModule, FormsModule, HttpClientModule], 22 | exports: [ 23 | LoginComponent, 24 | RegisterComponent, 25 | AuthLinksComponent, 26 | AuthButtonsComponent, 27 | ], 28 | }) 29 | export class AuthModule {} 30 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/confirm-email/confirm-email.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Email Confirmation Page

4 | 7 | 10 |
11 |
-------------------------------------------------------------------------------- /SPA/src/app/modules/auth/confirm-email/confirm-email.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/modules/auth/confirm-email/confirm-email.component.scss -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/confirm-email/confirm-email.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ConfirmEmailComponent } from './confirm-email.component'; 4 | 5 | describe('ConfirmEmailComponent', () => { 6 | let component: ConfirmEmailComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ConfirmEmailComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ConfirmEmailComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/confirm-email/confirm-email.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | import { AlertService } from 'ngx-alerts'; 4 | import { ProgressbarService } from 'src/app/shared/services/progressbar.service'; 5 | import { AuthService } from '../resources/auth.service'; 6 | 7 | @Component({ 8 | selector: 'app-confirm-email', 9 | templateUrl: './confirm-email.component.html', 10 | styleUrls: ['./confirm-email.component.scss'], 11 | }) 12 | export class ConfirmEmailComponent implements OnInit { 13 | emailConfirmed: boolean = false; 14 | urlParams: any = {}; 15 | 16 | constructor( 17 | private route: ActivatedRoute, 18 | private authService: AuthService, 19 | public progressBar: ProgressbarService, 20 | private alertService: AlertService 21 | ) {} 22 | 23 | ngOnInit() { 24 | this.urlParams.token = this.route.snapshot.queryParamMap.get('token'); 25 | this.urlParams.userid = this.route.snapshot.queryParamMap.get('userid'); 26 | this.confirmEmail(); 27 | } 28 | 29 | confirmEmail() { 30 | this.progressBar.startLoading(); 31 | this.authService.confirmEmail(this.urlParams).subscribe( 32 | () => { 33 | this.progressBar.setSuccess(); 34 | console.log('success'); 35 | this.alertService.success('Email Confirmed'); 36 | this.progressBar.completeLoading(); 37 | this.emailConfirmed = true; 38 | }, 39 | (error) => { 40 | this.progressBar.setFailure(); 41 | console.log(error); 42 | this.alertService.danger('Unable to confirm email'); 43 | this.progressBar.completeLoading(); 44 | this.emailConfirmed = false; 45 | } 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/login/login.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Login

4 |
5 |
6 | 7 | 9 |
10 |
11 | 12 | 14 |
15 | 16 | 17 | 18 |
19 | 20 | 21 |
22 | 23 |
24 |
25 |
-------------------------------------------------------------------------------- /SPA/src/app/modules/auth/login/login.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/modules/auth/login/login.component.scss -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { NgForm } from '@angular/forms'; 3 | import { AuthService } from '../resources/auth.service'; 4 | import { ProgressbarService } from 'src/app/shared/services/progressbar.service'; 5 | import { AlertService } from 'ngx-alerts'; 6 | 7 | @Component({ 8 | selector: 'app-login', 9 | templateUrl: './login.component.html', 10 | styleUrls: ['./login.component.scss'], 11 | }) 12 | export class LoginComponent implements OnInit { 13 | constructor( 14 | private authService: AuthService, 15 | private progressService: ProgressbarService, 16 | private alertService: AlertService 17 | ) {} 18 | 19 | ngOnInit(): void {} 20 | 21 | onSubmit(f: NgForm) { 22 | this.alertService.info('Check login information'); 23 | this.progressService.startLoading(); 24 | 25 | const loginObserver = { 26 | next: (x) => { 27 | this.progressService.setSuccess(); 28 | this.alertService.success('Welcome back ' + x.username); 29 | this.progressService.completeLoading(); 30 | }, 31 | error: (err) => { 32 | this.progressService.setFailure(); 33 | console.log(err); 34 | this.alertService.danger('Unable to Login'); 35 | this.progressService.completeLoading(); 36 | }, 37 | }; 38 | 39 | this.authService.login(f.value).subscribe(loginObserver); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/register/register.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Register New Employer

4 |
5 |
6 | 7 | 9 |
10 |
11 | 12 | 14 |
15 |
16 | 17 | 19 |
20 |
21 | 22 | 29 |
30 |
31 | 32 | 39 |
40 | 41 |
42 |
43 |
-------------------------------------------------------------------------------- /SPA/src/app/modules/auth/register/register.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/modules/auth/register/register.component.scss -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/register/register.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { RegisterComponent } from './register.component'; 4 | 5 | describe('RegisterComponent', () => { 6 | let component: RegisterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ RegisterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(RegisterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/register/register.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { NgForm } from '@angular/forms'; 3 | import { ProgressbarService } from 'src/app/shared/services/progressbar.service'; 4 | import { AlertService } from 'ngx-alerts'; 5 | import { AuthService } from '../resources/auth.service'; 6 | 7 | @Component({ 8 | selector: 'app-register', 9 | templateUrl: './register.component.html', 10 | styleUrls: ['./register.component.scss'], 11 | }) 12 | export class RegisterComponent implements OnInit { 13 | roleOptions: string[] = ['Administrator', 'Manager']; 14 | developerType: string[] = ['Developer', 'Designer']; 15 | 16 | model: any = { 17 | username: null, 18 | email: null, 19 | password: null, 20 | role: 'Administrator', 21 | jobtitle: 'Developer', 22 | //claim: 'Developer', 23 | }; 24 | constructor( 25 | private progressService: ProgressbarService, 26 | private alertService: AlertService, 27 | private authService: AuthService 28 | ) {} 29 | 30 | ngOnInit(): void {} 31 | 32 | onSubmit() { 33 | this.alertService.info('Creating new user'); 34 | this.progressService.startLoading(); 35 | 36 | const registerObserver = { 37 | next: (x) => { 38 | this.progressService.setSuccess(); 39 | this.alertService.success('Account Created'); 40 | this.progressService.completeLoading(); 41 | }, 42 | error: (err) => { 43 | this.progressService.setFailure(); 44 | this.alertService.danger(err.error.errors[0].description); 45 | this.progressService.completeLoading(); 46 | }, 47 | }; 48 | 49 | this.authService.register(this.model).subscribe(registerObserver); 50 | } 51 | 52 | roleChange(value) { 53 | this.model.role = value; 54 | } 55 | 56 | claimChange(value) { 57 | this.model.claim = value; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/resources/IResponse.ts: -------------------------------------------------------------------------------- 1 | export interface IResponse { 2 | role: string; 3 | claim: string; 4 | } 5 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/resources/IUser.ts: -------------------------------------------------------------------------------- 1 | export interface IUser { 2 | username: string; 3 | email: string; 4 | role: string; 5 | jobtitle: string; 6 | } 7 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/resources/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { AuthService } from './auth.service'; 4 | 5 | describe('AuthService', () => { 6 | let service: AuthService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(AuthService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /SPA/src/app/modules/auth/resources/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { environment } from 'src/environments/environment'; 4 | import { Observable, of } from 'rxjs'; 5 | import { IUser } from './IUser'; 6 | import { map } from 'rxjs/operators'; 7 | import { JwtHelperService } from '@auth0/angular-jwt'; 8 | 9 | @Injectable({ 10 | providedIn: 'root', 11 | }) 12 | export class AuthService { 13 | baseUrl: string = environment.baseUrl; 14 | 15 | helper = new JwtHelperService(); 16 | 17 | currentUser: IUser = { 18 | username: null, 19 | email: null, 20 | role: null, 21 | jobtitle: null, 22 | }; 23 | constructor(private http: HttpClient) {} 24 | 25 | login(model: any): Observable { 26 | return this.http.post(this.baseUrl + 'identity/login', model).pipe( 27 | map((response: any) => { 28 | const decodedToken = this.helper.decodeToken(response.token); 29 | 30 | this.currentUser.username = decodedToken.given_name; 31 | this.currentUser.email = decodedToken.email; 32 | this.currentUser.jobtitle = decodedToken.JobTitle; 33 | this.currentUser.role = decodedToken.role; 34 | 35 | localStorage.setItem('token', response.token); 36 | 37 | return this.currentUser; 38 | }) 39 | ); 40 | } 41 | 42 | loggedIn(): boolean { 43 | const token = localStorage.getItem('token'); 44 | return !this.helper.isTokenExpired(token); 45 | } 46 | 47 | logout() { 48 | this.currentUser = { 49 | username: null, 50 | email: null, 51 | role: null, 52 | jobtitle: null, 53 | }; 54 | localStorage.removeItem('token'); 55 | } 56 | 57 | register(model: any) { 58 | return this.http.post(this.baseUrl + 'identity/register', model); 59 | } 60 | 61 | confirmEmail(model: any) { 62 | return this.http.post(this.baseUrl + 'identity/confirmemail', model); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /SPA/src/app/pages/admin/admin.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Admin Page

3 |

Only administrators can view data on this page 4 |

5 | 6 |
7 |

Some secret data that only admins can see below

8 | 9 | Home 10 | 11 |

Top secret stuff for Admin Developers

12 |
13 |

Role: {{secrets.role}}

14 |

Claim: {{secrets.claim}}

15 |
16 |
-------------------------------------------------------------------------------- /SPA/src/app/pages/admin/admin.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/pages/admin/admin.component.scss -------------------------------------------------------------------------------- /SPA/src/app/pages/admin/admin.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AdminComponent } from './admin.component'; 4 | 5 | describe('AdminComponent', () => { 6 | let component: AdminComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AdminComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AdminComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/pages/admin/admin.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Observable } from 'rxjs'; 3 | import { IResponse } from 'src/app/modules/auth/resources/IResponse'; 4 | import { SecretService } from 'src/app/shared/services/secret.service'; 5 | 6 | @Component({ 7 | selector: 'app-admin', 8 | templateUrl: './admin.component.html', 9 | styleUrls: ['./admin.component.scss'], 10 | }) 11 | export class AdminComponent implements OnInit { 12 | secrets$: Observable; 13 | constructor(private secretService: SecretService) {} 14 | 15 | ngOnInit(): void { 16 | this.getAdminDeveloperSecrets(); 17 | } 18 | 19 | getAdminDeveloperSecrets() { 20 | this.secrets$ = this.secretService.adminDeveloperSecrets(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SPA/src/app/pages/home/home.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Angular, .Net Core and Identity

3 |

Authentication & Authorization Tutorial (Roles/Claims/Identity/JWT) 4 |

5 |

Find this course on YouTube 6 |

7 | 8 |

Github 9 |

10 |
11 | 12 | 13 |
14 | -------------------------------------------------------------------------------- /SPA/src/app/pages/home/home.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/pages/home/home.component.scss -------------------------------------------------------------------------------- /SPA/src/app/pages/home/home.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeComponent } from './home.component'; 4 | 5 | describe('HomeComponent', () => { 6 | let component: HomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HomeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/pages/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { SecretService } from 'src/app/shared/services/secret.service'; 3 | 4 | @Component({ 5 | selector: 'app-home', 6 | templateUrl: './home.component.html', 7 | styleUrls: ['./home.component.scss'], 8 | }) 9 | export class HomeComponent implements OnInit { 10 | constructor(private secretService: SecretService) {} 11 | 12 | ngOnInit(): void { 13 | this.secretService.getValues().subscribe((secrets) => console.log(secrets)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /SPA/src/app/pages/manager/manager.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Manager Page

3 |

Only managers can view data on this page 4 |

5 | 6 |
7 |

Some secret data that only managers can see below

8 | 9 | Home 10 | 11 |

Top secret stuff for Manager Developers

12 |
13 |

Role: {{secrets.role}}

14 |

Claim: {{secrets.claim}}

15 |
16 | 17 |
-------------------------------------------------------------------------------- /SPA/src/app/pages/manager/manager.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/pages/manager/manager.component.scss -------------------------------------------------------------------------------- /SPA/src/app/pages/manager/manager.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ManagerComponent } from './manager.component'; 4 | 5 | describe('ManagerComponent', () => { 6 | let component: ManagerComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ManagerComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ManagerComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/pages/manager/manager.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Observable } from 'rxjs'; 3 | import { IResponse } from 'src/app/modules/auth/resources/IResponse'; 4 | import { SecretService } from 'src/app/shared/services/secret.service'; 5 | 6 | @Component({ 7 | selector: 'app-manager', 8 | templateUrl: './manager.component.html', 9 | styleUrls: ['./manager.component.scss'], 10 | }) 11 | export class ManagerComponent implements OnInit { 12 | secrets$: Observable; 13 | constructor(private secretService: SecretService) {} 14 | 15 | ngOnInit(): void { 16 | this.getManagerDeveloperSecrets(); 17 | } 18 | 19 | getManagerDeveloperSecrets() { 20 | this.secrets$ = this.secretService.managerDeveloperSecrets(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SPA/src/app/pages/public/public.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Public Page

3 |

Everyone can view this page 4 |

5 | 6 |
7 |

Welcome to all users

8 | 9 | Home 10 |
-------------------------------------------------------------------------------- /SPA/src/app/pages/public/public.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/pages/public/public.component.scss -------------------------------------------------------------------------------- /SPA/src/app/pages/public/public.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PublicComponent } from './public.component'; 4 | 5 | describe('PublicComponent', () => { 6 | let component: PublicComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PublicComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PublicComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/pages/public/public.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-public', 5 | templateUrl: './public.component.html', 6 | styleUrls: ['./public.component.scss'] 7 | }) 8 | export class PublicComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /SPA/src/app/shared/components/course-list/course-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
Course List
3 | 4 |
5 | 7 | Placeholder 8 | 32x32 9 | 10 |
11 |
12 | Setup Project 13 | GitHub.com 14 |
15 | Get project on GitHub.com 16 |
17 |
18 | 19 |
20 | 22 | Placeholder 23 | 32x32 24 | 25 |
26 |
27 | Video 1 28 | Checklist 29 | Snippet 30 | Link 31 |
32 | Configure Identity in StartUp Class 33 |
34 |
35 | 36 |
37 | 39 | Placeholder 40 | 32x32 41 | 42 |
43 |
44 | Video 2 45 | Checklist 46 | Snippet 47 | Link 48 |
49 | Set up Identity in database context and run migration 50 |
51 |
52 | 53 |
54 | 56 | Placeholder 57 | 32x32 58 | 59 |
60 |
61 | Video 3 62 | Checklist 63 | Snippet 64 | Link 65 |
66 | Register new user using Identity - API 67 |
68 |
69 | 70 |
71 | 73 | Placeholder 74 | 32x32 75 | 76 |
77 |
78 | Video 4 79 | Checklist 80 | Snippet 81 | Link 82 |
83 | Create SPA Register Method in Auth Service - SPA 84 |
85 |
86 | 87 |
88 | 90 | Placeholder 91 | 32x32 92 | 93 |
94 |
95 | Video 5 96 | Checklist 97 | Snippet 98 | Link 99 |
100 | Login User - API 101 |
102 |
103 | 104 |
105 | 107 | Placeholder 108 | 32x32 109 | 110 |
111 |
112 | Video 6 113 | Checklist 114 | Snippet 115 | Link 116 |
117 | Login User - SPA 118 |
119 |
120 | 121 |
122 | 124 | Placeholder 125 | 32x32 126 | 127 |
128 |
129 | Video 7 130 | Checklist 131 | Snippet 132 | Link 133 |
134 | Generate a Json Web Token 135 |
136 |
137 | 138 |
139 | 141 | Placeholder 142 | 32x32 143 | 144 |
145 |
146 | Video 8 147 | Checklist 148 | Snippet 149 | Link 150 |
151 | Protect API With JWT Token - API 152 |
153 |
154 | 155 |
156 | 158 | Placeholder 159 | 32x32 160 | 161 |
162 |
163 | Video 9 164 | Checklist 165 | Snippet 166 | Link 167 |
168 | Call protected API from client - SPA 169 |
170 |
171 | 172 |
173 | 175 | Placeholder 176 | 32x32 177 | 178 |
179 |
180 | Video 10 181 | Checklist 182 | Snippet 183 | Link 184 |
185 | Assign Roles to Users 186 |
187 |
188 | 189 |
190 | 192 | Placeholder 193 | 32x32 194 | 195 |
196 |
197 | Video 11 198 | Checklist 199 | Snippet 200 | Link 201 |
202 | Assign Claims to Users 203 |
204 |
205 | 206 |
207 | 209 | Placeholder 210 | 32x32 211 | 212 |
213 |
214 | Video 12 215 | Checklist 216 | Snippet 217 | Link 218 |
219 | Create and use policies to protect API 220 |
221 |
222 | 223 |
224 | 226 | Placeholder 227 | 32x32 228 | 229 |
230 |
231 | Video 13 232 | Checklist 233 | Snippet 234 | Link 235 |
236 | Decode JWT token and use in application 237 |
238 |
239 | 240 |
241 | 243 | Placeholder 244 | 32x32 245 | 246 |
247 |
248 | Video 14 249 | Checklist 250 | Snippet 251 | Link 252 |
253 | Call protected API from SPA 254 |
255 |
256 | 257 |
258 | 260 | Placeholder 261 | 32x32 262 | 263 |
264 |
265 | Video 15 266 | Checklist 267 | Snippet 268 | Link 269 |
270 | Confirming Emails 271 |
272 |
273 | 274 |
275 | 277 | Placeholder 278 | 32x32 279 | 280 |
281 |
282 | Video 16 283 | Checklist 284 | Snippet 285 | Link 286 |
287 | Confirming Emails - SPA 288 |
289 |
290 | 291 | 292 |
-------------------------------------------------------------------------------- /SPA/src/app/shared/components/course-list/course-list.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/shared/components/course-list/course-list.component.scss -------------------------------------------------------------------------------- /SPA/src/app/shared/components/course-list/course-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CourseListComponent } from './course-list.component'; 4 | 5 | describe('CourseListComponent', () => { 6 | let component: CourseListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CourseListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CourseListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/shared/components/course-list/course-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-course-list', 5 | templateUrl: './course-list.component.html', 6 | styleUrls: ['./course-list.component.scss'] 7 | }) 8 | export class CourseListComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /SPA/src/app/shared/components/footer/footer.component.html: -------------------------------------------------------------------------------- 1 |

footer works!

2 | -------------------------------------------------------------------------------- /SPA/src/app/shared/components/footer/footer.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/shared/components/footer/footer.component.scss -------------------------------------------------------------------------------- /SPA/src/app/shared/components/footer/footer.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { FooterComponent } from './footer.component'; 4 | 5 | describe('FooterComponent', () => { 6 | let component: FooterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ FooterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(FooterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/shared/components/footer/footer.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-footer', 5 | templateUrl: './footer.component.html', 6 | styleUrls: ['./footer.component.scss'] 7 | }) 8 | export class FooterComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /SPA/src/app/shared/components/header/header.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /SPA/src/app/shared/components/header/header.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/app/shared/components/header/header.component.scss -------------------------------------------------------------------------------- /SPA/src/app/shared/components/header/header.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HeaderComponent } from './header.component'; 4 | 5 | describe('HeaderComponent', () => { 6 | let component: HeaderComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HeaderComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HeaderComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /SPA/src/app/shared/components/header/header.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { NgProgress } from 'ngx-progressbar'; 3 | import { AuthService } from 'src/app/modules/auth/resources/auth.service'; 4 | import { ProgressbarService } from '../../services/progressbar.service'; 5 | 6 | @Component({ 7 | selector: 'app-header', 8 | templateUrl: './header.component.html', 9 | styleUrls: ['./header.component.scss'], 10 | }) 11 | export class HeaderComponent implements OnInit { 12 | constructor( 13 | private progress: NgProgress, 14 | public progressBar: ProgressbarService, 15 | private authService: AuthService 16 | ) {} 17 | 18 | ngOnInit(): void { 19 | this.progressBar.progressRef = this.progress.ref('progressBar'); 20 | } 21 | 22 | isAdmin(): boolean { 23 | return this.authService.currentUser.role == 'Administrator' ? true : false; 24 | } 25 | 26 | isManager(): boolean { 27 | return this.authService.currentUser.role == 'Manager' ? true : false; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /SPA/src/app/shared/services/progressbar.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { NgProgressRef } from 'ngx-progressbar'; 3 | 4 | @Injectable({ 5 | providedIn: 'root', 6 | }) 7 | export class ProgressbarService { 8 | progressRef: NgProgressRef; 9 | defaultColor: string = '#007bff'; 10 | successColor: string = '#13b955'; 11 | failureColor: string = '#fc3939'; 12 | currentColor: string = this.defaultColor; 13 | constructor() {} 14 | 15 | startLoading() { 16 | this.currentColor = this.defaultColor; 17 | this.progressRef.start(); 18 | } 19 | 20 | completeLoading() { 21 | this.progressRef.complete(); 22 | } 23 | 24 | setSuccess() { 25 | this.currentColor = this.successColor; 26 | } 27 | 28 | setFailure() { 29 | this.currentColor = this.failureColor; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /SPA/src/app/shared/services/secret.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { SecretService } from './secret.service'; 4 | 5 | describe('SecretService', () => { 6 | let service: SecretService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(SecretService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /SPA/src/app/shared/services/secret.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable } from 'rxjs'; 4 | import { IResponse } from 'src/app/modules/auth/resources/IResponse'; 5 | import { environment } from 'src/environments/environment'; 6 | 7 | @Injectable({ 8 | providedIn: 'root', 9 | }) 10 | export class SecretService { 11 | baseUrl: string = environment.baseUrl; 12 | constructor(private http: HttpClient) {} 13 | 14 | managerDeveloperSecrets(): Observable { 15 | return this.http.get( 16 | this.baseUrl + 'user/managerdevelopers', 17 | this.getHttpOptions() 18 | ); 19 | } 20 | 21 | adminDeveloperSecrets(): Observable { 22 | return this.http.get( 23 | this.baseUrl + 'user/admindevelopers', 24 | this.getHttpOptions() 25 | ); 26 | } 27 | 28 | getValues(): Observable { 29 | return this.http.get( 30 | this.baseUrl + 'value', 31 | this.getHttpOptions() 32 | ); 33 | } 34 | 35 | getHttpOptions() { 36 | const httpOptions = { 37 | headers: new HttpHeaders({ 38 | Authorization: 'Bearer ' + localStorage.getItem('token'), 39 | }), 40 | }; 41 | 42 | return httpOptions; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SPA/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/assets/.gitkeep -------------------------------------------------------------------------------- /SPA/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /SPA/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | baseUrl: 'http://localhost:5000/', 8 | }; 9 | 10 | /* 11 | * For easier debugging in development mode, you can import the following file 12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 13 | * 14 | * This import should be commented out in production mode because it will have a negative impact 15 | * on performance if an error is thrown. 16 | */ 17 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 18 | -------------------------------------------------------------------------------- /SPA/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/SPA/src/favicon.ico -------------------------------------------------------------------------------- /SPA/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SPA 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /SPA/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /SPA/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /SPA/src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import "~bootswatch/dist/pulse/variables"; 3 | @import "~bootstrap/scss/bootstrap"; 4 | @import "~bootswatch/dist/pulse/bootswatch"; 5 | 6 | .success { 7 | background-color: $success !important; 8 | } 9 | .info { 10 | background-color: $primary !important; 11 | } 12 | .danger { 13 | background-color: $danger !important; 14 | } 15 | .warning { 16 | background-color: $warning !important; 17 | } 18 | -------------------------------------------------------------------------------- /SPA/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /SPA/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /SPA/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": [ 15 | "es2018", 16 | "dom" 17 | ] 18 | }, 19 | "angularCompilerOptions": { 20 | "fullTemplateTypeCheck": true, 21 | "strictInjectionParameters": true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SPA/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /SPA/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-return-shorthand": true, 12 | "curly": true, 13 | "deprecation": { 14 | "severity": "warning" 15 | }, 16 | "component-class-suffix": true, 17 | "contextual-lifecycle": true, 18 | "directive-class-suffix": true, 19 | "directive-selector": [ 20 | true, 21 | "attribute", 22 | "app", 23 | "camelCase" 24 | ], 25 | "component-selector": [ 26 | true, 27 | "element", 28 | "app", 29 | "kebab-case" 30 | ], 31 | "eofline": true, 32 | "import-blacklist": [ 33 | true, 34 | "rxjs/Rx" 35 | ], 36 | "import-spacing": true, 37 | "indent": { 38 | "options": [ 39 | "spaces" 40 | ] 41 | }, 42 | "max-classes-per-file": false, 43 | "max-line-length": [ 44 | true, 45 | 140 46 | ], 47 | "member-ordering": [ 48 | true, 49 | { 50 | "order": [ 51 | "static-field", 52 | "instance-field", 53 | "static-method", 54 | "instance-method" 55 | ] 56 | } 57 | ], 58 | "no-console": [ 59 | true, 60 | "debug", 61 | "info", 62 | "time", 63 | "timeEnd", 64 | "trace" 65 | ], 66 | "no-empty": false, 67 | "no-inferrable-types": [ 68 | true, 69 | "ignore-params" 70 | ], 71 | "no-non-null-assertion": true, 72 | "no-redundant-jsdoc": true, 73 | "no-switch-case-fall-through": true, 74 | "no-var-requires": false, 75 | "object-literal-key-quotes": [ 76 | true, 77 | "as-needed" 78 | ], 79 | "quotemark": [ 80 | true, 81 | "single" 82 | ], 83 | "semicolon": { 84 | "options": [ 85 | "always" 86 | ] 87 | }, 88 | "space-before-function-paren": { 89 | "options": { 90 | "anonymous": "never", 91 | "asyncArrow": "always", 92 | "constructor": "never", 93 | "method": "never", 94 | "named": "never" 95 | } 96 | }, 97 | "typedef-whitespace": { 98 | "options": [ 99 | { 100 | "call-signature": "nospace", 101 | "index-signature": "nospace", 102 | "parameter": "nospace", 103 | "property-declaration": "nospace", 104 | "variable-declaration": "nospace" 105 | }, 106 | { 107 | "call-signature": "onespace", 108 | "index-signature": "onespace", 109 | "parameter": "onespace", 110 | "property-declaration": "onespace", 111 | "variable-declaration": "onespace" 112 | } 113 | ] 114 | }, 115 | "variable-name": { 116 | "options": [ 117 | "ban-keywords", 118 | "check-format", 119 | "allow-pascal-case" 120 | ] 121 | }, 122 | "whitespace": { 123 | "options": [ 124 | "check-branch", 125 | "check-decl", 126 | "check-operator", 127 | "check-separator", 128 | "check-type", 129 | "check-typecast" 130 | ] 131 | }, 132 | "no-conflicting-lifecycle": true, 133 | "no-host-metadata-property": true, 134 | "no-input-rename": true, 135 | "no-inputs-metadata-property": true, 136 | "no-output-native": true, 137 | "no-output-on-prefix": true, 138 | "no-output-rename": true, 139 | "no-outputs-metadata-property": true, 140 | "template-banana-in-box": true, 141 | "template-no-negated-async": true, 142 | "use-lifecycle-interface": true, 143 | "use-pipe-transform-interface": true 144 | }, 145 | "rulesDirectory": [ 146 | "codelyzer" 147 | ] 148 | } -------------------------------------------------------------------------------- /diagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oopcoders/Angular-Core-Authentication/86ce1407fc27e2ee914995fb41693192a11d25bb/diagram.jpg --------------------------------------------------------------------------------