Exemplo n.º 1
0
        public async Task CreateQrCode()
        {
            var user   = fillTestDbHelper.Users.FirstOrDefault();
            var qrCode = await codesService.CreateQRCodeAsync(user.Id, 1);

            Assert.True(!string.IsNullOrEmpty(qrCode.Sequence) && qrCode.UserId == user.Id);
        }
Exemplo n.º 2
0
        public async Task <Response> CreateResponseAsync()
        {
            try
            {
                var qrCode = await qrCodesService.CreateQRCodeAsync(clientConnection.UserId.Value, NodeSettings.Configs.Node.Id).ConfigureAwait(false);

                return(new QRCodeResponse(request.RequestId, qrCode));
            }
            catch (ObjectDoesNotExistsException ex)
            {
                return(new ResultResponse(request.RequestId, ex.Message, ErrorCode.ObjectDoesNotExists));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetQRCode([FromQuery] long userId)
        {
            Dictionary <string, string> errors = new Dictionary <string, string>();
            var user = await _loadUsersService.GetUserAsync(userId).ConfigureAwait(false);

            if (user == null)
            {
                errors.Add("userId", $"The user with the specified identifier was not found. ({nameof(userId)} : {userId})");
            }
            if (errors.Any())
            {
                return(new JsonResult(errors));
            }
            var qrCodeAuthData = await _qrCodesService.CreateQRCodeAsync(userId, NodeSettings.Configs.Node.Id).ConfigureAwait(false);

            QRCodeGenerator qrCodeGenerator = new QRCodeGenerator();
            QRCodeData      qrCodeData      = qrCodeGenerator.CreateQrCode(qrCodeAuthData.ToJson(), QRCodeGenerator.ECCLevel.Q);
            QRCode          qRCode          = new QRCode(qrCodeData);
            Bitmap          bitmap          = new Bitmap("wwwroot/lock-black-256.png");
            var             imageData       = qRCode.GetGraphic(10, System.Drawing.Color.Black, System.Drawing.Color.White, bitmap);
            string          imageTempName   = $"{Guid.NewGuid().ToString()}.png";
            var             newImage        = new Bitmap(imageData.Width, imageData.Height + 100);
            Graphics        graphics        = Graphics.FromImage(newImage);
            SolidBrush      fillBrush       = new SolidBrush(System.Drawing.Color.White);

            graphics.FillRectangle(fillBrush, 0, 0, newImage.Width, newImage.Height);
            graphics.DrawImage(imageData, 0, 100, new Rectangle(0, 0, imageData.Width, imageData.Height), GraphicsUnit.Pixel);
            Font       drawFont  = new Font("Arial", 60);
            SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.Black);
            float      x         = newImage.Width / 2 - 200;
            float      y         = 50;

            graphics.DrawString("Sign in QR", drawFont, drawBrush, x, y);
            using (Stream stream = System.IO.File.OpenWrite(imageTempName))
            {
                newImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            }
            byte[] content = await System.IO.File.ReadAllBytesAsync(imageTempName);

            using (Stream stream = System.IO.File.OpenRead(imageTempName))
            {
                await _fileStorage.UploadAsync(stream, imageTempName);
            }
            System.IO.File.Delete(imageTempName);
            return(File(content, "image/png", imageTempName));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetQr([FromForm] long userId)
        {
            var qrCode = await _qrCodeService.CreateQRCodeAsync(userId, NodeSettings.Configs.Node.Id).ConfigureAwait(false);

            return(Json(qrCode));
        }