aboutsummaryrefslogtreecommitdiff
path: root/backend/api
diff options
context:
space:
mode:
authorOgnjen Cirkovic <ciraboxkg@gmail.com>2022-04-19 16:52:03 +0200
committerOgnjen Cirkovic <ciraboxkg@gmail.com>2022-04-19 16:52:03 +0200
commit054d567cef92cae42cd75f56c55e16febdac658c (patch)
tree501494be95ae31ff8594d92a924e9c1ef21c594b /backend/api
parent3c2a0be2a169f16702ff9648dc65ef9efbae07fc (diff)
Omoguceno pravljenje privremenog korisnika.
Diffstat (limited to 'backend/api')
-rw-r--r--backend/api/api/Controllers/ModelController.cs2
-rw-r--r--backend/api/api/Models/IJwtToken.cs2
-rw-r--r--backend/api/api/Models/JwtToken.cs5
-rw-r--r--backend/api/api/Models/User.cs1
-rw-r--r--backend/api/api/Services/AuthService.cs14
-rw-r--r--backend/api/api/Services/IAuthService.cs1
6 files changed, 20 insertions, 5 deletions
diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs
index ce1759ca..d60e3236 100644
--- a/backend/api/api/Controllers/ModelController.cs
+++ b/backend/api/api/Controllers/ModelController.cs
@@ -98,7 +98,7 @@ namespace api.Controllers
// GET: api/<ModelController>/mymodels
[HttpGet("mymodels")]
- [Authorize(Roles = "User")]
+ [Authorize(Roles = "User,Guest")]
public ActionResult<List<Model>> Get()
{
string uploaderId = getUserId();
diff --git a/backend/api/api/Models/IJwtToken.cs b/backend/api/api/Models/IJwtToken.cs
index 2afb6683..96b96997 100644
--- a/backend/api/api/Models/IJwtToken.cs
+++ b/backend/api/api/Models/IJwtToken.cs
@@ -4,7 +4,7 @@ namespace api.Models
{
public interface IJwtToken
{
- string GenGuestToken();
+ string GenGuestToken(string id);
string GenToken(AuthRequest user);
string RenewToken(string existingToken);
string TokenToUsername(string token);
diff --git a/backend/api/api/Models/JwtToken.cs b/backend/api/api/Models/JwtToken.cs
index 06b3a666..3ec75468 100644
--- a/backend/api/api/Models/JwtToken.cs
+++ b/backend/api/api/Models/JwtToken.cs
@@ -100,15 +100,16 @@ namespace api.Models
}
- public string GenGuestToken()
+ public string GenGuestToken(string id)
{
+ var user=_userService.GetUserById(id);
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(_configuration.GetSection("AppSettings:JwtToken").Value);
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new[] { new Claim("name",""),
new Claim("role", "Guest"),
- new Claim("id","")}),
+ new Claim("id",user._id)}),
Expires = DateTime.UtcNow.AddMinutes(20),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
diff --git a/backend/api/api/Models/User.cs b/backend/api/api/Models/User.cs
index 1ae8e437..ce289af1 100644
--- a/backend/api/api/Models/User.cs
+++ b/backend/api/api/Models/User.cs
@@ -25,6 +25,7 @@ namespace api.Models
public string LastName { get; set; }
public string photoId { get; set; }
+ public bool isPermament { get; set; }
}
}
diff --git a/backend/api/api/Services/AuthService.cs b/backend/api/api/Services/AuthService.cs
index c7161dee..b734fa7a 100644
--- a/backend/api/api/Services/AuthService.cs
+++ b/backend/api/api/Services/AuthService.cs
@@ -37,6 +37,7 @@ namespace api.Services
u.FirstName = user.firstName;
u.LastName = user.lastName;
u.photoId = "1";
+ u.isPermament = true;
if (_users.Find(user => user.Username == u.Username).FirstOrDefault() != null)
return "Username Already Exists";
if (_users.Find(user => user.Email == u.Email).FirstOrDefault() != null)
@@ -45,6 +46,13 @@ namespace api.Services
_users.InsertOne(u);
return "User added";
}
+ public void RegisterGuest()
+ {
+ User u=new User();
+ u._id = "";
+ _users.InsertOne(u);
+ _jwt.GenGuestToken(u._id);
+ }
public string RenewToken(string header)
{
@@ -60,7 +68,11 @@ namespace api.Services
public string GuestToken()
{
- return _jwt.GenGuestToken();
+ User u = new User();
+ u._id = "";
+ _users.InsertOne(u);
+ return _jwt.GenGuestToken(u._id);
+
}
diff --git a/backend/api/api/Services/IAuthService.cs b/backend/api/api/Services/IAuthService.cs
index 9a109208..4ed9a761 100644
--- a/backend/api/api/Services/IAuthService.cs
+++ b/backend/api/api/Services/IAuthService.cs
@@ -8,5 +8,6 @@ namespace api.Services
string Register(RegisterRequest user);
string RenewToken(string token);
public string GuestToken();
+ public void RegisterGuest();
}
} \ No newline at end of file