diff --git a/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/.suo b/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/.suo new file mode 100644 index 0000000..57c4fcb Binary files /dev/null and b/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/.suo differ diff --git a/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide b/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide new file mode 100644 index 0000000..af3b216 Binary files /dev/null and b/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide differ diff --git a/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide-shm b/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide-shm new file mode 100644 index 0000000..47d83cf Binary files /dev/null and b/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide-shm differ diff --git a/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide-wal b/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide-wal new file mode 100644 index 0000000..cb1271d Binary files /dev/null and b/Chetna_Mongmaw/UsersApplication/.vs/UsersApplication/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Chetna_Mongmaw/UsersApplication/.vs/config/applicationhost.config b/Chetna_Mongmaw/UsersApplication/.vs/config/applicationhost.config new file mode 100644 index 0000000..849c71b --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/.vs/config/applicationhost.config @@ -0,0 +1,984 @@ + + + + + + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication.sln b/Chetna_Mongmaw/UsersApplication/UsersApplication.sln new file mode 100644 index 0000000..76c66e4 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.902 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UsersApplication", "UsersApplication\UsersApplication.csproj", "{FDFFDA99-730C-4BD5-810A-898B460C41D1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FDFFDA99-730C-4BD5-810A-898B460C41D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDFFDA99-730C-4BD5-810A-898B460C41D1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDFFDA99-730C-4BD5-810A-898B460C41D1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDFFDA99-730C-4BD5-810A-898B460C41D1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AF1D31B3-2427-4FBE-9F0F-2603C10ACFDB} + EndGlobalSection +EndGlobal diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/LoginController.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/LoginController.cs new file mode 100644 index 0000000..d9bfa95 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/LoginController.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http.Cors; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; +using UsersApplication.Models; + +namespace UsersApplication.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class LoginController : ControllerBase + { + private IConfiguration _config; + public Models.WebAppContext _webAppContext; + + //[EnableCors("AllowSpecificOrigin")] + public LoginController(IConfiguration config, Models.WebAppContext context) + { + _config = config; + _webAppContext = context; + } + [AllowAnonymous] + [HttpPost] + public IActionResult Login([FromBody] Users login) + { + IActionResult response = Unauthorized(); + var user = AuthenticateUser(login); + + if (user != null) + { + var tokenString = GenerateJSONWebToken(user); + response = Ok(new { token = tokenString }); + } + + return response; + } + + private string GenerateJSONWebToken(Users userInfo) + { + var claims = new[] { + new Claim(JwtRegisteredClaimNames.Email, userInfo.Email), + new Claim("Role", userInfo.Role), + new Claim("Username", userInfo.Username), + new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) + }; + + var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"])); + var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); + + var token = new JwtSecurityToken(_config["Jwt:Issuer"], + _config["Jwt:Issuer"], + claims, + expires: DateTime.Now.AddMinutes(120), + signingCredentials: credentials); + + return new JwtSecurityTokenHandler().WriteToken(token); + } + + private Users AuthenticateUser(Users login) + { + Users user = null; + try + { + user = _webAppContext.Users.Where(x => (x.Username == login.Username && x.Password == login.Password)).FirstOrDefault(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return user; + } + } + } + diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/OperationsController.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/OperationsController.cs new file mode 100644 index 0000000..b044a01 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/OperationsController.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using UsersApplication.Models; +using UsersApplication.CustomModels; +using UsersApplication.Repositories; + +namespace UsersApplication.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class OperationsController : ControllerBase + { + Repositories.IRegister _reg; + public OperationsController(Repositories.IRegister reg) + { + _reg = reg; + } + + [HttpPost] + public IActionResult Post([FromBody] UserInfo enteredDetails) + { + //Register register = new Register(enteredDetails); + //return Ok(userInfo); + var output = _reg.signupHandler(enteredDetails); + + return Ok(output); + } + [HttpDelete("{id}")] + public IActionResult Delete([FromBody] deleteInfo toDelete) + { + var output = _reg.deleteHandler(toDelete); + return Ok(output); + } + + [HttpPut("{id}")] + public IActionResult Put([FromBody] UserInfo updatedDetails) + + { + var output = _reg.updateHandler(updatedDetails); + return Ok(output); + } + + [HttpGet] + public IActionResult Get() + { + var output = _reg.listHandler(); + return Ok(output); + + } + } +} \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/ValuesController.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/ValuesController.cs new file mode 100644 index 0000000..5275e8a --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Controllers/ValuesController.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace UsersApplication.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + // GET api/values + [HttpGet] + public ActionResult> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/CustomModels/UserInfo.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/CustomModels/UserInfo.cs new file mode 100644 index 0000000..dba9ad5 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/CustomModels/UserInfo.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using UsersApplication.Models; + +namespace UsersApplication.CustomModels +{ + public partial class UserInfo + { + + public int RId { get; set; } + public string Name { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public int? ProjectId { get; set; } + public string Role { get; set; } + } +} diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/CustomModels/deleteInfo.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/CustomModels/deleteInfo.cs new file mode 100644 index 0000000..7ee5055 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/CustomModels/deleteInfo.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace UsersApplication.CustomModels +{ + public class deleteInfo + { + public int RId { get; set; } + } +} diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Models/Users.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/Models/Users.cs new file mode 100644 index 0000000..5365eb0 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Models/Users.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace UsersApplication.Models +{ + public partial class Users + { + public int RId { get; set; } + public string Name { get; set; } + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } + public int? ProjectId { get; set; } + public string Role { get; set; } + } +} diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Models/WebAppContext.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/Models/WebAppContext.cs new file mode 100644 index 0000000..9d7b14a --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Models/WebAppContext.cs @@ -0,0 +1,60 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +namespace UsersApplication.Models +{ + public partial class WebAppContext : DbContext + { + public WebAppContext() + { + } + + public WebAppContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Users { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.RId); + + entity.Property(e => e.RId).HasColumnName("R_id"); + + entity.Property(e => e.Email) + .IsRequired() + .HasMaxLength(500) + .IsUnicode(false); + + entity.Property(e => e.Name) + .IsRequired() + .HasMaxLength(500) + .IsUnicode(false); + + entity.Property(e => e.Password) + .IsRequired() + .HasMaxLength(500) + .IsUnicode(false); + + entity.Property(e => e.ProjectId).HasColumnName("ProjectID"); + + entity.Property(e => e.Role) + .HasMaxLength(500) + .IsUnicode(false); + + entity.Property(e => e.Username) + .IsRequired() + .HasMaxLength(500) + .IsUnicode(false); + }); + } + } +} diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Program.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/Program.cs new file mode 100644 index 0000000..3412314 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Program.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace UsersApplication +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Properties/launchSettings.json b/Chetna_Mongmaw/UsersApplication/UsersApplication/Properties/launchSettings.json new file mode 100644 index 0000000..434d140 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:49801", + "sslPort": 44348 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "UsersApplication": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Repositories/Register.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/Repositories/Register.cs new file mode 100644 index 0000000..1776ab3 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Repositories/Register.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using UsersApplication.Models; +using UsersApplication.CustomModels; + + +namespace UsersApplication.Repositories +{ + public interface IRegister + { + string signupHandler(UserInfo enteredDetails); + string deleteHandler(deleteInfo toDelete); + } + public class Register : IRegister + { + + private WebAppContext _webAppcontext; + public Register(WebAppContext webAppContext) + { + _webAppcontext = webAppContext; + } + + //public Register(UserInfo enteredDetails) + //{ + // this.enteredDetails = enteredDetails; + + //} + + public string signupHandler(UserInfo enteredDetails) + { + Users user = new Users() + { + Username = enteredDetails.Username, + Name = enteredDetails.Name, + Email = enteredDetails.Email, + Password = enteredDetails.Password, + ProjectId = enteredDetails.ProjectId, + Role = enteredDetails.Role + + }; + + _webAppcontext.Users.Add(user); + _webAppcontext.SaveChanges(); + + return ("registered"); + + } + public string deleteHandler(deleteInfo toDelete) + { + //Users user = new Users(); + Users output = _webAppcontext.Users.Find(toDelete.RId); + if (output == null) + { + return ("nothing to delete"); + } + _webAppcontext.Users.Remove(output); + _webAppcontext.SaveChanges(); + + return ("deleted"); + + } + public string updateHandler(UserInfo updatedDetails) + { + Users user = _webAppcontext.Users.Find(updatedDetails.RId); + user.Name = updatedDetails.Name; + user.Username = updatedDetails.Username; + user.Email = updatedDetails.Email; + user.Password = updatedDetails.Password; + user.ProjectId = updatedDetails.ProjectId; + user.Role = updatedDetails.Role; + _webAppcontext.SaveChanges(); + return ("Student updated"); + } + + public List listHandler() + { + List output = _webAppcontext.Users.ToList(); + return (output); + } + + + + } +} + diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/Startup.cs b/Chetna_Mongmaw/UsersApplication/UsersApplication/Startup.cs new file mode 100644 index 0000000..5c65a6b --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/Startup.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.IdentityModel.Tokens; + +namespace UsersApplication +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => + { + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + ValidIssuer = Configuration["Jwt:Issuer"], + ValidAudience = Configuration["Jwt:Issuer"], + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"])) + }; + }); + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + services.AddDbContext(sql => sql.UseSqlServer("ConnectionString")); + services.AddScoped(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseHsts(); + } + + app.UseCors(builder => builder + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials()); + app.UseAuthentication(); + app.UseHttpsRedirection(); + app.UseMvc(); + + } + } +} diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/UsersApplication.csproj b/Chetna_Mongmaw/UsersApplication/UsersApplication/UsersApplication.csproj new file mode 100644 index 0000000..fb6b43e --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/UsersApplication.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/UsersApplication.csproj.user b/Chetna_Mongmaw/UsersApplication/UsersApplication/UsersApplication.csproj.user new file mode 100644 index 0000000..2dbec45 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/UsersApplication.csproj.user @@ -0,0 +1,13 @@ + + + + ApiControllerEmptyScaffolder + root/Controller + 600 + True + False + True + + False + + \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/appsettings.Development.json b/Chetna_Mongmaw/UsersApplication/UsersApplication/appsettings.Development.json new file mode 100644 index 0000000..4f83848 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "ConnectionString": "Server=CYG317\\\\SQLEXPRESS;Database=WebApp;Trusted_Connection=True;" +} diff --git a/Chetna_Mongmaw/UsersApplication/UsersApplication/appsettings.json b/Chetna_Mongmaw/UsersApplication/UsersApplication/appsettings.json new file mode 100644 index 0000000..82bb01c --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/UsersApplication/appsettings.json @@ -0,0 +1,7 @@ +{ + "Jwt": { + "Key": "ThisismySecretKey", + "Issuer": "Test.com" + }, + "ConnectionString": "Server=CYG317\\\\SQLEXPRESS;Database=WebApp;Trusted_Connection=True;" +} \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/images/login.jpeg b/Chetna_Mongmaw/UsersApplication/ui/assets/images/login.jpeg new file mode 100644 index 0000000..2437d53 Binary files /dev/null and b/Chetna_Mongmaw/UsersApplication/ui/assets/images/login.jpeg differ diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/display.js b/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/display.js new file mode 100644 index 0000000..e3b03d1 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/display.js @@ -0,0 +1,57 @@ +// function display(){ +// // Get all users +// var url = "https://localhost:44348/api/operations"; + +// var xhr = new XMLHttpRequest() +// xhr.open('GET', url, true) +// xhr.onload = function () { +// var users = JSON.parse(xhr.responseText); +// if (xhr.readyState == 4 && xhr.status == "200") { +// console.table(users); +// } else { +// console.error(users); +// } +// } +// xhr.send(null); +// } +// function display(){ + + + function display(){ + // Creating a XHR object + var xhr = new XMLHttpRequest(); + let url = "https://localhost:44348/api/operations"; + + + // open a connection + xhr.open("GET", url, true); + + // Set the request header i.e. which type of content you are sending + xhr.setRequestHeader("Content-Type", "application/json"); + + //let request = new XMLHttpRequest(); + xhr.onreadystatechange = function () { + if (this.readyState === 4) { + if (this.status === 200) { + console.log(this.responseText); + + var obj = JSON.parse(this.responseText); + var content; + content+= "" + for (x in obj) { + content += ""+""+""+""+ + ""+"" + +""+""; + } + content += "
"+obj[x].rId+"" + obj[x].name+"" + obj[x].username+"" + obj[x].email+"" + obj[x].projectId+"" + obj[x].role+"
" + document.getElementById("content").innerHTML = content; + } + } else if (this.response == null && this.status === 0) { + console.log("The computer appears to be offline."); + } else { + console.log("error"); + } + } + xhr.send(null); + +}; diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/login.js b/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/login.js new file mode 100644 index 0000000..c0d84d3 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/login.js @@ -0,0 +1,66 @@ + +function sendJSON(){ + + let username = document.getElementById("username").value; + let password = document.getElementById("password").value; + let role = document.getElementById("role").value; + console.log(username); + console.log(password); + console.log(role); + // Creating a XHR object + var xhr = new XMLHttpRequest(); + let url = "https://localhost:44348/api/login"; + + // open a connection + xhr.open("POST", url, true); + + // Set the request header i.e. which type of content you are sending + xhr.setRequestHeader("Content-Type", "application/json"); + + // Create a state change callback + xhr.onreadystatechange = function () { + if(xhr.readyState===4){ + if (xhr.status === 200) { + console.log(this.response); + SaveToken(this.response); + DecodeToken(this.response); + window.open("./list.html"); + + } + else{ + alert("Wrong credentials"); + } + } + event.preventDefault(); + + + // Converting JSON data to string + var data = JSON.stringify({ "username": username, "password": password,"role": role }); + + // Sending data with the request + xhr.send(data); +} + //saving token in local storage + function SaveToken(token){ + if(typeof Storage !=="undefined"){ + localStorage.setItem("JWTtoken",token); + } + else{ + console.log("Sorry, your browser does not support web storage"); + } + DecodeToken(token); + } + + //for decoding the token + + function DecodeToken (token) { + var base64Url = token.split('.')[1]; + var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); + var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }).join('')); + console.log(jsonPayload); + return JSON.parse(jsonPayload); + }; + +} \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/register.js b/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/register.js new file mode 100644 index 0000000..3e8b9bc --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/register.js @@ -0,0 +1,40 @@ +function sendJSON(){ + let name = document.getElementById("name").value; + let username = document.getElementById("username").value; + let email = document.getElementById("email").value; + let password = document.getElementById("password").value; + let p_id = document.getElementById("p_id").value; + let role = document.getElementById("role").value; + + console.log(email); + + // Creating a XHR object + var xhr = new XMLHttpRequest(); + let url = "https://localhost:44348/api/operations"; + + // open a connection + xhr.open("POST", url, true); + + // Set the request header i.e. which type of content you are sending + xhr.setRequestHeader("Content-Type", "application/json"); + + // Create a state change callback + xhr.onreadystatechange = function () { + if (xhr.readyState===4){ + if (xhr.status === 200) { + console.log("registered"); + } + else { + alert("unsuccessful"); + } + } + }; + + // Converting JSON data to string + var data = JSON.stringify({ "Name": name,"Email": email, "Username": username, "Password": password, + "ProjectId": p_id, "Role": role }); + console.log(data); + + // Sending data with the request + xhr.send(data); +} \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/update.js b/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/update.js new file mode 100644 index 0000000..85f7f13 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/assets/scripts/update.js @@ -0,0 +1,76 @@ +function deleteUser(){ + + let id = document.getElementById("id").value; + console.log(id.value); + + // Creating a XHR object + var xhr = new XMLHttpRequest(); + let url = "https://localhost:44348/api/operations/"+id; + + + // open a connection + xhr.open("DELETE", url, true); + + // Set the request header i.e. which type of content you are sending + xhr.setRequestHeader("Content-Type", "application/json"); + + // Create a state change callback + xhr.onreadystatechange = function () { + if (xhr.readyState === 4 && xhr.status === 200) { + alert("deleted user") + console.log(url); + } + else{ + alert("no user with such ID"); + } + }; + + // Converting JSON data to string + var data = JSON.stringify({ "id": id.value}); + + // Sending data with the request + xhr.send(data); +} + +function updateUser(){ + let id = document.getElementById("r_id").value; + let name = document.getElementById("name").value; + let username = document.getElementById("username").value; + let email = document.getElementById("email").value; + let password = document.getElementById("password").value; + let p_id = document.getElementById("p_id").value; + let role = document.getElementById("role").value; + + + // Creating a XHR object + var xhr = new XMLHttpRequest(); + let url = "https://localhost:44348/api/operations/"+id; + console.log(url); + + // open a connection + xhr.open("PUT", url, true); + + // Set the request header i.e. which type of content you are sending + xhr.setRequestHeader("Content-Type", "application/json"); + + // Create a state change callback + xhr.onreadystatechange = function () { + if (xhr.readyState===4){ + if (xhr.status === 200) { + console.log("updated"); + alert("successfully updated"); + } + else { + alert("unsuccessful"); + } + } + }; + + // Converting JSON data to string + var data = JSON.stringify({ "RId": id,"ProjectId": p_id,"Name": name,"Email": email, "Username": username, "Password": password, + "Role": role }); + console.log(data); + + // Sending data with the request + xhr.send(data); +} \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/styles/display.css b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/display.css new file mode 100644 index 0000000..e69de29 diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/styles/list.css b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/list.css new file mode 100644 index 0000000..08bbeec --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/list.css @@ -0,0 +1,168 @@ +html { + background-color: #56baed; + } + + body { + font-family: "Poppins", sans-serif; + height: 100vh; + } + + a { + color: #92badd; + display:inline-block; + text-decoration: none; + font-weight: 400; + } + + h2 { + text-align: center; + font-size: 16px; + font-weight: 600; + text-transform: uppercase; + display:inline-block; + margin: 40px 8px 10px 8px; + color: #cccccc; + } + + + + /* STRUCTURE */ + + .wrapper { + display: flex; + align-items: center; + flex-direction: column; + justify-content: center; + width: 100%; + min-height: 100%; + padding: 20px; + } + + #formContent { + -webkit-border-radius: 10px 10px 10px 10px; + border-radius: 10px 10px 10px 10px; + background: #fff; + padding: 30px; + width: 90%; + max-width: 450px; + position: relative; + padding: 0px; + -webkit-box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3); + box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3); + text-align: center; + } + + #formFooter { + background-color: #f6f6f6; + border-top: 1px solid #dce8f1; + padding: 25px; + text-align: center; + -webkit-border-radius: 0 0 10px 10px; + border-radius: 0 0 10px 10px; + } + + + + /* TABS */ + + h2.inactive { + color: #cccccc; + } + + h2.active { + color: #0d0d0d; + border-bottom: 2px solid #5fbae9; + } + + + + /* FORM TYPOGRAPHY*/ + + input[type=button], input[type=submit], input[type=reset] { + background-color: #56baed; + border: none; + color: white; + padding: 15px 80px; + text-align: center; + text-decoration: none; + display: inline-block; + text-transform: uppercase; + font-size: 13px; + -webkit-box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4); + box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4); + -webkit-border-radius: 5px 5px 5px 5px; + border-radius: 5px 5px 5px 5px; + margin: 5px 20px 40px 20px; + -webkit-transition: all 0.3s ease-in-out; + -moz-transition: all 0.3s ease-in-out; + -ms-transition: all 0.3s ease-in-out; + -o-transition: all 0.3s ease-in-out; + transition: all 0.3s ease-in-out; + } + + input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover { + background-color: #39ace7; + } + + input[type=button]:active, input[type=submit]:active, input[type=reset]:active { + -moz-transform: scale(0.95); + -webkit-transform: scale(0.95); + -o-transform: scale(0.95); + -ms-transform: scale(0.95); + transform: scale(0.95); + } + + input[type=text] { + background-color: #f6f6f6; + border: none; + color: #0d0d0d; + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin: 5px; + width: 85%; + border: 2px solid #f6f6f6; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -ms-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + transition: all 0.5s ease-in-out; + -webkit-border-radius: 5px 5px 5px 5px; + border-radius: 5px 5px 5px 5px; + } + + input[type=text]:focus { + background-color: #fff; + border-bottom: 2px solid #5fbae9; + } + + input[type=text]:placeholder { + color: #cccccc; + } + + + + + + /* Simple CSS3 Fade-in Animation */ + + + + + + + /* OTHERS */ + + *:focus { + outline: none; + } + + + + * { + box-sizing: border-box; + } + + \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/styles/login.css b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/login.css new file mode 100644 index 0000000..0d2c7ce --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/login.css @@ -0,0 +1,171 @@ +@import url('https://fonts.googleapis.com/css?family=Poppins'); + +/* BASIC */ + +html { + background-color: #56baed; +} + +body { + font-family: "Poppins", sans-serif; + height: 100vh; +} + +a { + color: #92badd; + display:inline-block; + text-decoration: none; + font-weight: 400; +} + +h2 { + text-align: center; + font-size: 16px; + font-weight: 600; + text-transform: uppercase; + display:inline-block; + margin: 40px 8px 10px 8px; + color: #cccccc; +} + + + +/* STRUCTURE */ + +.wrapper { + display: flex; + align-items: center; + flex-direction: column; + justify-content: center; + width: 100%; + min-height: 100%; + padding: 20px; +} + +#formContent { + -webkit-border-radius: 10px 10px 10px 10px; + border-radius: 10px 10px 10px 10px; + background: #fff; + padding: 30px; + width: 90%; + max-width: 450px; + position: relative; + padding: 0px; + -webkit-box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3); + box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3); + text-align: center; +} + +#formFooter { + background-color: #f6f6f6; + border-top: 1px solid #dce8f1; + padding: 25px; + text-align: center; + -webkit-border-radius: 0 0 10px 10px; + border-radius: 0 0 10px 10px; +} + + + +/* TABS */ + +h2.inactive { + color: #cccccc; +} + +h2.active { + color: #0d0d0d; + border-bottom: 2px solid #5fbae9; +} + + + +/* FORM TYPOGRAPHY*/ + +input[type=button], input[type=submit], input[type=reset] { + background-color: #56baed; + border: none; + color: white; + padding: 15px 80px; + text-align: center; + text-decoration: none; + display: inline-block; + text-transform: uppercase; + font-size: 13px; + -webkit-box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4); + box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4); + -webkit-border-radius: 5px 5px 5px 5px; + border-radius: 5px 5px 5px 5px; + margin: 5px 20px 40px 20px; + -webkit-transition: all 0.3s ease-in-out; + -moz-transition: all 0.3s ease-in-out; + -ms-transition: all 0.3s ease-in-out; + -o-transition: all 0.3s ease-in-out; + transition: all 0.3s ease-in-out; +} + +input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover { + background-color: #39ace7; +} + +input[type=button]:active, input[type=submit]:active, input[type=reset]:active { + -moz-transform: scale(0.95); + -webkit-transform: scale(0.95); + -o-transform: scale(0.95); + -ms-transform: scale(0.95); + transform: scale(0.95); +} + +input[type=text] { + background-color: #f6f6f6; + border: none; + color: #0d0d0d; + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin: 5px; + width: 85%; + border: 2px solid #f6f6f6; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -ms-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + transition: all 0.5s ease-in-out; + -webkit-border-radius: 5px 5px 5px 5px; + border-radius: 5px 5px 5px 5px; +} + +input[type=text]:focus { + background-color: #fff; + border-bottom: 2px solid #5fbae9; +} + +input[type=text]:placeholder { + color: #cccccc; +} + + + + + +/* Simple CSS3 Fade-in Animation */ + + + + + + +/* OTHERS */ + +*:focus { + outline: none; +} + + + +* { + box-sizing: border-box; +} + diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/styles/register.css b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/register.css new file mode 100644 index 0000000..17607e7 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/register.css @@ -0,0 +1,79 @@ +@import url('https://fonts.googleapis.com/css?family=Poppins'); + +/* BASIC */ + +html { + background-color: #56baed; +} + +body { + font-family: "Poppins", sans-serif; + height: 100vh; +} + +a { + color: #92badd; + display:inline-block; + text-decoration: none; + font-weight: 400; +} + +h2 { + text-align: center; + font-size: 16px; + font-weight: 600; + text-transform: uppercase; + display:inline-block; + margin: 40px 8px 10px 8px; + color: #cccccc; +} + + + +/* STRUCTURE */ + +.wrapper { + display: flex; + align-items: center; + flex-direction: column; + justify-content: center; + width: 100%; + min-height: 100%; + padding: 20px; +} + +#formContent { + -webkit-border-radius: 10px 10px 10px 10px; + border-radius: 10px 10px 10px 10px; + background: #fff; + padding: 30px; + width: 90%; + max-width: 450px; + position: relative; + padding: 0px; + -webkit-box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3); + box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3); + text-align: center; +} + +#formFooter { + background-color: #f6f6f6; + border-top: 1px solid #dce8f1; + padding: 25px; + text-align: center; + -webkit-border-radius: 0 0 10px 10px; + border-radius: 0 0 10px 10px; +} + + + +/* TABS */ + +h2.inactive { + color: #cccccc; +} + +h2.active { + color: #0d0d0d; + border-bottom: 2px solid #5fbae9; +} \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/assets/styles/update.css b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/update.css new file mode 100644 index 0000000..ba59781 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/assets/styles/update.css @@ -0,0 +1,171 @@ +@import url('https://fonts.googleapis.com/css?family=Poppins'); + +/* BASIC */ + +html { + background-color: #56baed; +} + +body { + font-family: "Poppins", sans-serif; + height: 100vh; +} + +a { + color: #92badd; + display:inline-block; + text-decoration: none; + font-weight: 400; +} + +h2 { + text-align: center; + font-size: 16px; + font-weight: 600; + text-transform: uppercase; + display:inline-block; + margin: 40px 8px 10px 8px; + color: #cccccc; +} + + + +/* STRUCTURE */ + +.wrapper { + display: flex; + align-items: center; + flex-direction: column; + justify-content: center; + width: 100%; + min-height: 100%; + padding: 20px; +} + +#formContent { + -webkit-border-radius: 10px 10px 10px 10px; + border-radius: 10px 10px 10px 10px; + background: #fff; + padding: 30px; + width: 90%; + max-width: 450px; + position: relative; + padding: 0px; + -webkit-box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3); + box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3); + text-align: center; + padding-bottom: 2rem; +} + +#formFooter { + background-color: #f6f6f6; + border-top: 1px solid #dce8f1; + padding: 25px; + text-align: center; + -webkit-border-radius: 0 0 10px 10px; + border-radius: 0 0 10px 10px; +} + + + +/* TABS */ + +h2.inactive { + color: #cccccc; +} + +h2.active { + color: #0d0d0d; + border-bottom: 2px solid #5fbae9; +} + + + +/* FORM TYPOGRAPHY*/ + +input[type=button], input[type=submit], input[type=reset] { + background-color: #56baed; + border: none; + color: white; + padding: 15px 80px; + text-align: center; + text-decoration: none; + display: inline-block; + text-transform: uppercase; + font-size: 13px; + -webkit-box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4); + box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4); + -webkit-border-radius: 5px 5px 5px 5px; + border-radius: 5px 5px 5px 5px; + margin: 5px 20px 40px 20px; + -webkit-transition: all 0.3s ease-in-out; + -moz-transition: all 0.3s ease-in-out; + -ms-transition: all 0.3s ease-in-out; + -o-transition: all 0.3s ease-in-out; + transition: all 0.3s ease-in-out; +} + +input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover { + background-color: #39ace7; +} + +input[type=button]:active, input[type=submit]:active, input[type=reset]:active { + -moz-transform: scale(0.95); + -webkit-transform: scale(0.95); + -o-transform: scale(0.95); + -ms-transform: scale(0.95); + transform: scale(0.95); +} + +input[type=text] { + background-color: #f6f6f6; + border: none; + color: #0d0d0d; + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin: 5px; + width: 85%; + border: 2px solid #f6f6f6; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -ms-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + transition: all 0.5s ease-in-out; + -webkit-border-radius: 5px 5px 5px 5px; + border-radius: 5px 5px 5px 5px; +} + +input[type=text]:focus { + background-color: #fff; + border-bottom: 2px solid #5fbae9; +} + +input[type=text]:placeholder { + color: #cccccc; +} + + + + + +/* Simple CSS3 Fade-in Animation */ + + + + + + +/* OTHERS */ + +*:focus { + outline: none; +} + + + +* { + box-sizing: border-box; +} diff --git a/Chetna_Mongmaw/UsersApplication/ui/display.html b/Chetna_Mongmaw/UsersApplication/ui/display.html new file mode 100644 index 0000000..e699501 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/display.html @@ -0,0 +1,22 @@ + + + + + + + Document + + + + +
+

+ You are logged in as admin. +

+ + +

+

+ + + \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/list.html b/Chetna_Mongmaw/UsersApplication/ui/list.html new file mode 100644 index 0000000..d80a778 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/list.html @@ -0,0 +1,35 @@ + + + + + + + Document + + + + + + + +
+
+ +

Options

+ + + + +
+ + + +
+ + + +
+
+ + + \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/login.html b/Chetna_Mongmaw/UsersApplication/ui/login.html new file mode 100644 index 0000000..a733be2 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/login.html @@ -0,0 +1,38 @@ + + + + + + + Document + + + + + + + + + +
+
+ +

Sign In

+ + + + +
+ + + + +
+ + + +
+
+ + + \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/register.html b/Chetna_Mongmaw/UsersApplication/ui/register.html new file mode 100644 index 0000000..9105489 --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/register.html @@ -0,0 +1,34 @@ + + + + + + + Document + + + + + + +
+
+ +

Sign Up

+
+
+
+
+
+
+
+ +
+ +
+
+ + + + \ No newline at end of file diff --git a/Chetna_Mongmaw/UsersApplication/ui/update.html b/Chetna_Mongmaw/UsersApplication/ui/update.html new file mode 100644 index 0000000..6ca7eac --- /dev/null +++ b/Chetna_Mongmaw/UsersApplication/ui/update.html @@ -0,0 +1,46 @@ + + + + + + + Document + + + + + + + +
+
+ +
+ +
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/Chetna_Mongmaw/profile/p3.html b/Chetna_Mongmaw/profile/index.html similarity index 100% rename from Chetna_Mongmaw/profile/p3.html rename to Chetna_Mongmaw/profile/index.html