Esempio n. 1
0
 /// <summary>
 /// Signed in user may perform all basic operations related with his/her accounts.
 /// </summary>
 private bool SignedIn(object message)
 {
     return(base.ReceiveCommand(message) || message.Match()
            .With <UserCommands.ChangePassword>(change =>
     {
         if (ValidatePassword(State, change.OldPassword))
         {
             var passwordHash = HashPassword(change.NewPassword);
             Persist(new UserEvents.PasswordChanged(_id, passwordHash));
         }
         else
         {
             Log.Error("Unauthorized user sign in. User id: {0}", _id);
             Sender.Tell(Unauthorized.Message(change));
         }
     })
            .WasHandled);
 }
Esempio n. 2
0
 /// <summary>
 /// Initialized state represents actor which has entity already initialized,
 /// but following user has not logged in to his/her personal account.
 ///
 /// At this state allowed actions are sign in, resetting user password. User sign out is ignored.
 /// </summary>
 private bool Initialized(object message)
 {
     return(base.ReceiveCommand(message) || message.Match()
            .With <UserCommands.SignInUser>(signIn =>
     {
         if (string.Equals(State.Email, signIn.Email, StringComparison.InvariantCultureIgnoreCase) &&
             ValidatePassword(State, signIn.Password))
         {
             Persist(new UserEvents.UserSignedIn(_id), Sender);
         }
         else
         {
             Log.Error("Unauthorized user sign in. User id: {0}, email: {1}", _id, signIn.Email);
             Sender.Tell(Unauthorized.Message(signIn));
         }
     })
            .With <UserCommands.ResetPassword>(reset =>
     {
         //TODO: user reset password and mail sent
     })
            .With <UserCommands.SignOutUser>(_ => { /* ignore */ })
            .WasHandled);
 }