PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Samples/Blog/Bifrost.Samples.Blog.Domain/Security/User.cs

#
C# | 52 lines | 41 code | 11 blank | 0 comment | 0 complexity | fa4b5316e5d12288caaae627f893ac7d MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using Bifrost.Domain;
  3. using Bifrost.Samples.Blog.Events.Security;
  4. namespace Bifrost.Samples.Blog.Domain.Security
  5. {
  6. public class User : AggregatedRoot
  7. {
  8. string _password;
  9. public User(Guid id) : base(id)
  10. {
  11. }
  12. public void Create(string userName)
  13. {
  14. Apply(new UserCreated(Id, userName, string.Empty));
  15. SetUserName(userName);
  16. }
  17. public void SetPassword(string password)
  18. {
  19. Apply(new PasswordSet(Id, password));
  20. }
  21. public void Login()
  22. {
  23. Apply(new LoginSuccessful(Id));
  24. }
  25. private void SetUserName(string userName)
  26. {
  27. Apply(new UserNameSet(Id, userName));
  28. }
  29. public void Handle(PasswordSet passwordSet)
  30. {
  31. _password = passwordSet.Password;
  32. }
  33. public void Handle(UserCreated userCreated)
  34. {
  35. _password = userCreated.Password;
  36. }
  37. public void Handle(UserNameSet userNameSet) {}
  38. public void Handle(LoginSuccessful loginSuccessful) {}
  39. public void Handle(LoginAttemptedWithWrongPassword loginAttemptedWithWrongPassword) {}
  40. }
  41. }