public async Task Handle(CreateLocalMembership command) { // does user already exist? var hasUserId = command.Principal != null && command.Principal.Identity.HasAppUserId(); var user = hasUserId ? await _entities.GetAsync <User>(command.Principal.Identity.GetUserId <int>()) : null; if (!hasUserId) { var createUser = new CreateUser { Name = command.UserName }; await _commands.Execute(createUser); user = createUser.CreatedEntity; // verify & associate email address await _commands.Execute(new RedeemEmailVerification(user) { Commit = false, Token = command.Token, Ticket = command.Ticket, }); } user.LocalMembership = new LocalMembership { User = user, PasswordHash = await _queries.Execute(new HashedPassword(command.Password)), }; user.SecurityStamp = Guid.NewGuid().ToString(); await _entities.SaveChangesAsync(); command.CreatedEntity = user.LocalMembership; }
public async Task Handle(ChangeUserName command) { var entity = await _entities.GetAsync <User>(command.UserId); entity.Name = command.UserName; entity.SecurityStamp = Guid.NewGuid().ToString(); await _entities.SaveChangesAsync(); await _authenticator.SignOut(); await _authenticator.SignOn(entity); command.SignedIn = entity; }
public async Task Handle(DeleteEmailAddress command) { // load up the entity var entity = await _entities.GetAsync <EmailAddress>(command.EmailAddressId); // delete if it is verified if (entity.IsVerified) { _entities.Delete(entity); } // when it is unverified, just detach from user else { entity.UserId = null; } await _entities.SaveChangesAsync(); }