Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
984 changes: 984 additions & 0 deletions Chetna_Mongmaw/UsersApplication/.vs/config/applicationhost.config

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions Chetna_Mongmaw/UsersApplication/UsersApplication.sln
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

Original file line number Diff line number Diff line change
@@ -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);

}
}
}
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<string>> Get()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove Unused Controller

{
return new string[] { "value1", "value2" };
}

// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> 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)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
16 changes: 16 additions & 0 deletions Chetna_Mongmaw/UsersApplication/UsersApplication/Models/Users.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace UsersApplication.Models
{
public partial class WebAppContext : DbContext
{
public WebAppContext()
{
}

public WebAppContext(DbContextOptions<WebAppContext> options)
: base(options)
{
}

public virtual DbSet<Users> Users { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
optionsBuilder.UseSqlServer("Server=CYG317\\SQLEXPRESS;Database=WebApp;Trusted_Connection=True;");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please Explain the use of this connection string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

corrected

}
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Users>(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);
});
}
}
}
24 changes: 24 additions & 0 deletions Chetna_Mongmaw/UsersApplication/UsersApplication/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Startup>();
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Loading