diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json
new file mode 100644
index 0000000..f8b4888
--- /dev/null
+++ b/.vs/ProjectSettings.json
@@ -0,0 +1,3 @@
+{
+ "CurrentProjectSetting": null
+}
\ No newline at end of file
diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json
new file mode 100644
index 0000000..ceffd6c
--- /dev/null
+++ b/.vs/VSWorkspaceState.json
@@ -0,0 +1,8 @@
+{
+ "ExpandedNodes": [
+ "",
+ "\\Services"
+ ],
+ "SelectedNode": "\\Services\\UserService.cs",
+ "PreviewInSolutionExplorer": false
+}
\ No newline at end of file
diff --git a/.vs/WebApi/DesignTimeBuild/.dtbcache b/.vs/WebApi/DesignTimeBuild/.dtbcache
new file mode 100644
index 0000000..a9dcf20
Binary files /dev/null and b/.vs/WebApi/DesignTimeBuild/.dtbcache differ
diff --git a/.vs/WebApi/v16/.suo b/.vs/WebApi/v16/.suo
new file mode 100644
index 0000000..6031d26
Binary files /dev/null and b/.vs/WebApi/v16/.suo differ
diff --git a/.vs/WebApi/v16/Server/sqlite3/db.lock b/.vs/WebApi/v16/Server/sqlite3/db.lock
new file mode 100644
index 0000000..e69de29
diff --git a/.vs/WebApi/v16/Server/sqlite3/storage.ide b/.vs/WebApi/v16/Server/sqlite3/storage.ide
new file mode 100644
index 0000000..b0a20f2
Binary files /dev/null and b/.vs/WebApi/v16/Server/sqlite3/storage.ide differ
diff --git a/.vs/aspnet-core-3-registration-login-api/config/applicationhost.config b/.vs/aspnet-core-3-registration-login-api/config/applicationhost.config
new file mode 100644
index 0000000..a128ebb
--- /dev/null
+++ b/.vs/aspnet-core-3-registration-login-api/config/applicationhost.config
@@ -0,0 +1,1017 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.vs/aspnet-core-3-registration-login-api/v16/.suo b/.vs/aspnet-core-3-registration-login-api/v16/.suo
new file mode 100644
index 0000000..5912ff2
Binary files /dev/null and b/.vs/aspnet-core-3-registration-login-api/v16/.suo differ
diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite
new file mode 100644
index 0000000..bc46b27
Binary files /dev/null and b/.vs/slnx.sqlite differ
diff --git a/Controllers/UsersController.cs b/Controllers/UsersController.cs
index 7d6a461..c702b3a 100644
--- a/Controllers/UsersController.cs
+++ b/Controllers/UsersController.cs
@@ -38,10 +38,10 @@ public UsersController(
[HttpPost("authenticate")]
public IActionResult Authenticate([FromBody]AuthenticateModel model)
{
- var user = _userService.Authenticate(model.Username, model.Password);
+ var user = _userService.Authenticate(model.Dni, model.Password);
if (user == null)
- return BadRequest(new { message = "Username or password is incorrect" });
+ return BadRequest(new { message = "Dni o password incorrecta" });
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(_appSettings.Secret);
@@ -61,7 +61,7 @@ public IActionResult Authenticate([FromBody]AuthenticateModel model)
return Ok(new
{
Id = user.Id,
- Username = user.Username,
+ Dni = user.Dni,
FirstName = user.FirstName,
LastName = user.LastName,
Token = tokenString
diff --git a/Entities/User.cs b/Entities/User.cs
index d948a87..8c2702a 100644
--- a/Entities/User.cs
+++ b/Entities/User.cs
@@ -5,7 +5,7 @@ public class User
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
- public string Username { get; set; }
+ public string Dni { get; set; }
public byte[] PasswordHash { get; set; }
public byte[] PasswordSalt { get; set; }
}
diff --git a/Migrations/SqlServerMigrations/20200102103423_InitialCreate.Designer.cs b/Migrations/SqlServerMigrations/20200102103423_InitialCreate.Designer.cs
index c88a2e2..bf677aa 100644
--- a/Migrations/SqlServerMigrations/20200102103423_InitialCreate.Designer.cs
+++ b/Migrations/SqlServerMigrations/20200102103423_InitialCreate.Designer.cs
@@ -40,7 +40,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b.Property("PasswordSalt")
.HasColumnType("varbinary(max)");
- b.Property("Username")
+ b.Property("Dni")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
diff --git a/Migrations/SqlServerMigrations/20200102103423_InitialCreate.cs b/Migrations/SqlServerMigrations/20200102103423_InitialCreate.cs
index 876a668..3a0ddcf 100644
--- a/Migrations/SqlServerMigrations/20200102103423_InitialCreate.cs
+++ b/Migrations/SqlServerMigrations/20200102103423_InitialCreate.cs
@@ -15,7 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
.Annotation("SqlServer:Identity", "1, 1"),
FirstName = table.Column(nullable: true),
LastName = table.Column(nullable: true),
- Username = table.Column(nullable: true),
+ Dni = table.Column(nullable: true),
PasswordHash = table.Column(nullable: true),
PasswordSalt = table.Column(nullable: true)
},
diff --git a/Migrations/SqlServerMigrations/DataContextModelSnapshot.cs b/Migrations/SqlServerMigrations/DataContextModelSnapshot.cs
index 85473eb..1d5f3d5 100644
--- a/Migrations/SqlServerMigrations/DataContextModelSnapshot.cs
+++ b/Migrations/SqlServerMigrations/DataContextModelSnapshot.cs
@@ -38,7 +38,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property("PasswordSalt")
.HasColumnType("varbinary(max)");
- b.Property("Username")
+ b.Property("Dni")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
diff --git a/Migrations/SqliteMigrations/20200102102942_InitialCreate.Designer.cs b/Migrations/SqliteMigrations/20200102102942_InitialCreate.Designer.cs
index 519f449..30d0955 100644
--- a/Migrations/SqliteMigrations/20200102102942_InitialCreate.Designer.cs
+++ b/Migrations/SqliteMigrations/20200102102942_InitialCreate.Designer.cs
@@ -36,7 +36,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
b.Property("PasswordSalt")
.HasColumnType("BLOB");
- b.Property("Username")
+ b.Property("Dni")
.HasColumnType("TEXT");
b.HasKey("Id");
diff --git a/Migrations/SqliteMigrations/20200102102942_InitialCreate.cs b/Migrations/SqliteMigrations/20200102102942_InitialCreate.cs
index 7562f4f..f0a1b6e 100644
--- a/Migrations/SqliteMigrations/20200102102942_InitialCreate.cs
+++ b/Migrations/SqliteMigrations/20200102102942_InitialCreate.cs
@@ -15,7 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
.Annotation("Sqlite:Autoincrement", true),
FirstName = table.Column(nullable: true),
LastName = table.Column(nullable: true),
- Username = table.Column(nullable: true),
+ Dni = table.Column(nullable: true),
PasswordHash = table.Column(nullable: true),
PasswordSalt = table.Column(nullable: true)
},
diff --git a/Migrations/SqliteMigrations/SqliteDataContextModelSnapshot.cs b/Migrations/SqliteMigrations/SqliteDataContextModelSnapshot.cs
index 84c2760..5e132e3 100644
--- a/Migrations/SqliteMigrations/SqliteDataContextModelSnapshot.cs
+++ b/Migrations/SqliteMigrations/SqliteDataContextModelSnapshot.cs
@@ -34,7 +34,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property("PasswordSalt")
.HasColumnType("BLOB");
- b.Property("Username")
+ b.Property("Dni")
.HasColumnType("TEXT");
b.HasKey("Id");
diff --git a/Models/Users/AuthenticateModel.cs b/Models/Users/AuthenticateModel.cs
index b5c5956..c540e82 100644
--- a/Models/Users/AuthenticateModel.cs
+++ b/Models/Users/AuthenticateModel.cs
@@ -5,7 +5,7 @@ namespace WebApi.Models.Users
public class AuthenticateModel
{
[Required]
- public string Username { get; set; }
+ public string Dni { get; set; }
[Required]
public string Password { get; set; }
diff --git a/Models/Users/RegisterModel.cs b/Models/Users/RegisterModel.cs
index 92bdc1f..2a3c052 100644
--- a/Models/Users/RegisterModel.cs
+++ b/Models/Users/RegisterModel.cs
@@ -11,7 +11,7 @@ public class RegisterModel
public string LastName { get; set; }
[Required]
- public string Username { get; set; }
+ public string Dni { get; set; }
[Required]
public string Password { get; set; }
diff --git a/Models/Users/UpdateModel.cs b/Models/Users/UpdateModel.cs
index 6b86da9..e25b0f2 100644
--- a/Models/Users/UpdateModel.cs
+++ b/Models/Users/UpdateModel.cs
@@ -4,7 +4,7 @@ public class UpdateModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
- public string Username { get; set; }
+ public string Dni { get; set; }
public string Password { get; set; }
}
}
\ No newline at end of file
diff --git a/Models/Users/UserModel.cs b/Models/Users/UserModel.cs
index 9c61d04..2bd1cbe 100644
--- a/Models/Users/UserModel.cs
+++ b/Models/Users/UserModel.cs
@@ -5,6 +5,6 @@ public class UserModel
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
- public string Username { get; set; }
+ public string Dni { get; set; }
}
}
\ No newline at end of file
diff --git a/Services/UserService.cs b/Services/UserService.cs
index 379ed3c..ec22887 100644
--- a/Services/UserService.cs
+++ b/Services/UserService.cs
@@ -8,7 +8,7 @@ namespace WebApi.Services
{
public interface IUserService
{
- User Authenticate(string username, string password);
+ User Authenticate(string dni, string password);
IEnumerable GetAll();
User GetById(int id);
User Create(User user, string password);
@@ -25,14 +25,14 @@ public UserService(DataContext context)
_context = context;
}
- public User Authenticate(string username, string password)
+ public User Authenticate(string dni, string password)
{
- if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
+ if (string.IsNullOrEmpty(dni) || string.IsNullOrEmpty(password))
return null;
- var user = _context.Users.SingleOrDefault(x => x.Username == username);
+ var user = _context.Users.SingleOrDefault(x => x.dni == dni);
- // check if username exists
+ // check if dni exists
if (user == null)
return null;
@@ -60,8 +60,8 @@ public User Create(User user, string password)
if (string.IsNullOrWhiteSpace(password))
throw new AppException("Password is required");
- if (_context.Users.Any(x => x.Username == user.Username))
- throw new AppException("Username \"" + user.Username + "\" is already taken");
+ if (_context.Users.Any(x => x.dni == user.dni))
+ throw new AppException("dni \"" + user.dni + "\" is already taken");
byte[] passwordHash, passwordSalt;
CreatePasswordHash(password, out passwordHash, out passwordSalt);
@@ -82,14 +82,14 @@ public void Update(User userParam, string password = null)
if (user == null)
throw new AppException("User not found");
- // update username if it has changed
- if (!string.IsNullOrWhiteSpace(userParam.Username) && userParam.Username != user.Username)
+ // update dni if it has changed
+ if (!string.IsNullOrWhiteSpace(userParam.dni) && userParam.dni != user.dni)
{
- // throw error if the new username is already taken
- if (_context.Users.Any(x => x.Username == userParam.Username))
- throw new AppException("Username " + userParam.Username + " is already taken");
+ // throw error if the new dni is already taken
+ if (_context.Users.Any(x => x.dni == userParam.dni))
+ throw new AppException("dni " + userParam.dni + " is already taken");
- user.Username = userParam.Username;
+ user.dni = userParam.dni;
}
// update user properties if provided
diff --git a/WebApi.sln b/WebApi.sln
new file mode 100644
index 0000000..aabc917
--- /dev/null
+++ b/WebApi.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29806.167
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "WebApi.csproj", "{03A2C7FA-2FD1-4095-AA9A-BA0BE809439B}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {03A2C7FA-2FD1-4095-AA9A-BA0BE809439B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {03A2C7FA-2FD1-4095-AA9A-BA0BE809439B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {03A2C7FA-2FD1-4095-AA9A-BA0BE809439B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {03A2C7FA-2FD1-4095-AA9A-BA0BE809439B}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {BF49A40E-181F-4814-A7D5-4445FEC87189}
+ EndGlobalSection
+EndGlobal
diff --git a/appsettings.Development.json b/appsettings.Development.json
index 0b5ef19..43b5dcb 100644
--- a/appsettings.Development.json
+++ b/appsettings.Development.json
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
- "WebApiDatabase": "Data Source=LocalDatabase.db"
+ "WebApiDatabase": "Data Source=DESKTOP-QF24B4L;Initial Catalog=CruzRojaDB;Integrated Security=True;"
},
"Logging": {
"LogLevel": {
diff --git a/appsettings.json b/appsettings.json
index 8df0888..51d6bc6 100644
--- a/appsettings.json
+++ b/appsettings.json
@@ -1,16 +1,16 @@
{
- "AppSettings": {
- "Secret": "THIS IS USED TO SIGN AND VERIFY JWT TOKENS, REPLACE IT WITH YOUR OWN SECRET, IT CAN BE ANY STRING"
- },
- "ConnectionStrings": {
- "WebApiDatabase": "ENTER PRODUCTION SQL SERVER CONNECTION STRING HERE"
- },
- "Logging": {
- "LogLevel": {
- "Default": "Information",
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
- }
- },
- "AllowedHosts": "*"
+ "AppSettings": {
+ "Secret": "administration-password"
+ },
+ "ConnectionStrings": {
+ "WebApiDatabase": "Data Source=DESKTOP-QF24B4L;Initial Catalog=CruzRojaDB;Integrated Security=True;"
+ },
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ },
+ "AllowedHosts": "*"
}