public async Task <RemotingResult <string> > CreateScanJoinCodeAsync(Guid id, Guid userId)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentException("must not be empty", nameof(id));
            }
            if (userId == Guid.Empty)
            {
                throw new ArgumentException("must not be empty", nameof(userId));
            }

            var createdBy = Guid.Empty;

            using (var db = new ServiceDbContext(_dbOptions))
            {
                var query = from entity in db.Groups
                            where entity.Id == id && entity.Type == GroupType.CustomChat
                            select entity.CreatedBy;
                createdBy = await query.FirstOrDefaultAsync();

                if (createdBy == Guid.Empty)
                {
                    return(RemotingResult <string> .Fail(1));
                }
                if (createdBy != userId)
                {
                    return(RemotingResult <string> .Fail(2));
                }
            }
            var fingerprint = Guid.NewGuid().ToString("N");
            await _simpleKeyValueService.AddOrUpdate(SKVContainer_ScanJoinCode,
                                                     id.ToString("N"), fingerprint);

            return(RemotingResult <string> .Success(id.ToString("N") + "," + fingerprint));
        }
        public async Task <IActionResult> GetAsync([Required] string connectionId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("connectionId is null"));
            }

            if (User.Identity.IsAuthenticated)
            {
                var userId   = User.GetSubId();
                var userName = User.GetUserName();
                if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(userName))
                {
                    var tmpPwd = Guid.NewGuid().ToString();
                    await _simpleKeyValueService.AddOrUpdate(StsConstants.TempPasswordContainerName, userId, tmpPwd);

                    var notifyAppService = _remotingClient.CreateScanLoginNotifyAppService();
                    await notifyAppService.NotifyAsync(connectionId, userName, tmpPwd);

                    return(Ok(userName));
                }
                return(BadRequest("userId or userName is null"));
            }
            return(Unauthorized());
        }
        public async Task <string> SendAsync(string phoneNumber)
        {
            var code = (new Random().Next(1000, 9999)).ToString();

            await _simpleKeyValueService.AddOrUpdate(
                SimpleKeyValueServiceContainerName, phoneNumber, code);

            await _bus.Send <SendMobileCodeCommand>(new
            {
                PhoneNumbers = new string[] { phoneNumber },
                Code         = code,
            });

            return(code);
        }
Beispiel #4
0
        public async Task <ActionResult <string> > GetAsync()
        {
            if (User.Identity.IsAuthenticated)
            {
                var userId = User.GetSubId();
                if (!string.IsNullOrEmpty(userId))
                {
                    var tmpPwd = Guid.NewGuid().ToString();
                    await _simpleKeyValueService.AddOrUpdate(StsConstants.TempPasswordContainerName, userId, tmpPwd);

                    return(tmpPwd);
                }
                return(BadRequest("userId is null"));
            }
            return(Unauthorized());
        }