Skip to content

Commit 5a550b4

Browse files
committed
Merge branch 'firebase-authentication'
2 parents 36cfdd9 + a6b825f commit 5a550b4

13 files changed

Lines changed: 104 additions & 212 deletions

File tree

RequestTests.paw

-424 Bytes
Binary file not shown.

src/SimpleToDoService/Common/Common.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
namespace SimpleToDoService
33
{
4-
class EmailExistedException : Exception { }
5-
64
public class ServiceError
75
{
86
public string Message { get; set; }

src/SimpleToDoService/Controllers/RootController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
32

43
namespace SimpleToDoService
54
{

src/SimpleToDoService/Controllers/TasksController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Security.Claims;
5+
using Microsoft.AspNetCore.Authorization;
46
using Microsoft.AspNetCore.Mvc;
57
using SimpleToDoService.Entities;
68
using SimpleToDoService.Middleware;
79
using SimpleToDoService.Repository;
810

911
namespace SimpleToDoService
1012
{
11-
[MiddlewareFilter(typeof(BasicAuthMiddleware))]
13+
[Authorize]
14+
[MiddlewareFilter(typeof(CheckUserMiddleware))]
1215
[Route("api/v1/[controller]")]
1316
public class TasksController : Controller
1417
{
@@ -19,6 +22,11 @@ public Guid CurrentUserUuid
1922
get { return (Guid)HttpContext.Items["UserUuid"]; }
2023
}
2124

25+
public string CurrentUserFirebaseId
26+
{
27+
get { return HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value; }
28+
}
29+
2230
public TasksController(IToDoRepository repository)
2331
{
2432
this.repository = repository;
@@ -28,7 +36,7 @@ public TasksController(IToDoRepository repository)
2836
public IEnumerable<Task> Get(Guid? uuid)
2937
{
3038
var entries = repository.Tasks(CurrentUserUuid).OrderBy(o => o.CreationDate).Where(o => !o.Completed);
31-
39+
3240
if (uuid != null)
3341
entries = entries.Where(o => o.Uuid == uuid);
3442

src/SimpleToDoService/Controllers/UserController.cs

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/SimpleToDoService/Database/Entities.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public class User
1515
[Required]
1616
public Guid Uuid { get; set; }
1717

18+
[Column("firebaseid")]
19+
[XmlIgnore]
20+
[JsonIgnore]
21+
[IgnoreDataMember]
22+
public string FirebaseId { get; set; }
23+
1824
[MaxLength(255)]
1925
[Column("firstname")]
2026
[Required]
@@ -30,14 +36,6 @@ public class User
3036
[Required]
3137
public string Email { get; set; }
3238

33-
[MaxLength(255)]
34-
[Column("password")]
35-
[Required]
36-
//[XmlIgnore]
37-
//[JsonIgnore]
38-
//[IgnoreDataMember]
39-
public string Password { get; set; }
40-
4139
[XmlIgnore]
4240
[JsonIgnore]
4341
[IgnoreDataMember]

src/SimpleToDoService/Database/Repositiory.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,12 @@ public bool DeleteTask(Guid uuid)
9191

9292
public User CreateUser(User user)
9393
{
94-
if (Users().Where(o => o.Email == user.Email).Count() > 0)
95-
throw new EmailExistedException();
96-
9794
user.Uuid = new Guid();
9895
user.CreationDate = DateTime.Now.ToUniversalTime();
9996
var entity = context.Users.Add(user);
10097

101-
if (context.SaveChanges() == 1)
102-
return entity.Entity;
103-
104-
return null;
98+
context.SaveChanges();
99+
return entity.Entity;
105100
}
106101

107102
public bool DeleteUser(User user)

src/SimpleToDoService/DbScripts/CreateTables.sql

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/SimpleToDoService/DbScripts/CreateUser.sql

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/SimpleToDoService/Middleware/BasicAuthMiddleware.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)