Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 removed .swp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion Anchal_Hora/Readme.md

This file was deleted.

Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
983 changes: 983 additions & 0 deletions Anchal_Hora/panel/.vs/config/applicationhost.config

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Anchal_Hora/panel/Database/SQLQuery14.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE EmpInformation(SNo int primary key, Projectid VARCHAR(200) , name VARCHAR(500) ,email VARCHAR(200) UNIQUE , [PASSWORD] VARCHAR(200) , [ROLE] VARCHAR(500), ContactNo bigint, ProjectName VARCHAR(200) );

INSERT INTO EmpInformation VALUES ('1', 'P1', 'Anchal','horaanchal@gmail.com', 'anchal', 'User1', '6656676878', 'Web development');
INSERT INTO EmpInformation VALUES ('2', 'P1', 'Anjali','horaanjali@gmail.com', 'anjali', 'User2', '7867665676', 'Web development');
INSERT INTO EmpInformation VALUES ('3', 'P2', 'Ankush','horaankush@gmail.com', 'ankush', 'User3', '6656566766', 'AI');
INSERT INTO EmpInformation VALUES ('4', 'P2', 'Resham','horaresham@gmail.com', 'resham', 'User4', '8990876774','AI');
INSERT INTO EmpInformation VALUES ('5', 'P1', 'Ansh','horaansh@gmail.com', 'ansh', 'Reporting Manager1', '7545347667', 'Web development');
INSERT INTO EmpInformation VALUES ('6', 'P2', 'Aditya','horaaditya@gmail.com', 'aditya', 'Reporting Manager2', '6378656789', 'AI');
INSERT INTO EmpInformation VALUES ('7','', 'Raghav','horaraghavl@gmail.com', 'raghav', 'Admin', '5653424789','');

SELECT * from EmpInformation ;
62 changes: 62 additions & 0 deletions Anchal_Hora/panel/Login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function login(){
document.getElementById("btn").addEventListener("click",postData)
function postData(){
var Sno=parseInt(document.getElementById("inputid").value);
var Username=document.getElementById("inputName").value;
var Email=document.getElementById("inputEmail").value;
var Password=document.getElementById("inputPassword").value;

console.log(empLogin);
api(empLogin);

window.location.href = "./admin/index.html";

};
var empLogin = {
"Sno":Sno,
"Name":Username,
"Email":Email,
"Password":Password
};

function parseJwt (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);
printToken(jsonPayload);
debugger;
return JSON.parse(jsonPayload);

}

function api(empLogin){
let json = empLogin;
//sendHTTPReq('POST', "http://localhost:51391/api/Panel", json).then(x => func() );
var xhr= new XMLHttpRequest();
var url="http://localhost:51391/api/Login";
xhr.open('POST', url,true);
xhr.responseType='json';
xhr.setRequestHeader('Content-type','application/json');
console.log(JSON.stringify(json));
xhr.onload = () => {
console.log(xhr.response);
let jwtToken = {} ;
jwtToken = xhr.response;
parseJwt(jwtToken);
debugger;
};
xhr.onerror = (err) =>{
console.log(err);
};
xhr.send(JSON.stringify(json));
}
//debugger;

}
function printToken(jsonPayload){
console.log(jsonPayload);
}
25 changes: 25 additions & 0 deletions Anchal_Hora/panel/WebApplicationPanel.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.1000
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplicationPanel", "WebApplicationPanel\WebApplicationPanel.csproj", "{EC1659EB-707D-416C-8BD0-AD72DD2CCE40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EC1659EB-707D-416C-8BD0-AD72DD2CCE40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC1659EB-707D-416C-8BD0-AD72DD2CCE40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC1659EB-707D-416C-8BD0-AD72DD2CCE40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC1659EB-707D-416C-8BD0-AD72DD2CCE40}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6291CE64-2D3B-4B27-BB96-989FDEF68E3B}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using WebApplicationPanel.DbModels;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace WebappAPItype.Controllers
{
[Route("api/[controller]")]
[ApiController]

public class LoginController : Controller
{
private panelContext _panelcontext;
private IConfiguration _config;
private panelContext _panelContext;

public LoginController(IConfiguration config, panelContext panelcontext)

{
_panelcontext = panelcontext;
_config = config;
}

[HttpPost]
public IActionResult Login([FromBody] EmpInformation login)
{
IActionResult response = Unauthorized();
var user = AuthenticateUser(login);

if (user != null)
{
var tokenString = GenerateJSONWebToken(user);
response = Ok(new { token = tokenString });
}

return response;
}

private object GenerateJSONWebToken(object user)
{
throw new NotImplementedException();
}

private string GenerateJSONWebToken(EmpInformation userInfo)
{
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
var claims = new[] {
new Claim("Name", userInfo.Name),
new Claim("Email", userInfo.Email),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
};


var token = new JwtSecurityToken(_config["Jwt:Issuer"],
_config["Jwt:Issuer"],
claims,
expires: DateTime.Now.AddMinutes(120),
signingCredentials: credentials);

return new JwtSecurityTokenHandler().WriteToken(token);
}

private EmpInformation AuthenticateUser(EmpInformation login)
{
EmpInformation user = _panelcontext.EmpInformation.Where(u => u.Sno == login.Sno && u.Password == login.Password).FirstOrDefault();
if (user != null)
{
user = new EmpInformation { Email = user.Email, Name=user.Name };
}
return user;
}
}
}
10 changes: 10 additions & 0 deletions Anchal_Hora/panel/WebApplicationPanel/Controllers/Panel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace WebApplicationPanel.Controllers
{
internal class Panel
{
public int Sno { get; internal set; }
public int Username { get; internal set; }
public string Emailid { get; internal set; }
public string Password { get; internal set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using System.Configuration;
using Microsoft.AspNetCore.Mvc;
using WebApplicationPanel.DbModels;
using WebappAPItype.CustomModels;
using Microsoft.Extensions.Configuration;

namespace WebApplicationPanel.Controllers
{
[Route("api/[controller]")]
[ApiController]

Comment thread
horaanchal marked this conversation as resolved.

public class PanelController : ControllerBase
{
panelContext _panelContext;

public PanelController(panelContext panelContext)
{
_panelContext = panelContext;
}
[HttpPost]
public IActionResult Createpanel([FromBody]PanelRequest panelRequest)
{
EmpInformation panel = new EmpInformation();
panel.Sno = panelRequest.Sno;
panel.Name = panelRequest.Name;
panel.Email = panelRequest.Email;
panel.Password = panelRequest.Password;

_panelContext.EmpInformation.Add(panel);
_panelContext.SaveChanges();
return Ok("Employee Added");

}

[HttpGet]
public IActionResult Get()
{
List<EmpInformation> output = _panelContext.EmpInformation.ToList();
return Ok(output);
}
[HttpGet("{id}")]

public ActionResult<string> Get(int id)
{
EmpInformation output = _panelContext.EmpInformation.Find(id);
if (output == null)
{
return NotFound();
}
return Ok(output);
}


[HttpPut("{id}")]

public IActionResult Put(int id, [FromBody]PanelRequest panelRequest)
{
EmpInformation panel = _panelContext.EmpInformation.Find(id);
panel.Email = panelRequest.Email;
panel.Name = panelRequest.Name;
panel.Password = panelRequest.Password;
// _panelContext.EmpInformation.Update(panel);
_panelContext.SaveChanges();
return Ok("Employee updated");

}

[HttpDelete("{id}")]

public ActionResult<string> Delete(int id)
{
EmpInformation output = _panelContext.EmpInformation.Where(x => x.Sno == id).FirstOrDefault();
if (output == null)
{
return NotFound();
}
//EmpInformation e = new EmpInformation { Sno = id };

_panelContext.EmpInformation.Remove(output);
_panelContext.SaveChanges();
return Ok("Employee Deleted");
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplicationPanel.CustomModels;
using WebApplicationPanel.DbModels;

namespace WebApplicationPanel.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class deleteController : Controller
{
panelContext _panelContext;

//private object panelContext;
//private object panel;

public deleteController(panelContext panelContext)
{
_panelContext = panelContext;
}
[HttpDelete("{id}")]

public ActionResult<string> Delete(int id)
{
EmpInformation output = _panelContext.EmpInformation.Where(x => x.Sno == id).FirstOrDefault();
if (output == null)
{
return NotFound();
}
//EmpInformation e = new EmpInformation { Sno = id };

_panelContext.EmpInformation.Remove(output);
_panelContext.SaveChanges();
return Ok("Employee Deleted");
}
}
}
30 changes: 30 additions & 0 deletions Anchal_Hora/panel/WebApplicationPanel/Controllers/getController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplicationPanel.DbModels;

namespace WebApplicationPanel.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class getController : Controller
{
panelContext _panelContext;

//private object panelContext;
//private object panel;

public getController(panelContext panelContext)
{
_panelContext = panelContext;
}
[HttpGet]
public IActionResult Get()
{
List<EmpInformation> output = _panelContext.EmpInformation.ToList();
return Ok(output);
}
}
}
Loading