Update "User" API
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using skydiveLogs_api.Business.Interface;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
using skydiveLogs_api.Business.Interface;
|
|
||||||
using skydiveLogs_api.Model;
|
using skydiveLogs_api.Model;
|
||||||
using skydiveLogs_api.Data.Interface;
|
using skydiveLogs_api.Data.Interface;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace skydiveLogs_api.Business
|
namespace skydiveLogs_api.Business
|
||||||
{
|
{
|
||||||
@@ -17,16 +17,44 @@ namespace skydiveLogs_api.Business
|
|||||||
|
|
||||||
public User GetByLogin(string login, string password)
|
public User GetByLogin(string login, string password)
|
||||||
{
|
{
|
||||||
var tmp = _userRepository.GetByLogin(login, password);
|
var tmp = _userRepository.GetByLogin(login, EncryptPassword(password));
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddNewUser(User newUser)
|
public void AddNewUser(User newUser)
|
||||||
{
|
{
|
||||||
|
newUser.Password = EncryptPassword(newUser.Password);
|
||||||
_userRepository.Add(newUser);
|
_userRepository.Add(newUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string EncryptPassword(string password)
|
||||||
|
{
|
||||||
|
var encryptionKey = "skydivelogsangular"; //we can change the code converstion key as per our requirement
|
||||||
|
byte[] clearBytes = Encoding.Unicode.GetBytes(password);
|
||||||
|
var encryptedPassword = string.Empty;
|
||||||
|
|
||||||
|
using (Aes encryptor = Aes.Create())
|
||||||
|
{
|
||||||
|
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(encryptionKey,
|
||||||
|
new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
|
||||||
|
encryptor.Key = pdb.GetBytes(32);
|
||||||
|
encryptor.IV = pdb.GetBytes(16);
|
||||||
|
using (MemoryStream ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
|
||||||
|
{
|
||||||
|
cs.Write(clearBytes, 0, clearBytes.Length);
|
||||||
|
cs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptedPassword = Convert.ToBase64String(ms.ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return encryptedPassword;
|
||||||
|
}
|
||||||
|
|
||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,14 @@ namespace skydiveLogs_api.Ioc
|
|||||||
_services.AddScoped<Business.Interface.IJumpService, Business.JumpService>();
|
_services.AddScoped<Business.Interface.IJumpService, Business.JumpService>();
|
||||||
_services.AddScoped<Business.Interface.IJumpTypeService, Business.JumpTypeService>();
|
_services.AddScoped<Business.Interface.IJumpTypeService, Business.JumpTypeService>();
|
||||||
_services.AddScoped<Business.Interface.IStatsService, Business.StatsService>();
|
_services.AddScoped<Business.Interface.IStatsService, Business.StatsService>();
|
||||||
|
_services.AddScoped<Business.Interface.IUserService, Business.UserService>();
|
||||||
|
|
||||||
_services.AddScoped<Data.Interface.IAircraftRepository, Data.AircraftRepository>();
|
_services.AddScoped<Data.Interface.IAircraftRepository, Data.AircraftRepository>();
|
||||||
_services.AddScoped<Data.Interface.IDropZoneRepository, Data.DropZoneRepository>();
|
_services.AddScoped<Data.Interface.IDropZoneRepository, Data.DropZoneRepository>();
|
||||||
_services.AddScoped<Data.Interface.IJumpRepository, Data.JumpRepository>();
|
_services.AddScoped<Data.Interface.IJumpRepository, Data.JumpRepository>();
|
||||||
_services.AddScoped<Data.Interface.IJumpTypeRepository, Data.JumpTypeRepository>();
|
_services.AddScoped<Data.Interface.IJumpTypeRepository, Data.JumpTypeRepository>();
|
||||||
_services.AddScoped<Data.Interface.IGearRepository, Data.GearRepository>();
|
_services.AddScoped<Data.Interface.IGearRepository, Data.GearRepository>();
|
||||||
|
_services.AddScoped<Data.Interface.IUserRepository, Data.UserRepository>();
|
||||||
|
|
||||||
string connectionString = _configuration.GetConnectionString("DefaultConnection");
|
string connectionString = _configuration.GetConnectionString("DefaultConnection");
|
||||||
_services.AddSingleton<Data.Interface.IDataProvider>(c => new Data.LiteDbProvider(connectionString));
|
_services.AddSingleton<Data.Interface.IDataProvider>(c => new Data.LiteDbProvider(connectionString));
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ namespace skydiveLogs_api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST: api/User
|
// POST: api/User
|
||||||
[HttpPost]
|
[HttpPost("Authenticate")]
|
||||||
[EnableCors]
|
[EnableCors]
|
||||||
public UserResp Authenticate([FromBody] string login, [FromBody] string password)
|
public UserResp Authenticate([FromBody] UserReq value)
|
||||||
{
|
{
|
||||||
var result = _userService.GetByLogin(login, password);
|
var result = _userService.GetByLogin(value.Login, value.Password);
|
||||||
return _mapper.Map<UserResp>(result);
|
return _mapper.Map<UserResp>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user