Exemplo n.º 1
0
        public async Task <EmailTempModel> GetTempEmailModelById(Guid modelId)
        {
            try
            {
                var findId = modelId.ToString();
                var found  = await _emailTempData.GetTempEmailById(findId);

                var item = found.FirstOrDefault();
                if (item == null)
                {
                    return(null);
                }

                var emailModel = new EmailTempModel
                {
                    Id              = modelId,
                    Email           = item.Email,
                    CreatedDate     = item.CreatedDate,
                    VerificationKey = item.VerificationKey
                };
                return(emailModel);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public async Task <EmailTempModel> GetTempEmailModelByEmail(string email)
        {
            try
            {
                var found = await _emailTempData.GetTempEmailByEmail(email);

                var item = found.FirstOrDefault();
                if (item == null)
                {
                    return(null);
                }

                var emailModel = new EmailTempModel
                {
                    Id              = Guid.Parse(item.Id),
                    Email           = email,
                    CreatedDate     = item.CreatedDate,
                    VerificationKey = item.VerificationKey
                };
                return(emailModel);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public async Task <List <EmailTempModel> > GetTempEmailModels()
        {
            try
            {
                var found = await _emailTempData.GetTempEmails();

                if (found == null)
                {
                    return(null);
                }

                var emails = new List <EmailTempModel>();
                foreach (var e in found)
                {
                    var email = new EmailTempModel
                    {
                        Id              = Guid.Parse(e.Id),
                        Email           = e.Email,
                        CreatedDate     = e.CreatedDate,
                        VerificationKey = e.VerificationKey
                    };
                    emails.Add(email);
                }
                return(emails);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([FromBody] CreateEmailModelRequest request)
        {
            // TODO - fix issue, when trying to imput an email that already exists in the database, it throws an exception
            var emailModel = new EmailTempModel
            {
                Id              = Guid.NewGuid(),
                Email           = request.Email,
                CreatedDate     = request.CreatedDate,
                VerificationKey = Guid.NewGuid().ToString() //Convert.ToBase64String(Guid.NewGuid().ToByteArray())
            };

            var created = await _emailTempDataService.CreateTempEmailModel(emailModel);

            if (created == false)
            {
                return(BadRequest());
            }

            // TODO - here the server should send a confirmation email
            var verificationMessage = _emailSendingService.GenerateVerificationEmail(emailModel.Email, emailModel.VerificationKey);

            /*
             * var recipients = new List<EmailModel>
             * {
             *  new EmailModel
             *  {
             *      Id = emailModel.Id,
             *      Email = emailModel.Email,
             *      CreatedDate = emailModel.CreatedDate
             *  }
             * };
             */

            _emailSendingService.SendMail(verificationMessage, "E-pasta verifikācija", true, emailModel.Email); //recipients
            // end of send

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" + ApiRoutes.VerificationEmailClientData.Get.Replace("{modelId}", emailModel.Id.ToString());

            var response = new EmailModelResponse {
                Id = emailModel.Id
            };

            return(Created(locationUri, response));
        }
Exemplo n.º 5
0
        public async Task <bool> CreateTempEmailModel(EmailTempModel emailModel)
        {
            try
            {
                var existingtemp = await _emailTempData.GetTempEmailByEmail(emailModel.Email);

                var itemtemp = existingtemp.FirstOrDefault();
                if (itemtemp != null)
                {
                    return(false);
                }

                var existing = await _emailData.GetEmailByEmail(emailModel.Email);

                var item = existing.FirstOrDefault();
                if (item != null)
                {
                    return(false);
                }

                var saveEmailModel = new DbEmailTempModel
                {
                    Id              = emailModel.Id.ToString(),
                    Email           = emailModel.Email,
                    CreatedDate     = emailModel.CreatedDate,
                    VerificationKey = emailModel.VerificationKey
                };

                await _emailTempData.SaveTempEmail(saveEmailModel);

                return(true);
            }
            catch
            {
                return(false);
            }
        }