Exemple #1
0
        public async Task <UserCreateClientModel> UserCreateClient(string userId, UserCreateClientBindingModel model)
        {
            var newClient = new Domain.Entity.Client
            {
                Id                   = ObjectId.GenerateNewId().ToString(),
                Active               = true,
                ApplicationType      = GetApplicationTypeEnum(model.ApplicationType),
                UserId               = userId,
                AllowedOrigin        = "*",
                RefreshTokenLifeTime = 10080
            };
            var result = new UserCreateClientModel
            {
                Id      = newClient.Id,
                Message = "client_id: " + newClient.Id
            };

            if (model.ApplicationType.ToUpper().Equals("JAVA SCRIPT"))
            {
                if (string.IsNullOrEmpty(model.AllowedOrigin) || model.AllowedOrigin.Equals("*"))
                {
                    CustomException.ThrowBadRequestException("Provide AllowedOrigin for cors support");
                }

                var secret = GenerateClientSecret();
                newClient.Secret        = GetHash(secret);
                newClient.AllowedOrigin = model.AllowedOrigin;
                result.Message         += Environment.NewLine + "client_secret: " + secret;
            }

            await Context.GetClientCollection().InsertOneAsync(newClient);

            return(result);
        }
Exemple #2
0
        public virtual MailLogDTO SendMail(Domain.Entity.Client currentClient, MailModel entity, object param)
        {
            List <string>   recipients = new List <string>();
            List <Document> documents  = new List <Document>();
            MailLog         mailLog;

            ValidateNull(entity);
            if (!validation.PreValidatePost(validationDictionnary, currentClient, entity, param, repo, recipients, documents))
            {
                throw new ManahostValidationException(validationDictionnary);
            }
            IHomeRepository homeRepo   = ((MailController.AdditionalRepositories)param).HomeRepo;
            MailConfig      mailconfig = repo.GetMailConfigById(entity.MailConfigId, currentClient.Id);

            Mailling.SendMailBcc(new InfosMailling(mailconfig.Smtp, (int)mailconfig.SmtpPort, mailconfig.Email, homeRepo.GetHomeById(mailconfig.HomeId, currentClient.Id).Title,
                                                   Encoding.UTF8.GetString(Convert.FromBase64String(entity.Password)))
            {
                body        = entity.Body,
                prio        = System.Net.Mail.MailPriority.Normal,
                subject     = entity.Subject,
                toPeople    = recipients,
                ssl         = (bool)mailconfig.IsSSL,
                attachments = MailUtils.GetAttachments(documents, mailconfig.Home)
            }, mailLog = new MailLog()
            {
                DateSended = DateTime.UtcNow,
                To         = String.Join(",", recipients.ToArray()),
                Successful = true,
                HomeId     = mailconfig.HomeId
            });
            repo.Add <MailLog>(mailLog);
            return(GetMapper.Map <MailLog, MailLogDTO>(mailLog));
        }