Example #1
0
        public void Run()
        {
            var user = UserStore.CreateUser(userName, password, email).Result;

            UserStore.EnsurePermissionsForUser(user, new HashSet <Permission> {
                Permission.ManageAnyUser
            }).Wait();
            Log.Info($"Created user {user} with the ManageAnyUser permission");
        }
        private async Task <WhatsappResponse> ProcessUnauthenticatedMessage(UserInfo userInfo, WhatsappMessage message)
        {
            string responseMessage;

            object[] pars = { userInfo.Name };

            string messageBody = message.MessageContent;
            string mediaUrl    = null;

            switch (userInfo.ConversationState)
            {
            case ConversationState.New:
                await _userStore.CreateUser(userInfo.PhoneNumber, null, ConversationState.AwaitingName);

                responseMessage = "Welkom bij deze app, wat is uw naam, aub?";
                break;

            case ConversationState.AwaitingName:
                userInfo.Name = messageBody;
                userInfo.ConversationState = ConversationState.AwaitingActivation;
                pars = new object[] { userInfo.Name };
                await _userStore.UpdateUser(userInfo);

                responseMessage =
                    "Welkom, {0}, als je een client wil connecteren, gelieve dan de activatiecode te sturen.  Die kan je bekomen door de eerste letters te nemen van de icoontjes op het scherm van de box.  In het voorbeeld is het bijvoorbeeld HOME";
                mediaUrl = "https://codithtc.blob.core.windows.net/public/media/example.png";
                break;

            case ConversationState.AwaitingActivation:
                responseMessage = await HandleBoxActivation(userInfo, messageBody);

                break;

            case ConversationState.Completed:
                _logger.LogWarning(
                    "User {phoneNumber} ended up in the unauthenticated conversation part, although the conversation state was completed",
                    userInfo.PhoneNumber);
                responseMessage =
                    "Normaal mag je nu gewoon foto's en berichten beginnen sturen en mag je dit niet meer krijgen";
                break;

            default:
                _logger.LogWarning(
                    "User {phoneNumber} ended up in the unauthenticated conversation part, although the conversation state was completed",
                    userInfo.PhoneNumber);
                responseMessage = "We konden uw bericht niet correct interpreteren.  Gelieve opnieuw te proberen";
                break;
            }

            return(new WhatsappResponse
            {
                ResponseMessage = (await _messageTranslater.Translate(userInfo.GetLanguage(), responseMessage, pars)),
                ImageUrl = mediaUrl,
                Accepted = true
            });
        }
Example #3
0
        public async Task <WikiUser> GetOrCreateUser(GoogleJsonWebSignature.Payload payload)
        {
            var user = await _userStore.GetUser(payload);

            if (user == null)
            {
                return(await _userStore.CreateUser(payload));
            }

            return(user);
        }
Example #4
0
        public async Task CreateNewUser_Should_Succeed()
        {
            string username = "******";
            string password = "******";
            string email    = "*****@*****.**";

            var user = await UserStore.GetUser(username);

            Assert.Null(user);
            var userId = await UserStore.CreateUser(username, password, email);

            user = await UserStore.GetUser(username);

            Assert.NotNull(user);
            Assert.Equal(user.Value.Username, username);
            Assert.Equal(user.Value.Email, email);
            Assert.NotEqual(user.Value.HashedPassword, password);
        }
Example #5
0
        public async Task <bool> Handle(CreateUserRequest message, IOutboundPort <NewUserResponse> outputPort)
        {
            // ensure username, email, are unused.
            if (await _userStore.GetUserByName(message.UserName) != null)
            {
                return(false);
            }

            // create a new entity instance.
            var user = _entityFactory.GetUserBuilder()
                       .AddName(message.UserName)
                       .AddEmail(message.Email)
                       .Build();

            var guid = await _userStore.CreateUser(user, message.Password);

            // use backing store to persist.
            NewUserResponse response = new NewUserResponse();

            response.Id = (guid == Guid.Empty) ? null : guid.ToString();

            outputPort.Handle(response);
            return(true);
        }