PageRenderTime 28ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms 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
 1using System;
 2using Bifrost.Domain;
 3using Bifrost.Samples.Blog.Events.Security;
 4
 5namespace Bifrost.Samples.Blog.Domain.Security
 6{
 7    public class User : AggregatedRoot
 8    {
 9        string _password;
10
11        public User(Guid id) : base(id)
12        {
13        }
14
15
16        public void Create(string userName)
17        {
18            Apply(new UserCreated(Id, userName, string.Empty));
19            SetUserName(userName);
20        }
21
22        public void SetPassword(string password)
23        {
24            Apply(new PasswordSet(Id, password));
25        }
26
27        public void Login()
28        {
29            Apply(new LoginSuccessful(Id));
30        }
31        
32
33        private void SetUserName(string userName)
34        {
35            Apply(new UserNameSet(Id, userName));
36        }
37
38        public void Handle(PasswordSet passwordSet)
39        {
40            _password = passwordSet.Password;
41        }
42
43        public void Handle(UserCreated userCreated)
44        {
45            _password = userCreated.Password;
46        }
47
48        public void Handle(UserNameSet userNameSet) {}
49        public void Handle(LoginSuccessful loginSuccessful) {}
50        public void Handle(LoginAttemptedWithWrongPassword loginAttemptedWithWrongPassword) {}
51    }
52}