private void DoSendEmail(EmailLetter letter)
        {
            logger.Info("Sending a email message.");

            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("Рикард-Недвижимость", infoOptions.Value.Email.From));
            message.To.Add(new MailboxAddress(letter.To));
            message.Subject = letter.Subject;

            var bodyBuilder = new BodyBuilder();

            bodyBuilder.HtmlBody = letter.Body;
            message.Body         = bodyBuilder.ToMessageBody();

            using (var client = new SmtpClient())
            {
                client.Connect(infoOptions.Value.Email.SmtpAddress, infoOptions.Value.Email.SmtpPort, infoOptions.Value.Email.EnableSsl);
                client.AuthenticationMechanisms.Remove("XOAUTH2");
                client.Authenticate(infoOptions.Value.Email.Username, infoOptions.Value.Email.Password);
                client.Send(message);
                client.Disconnect(true);
            }

            logger.Info("A email message have been sent via smtp");
        }
Ejemplo n.º 2
0
        public AdvertsDatabaseService(IAspLogger logger, IMongoDbService mongoDbService, IOptions <AdvertsOptions> advertsOptions)
        {
            this.logger = logger;

            var databaseFactory = mongoDbService.GetDatabase();

            this.advertsDatabase = AdvertsDatabase.Init(databaseFactory, advertsOptions);
            this.advertsOptions  = advertsOptions;

            logger.Info("AdvertsDatabaseService has been initialized.");

            logger.Info($"Adverts directories: RootDirectory={advertsOptions.Value.RootDirectory}, NfsDirectory={advertsOptions.Value.NfsDirectory}, FilesDirectory={advertsOptions.Value.FilesDirectory}");
        }
        public MongoUserStore(IAspLogger logger, IMongoDbService mongoDbService)
        {
            this.logger = logger;

            users = mongoDbService.GetDatabase().MongoDatabase.GetCollection <T>(USERS_COLLECTION_NAME);

            if (!ManagedIndicies)
            {
                ManagedIndicies = true;

                users.Indexes.CreateOne(
                    Builders <T> .IndexKeys.Ascending(u => u.Name),
                    new CreateIndexOptions <T>
                {
                    Unique = true,
                    Sparse = false
                });
                users.Indexes.CreateOne(
                    Builders <T> .IndexKeys.Ascending(u => u.NormalizedName),
                    new CreateIndexOptions <T>
                {
                    Unique = true,
                    Sparse = false
                });
                users.Indexes.CreateOne(
                    Builders <T> .IndexKeys.Ascending(u => u.NormalizedEmail),
                    new CreateIndexOptions <T>
                {
                    Unique = true,
                    Sparse = false
                });
                users.Indexes.CreateOne(
                    Builders <T> .IndexKeys.Ascending(u => u.Roles), new CreateIndexOptions
                {
                    Sparse = true,
                });
                users.Indexes.CreateOne(
                    Builders <T> .IndexKeys.Combine(
                        Builders <T> .IndexKeys.Ascending(
                            new StringFieldDefinition <T>(
                                $"{nameof(IdentityUser.Logins)}.{nameof(PersistedUserLoginInfo.LoginProvider)}")),
                        Builders <T> .IndexKeys.Ascending(
                            new StringFieldDefinition <T>(
                                $"{nameof(IdentityUser.Logins)}.{nameof(PersistedUserLoginInfo.ProviderKey)}"))
                        )
                    );
                users.Indexes.CreateOne(
                    Builders <T> .IndexKeys.Combine(
                        Builders <T> .IndexKeys.Ascending(
                            new StringFieldDefinition <T>(
                                $"{nameof(IdentityUser.Claims)}.{nameof(PersistedClaim.Type)}")),
                        Builders <T> .IndexKeys.Ascending(
                            new StringFieldDefinition <T>(
                                $"{nameof(IdentityUser.Claims)}.{nameof(PersistedClaim.Value)}"))
                        )
                    );

                logger.Info("MongoUserStore has been initialized.");
            }
        }
        public async Task <IActionResult> Login(LoginModel customer, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;

            if (ModelState.IsValid)
            {
                var result = await signInManager.PasswordSignInAsync(customer.Email, customer.Password, true, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    logger.Info($"{customer.Email} is logged in");
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    var user = await userManager.FindByEmailAsync(customer.Email);

                    string error = null;
                    if (user != null)
                    {
                        if (!user.EmailConfirmed)
                        {
                            error = "Вам необходимо подтвердить Email указанный при регистрации, проверьте почту.";
                        }
                        else if (!user.PhoneNumberConfirmed)
                        {
                            return(RedirectToAction("ConfirmPhone", new { userId = user.Id }));
                        }
                    }
                    ModelState.AddModelError("", error ?? "Неверный Email или пароль.");
                }
            }

            return(View());
        }
        public SendEmailService(IAspLogger logger, IOptions <InfoOptions> infoOptions)
        {
            Worker = new ParallelGatherSingle <EmailLetter>(DoSendEmail);

            this.logger      = logger;
            this.infoOptions = infoOptions;

            logger.Info("SendEmailService is started");
        }
Ejemplo n.º 6
0
        public UsersService(IAspLogger logger, IMongoDbService mongoDbService)
        {
            this.logger = logger;

            users = mongoDbService.GetDatabase().MongoDatabase.GetCollection <T>(USERS_COLLECTION_NAME);

            worker = new ParallelGatherSingle <ProlongationPayment>(DoProlongationPayment);

            logger.Info("UsersService has been initialized.");
        }
Ejemplo n.º 7
0
        public NewsDatabaseService(IAspLogger logger, IMongoDbService mongoDbService)
        {
            this.logger = logger;

            var databaseFactory = mongoDbService.GetDatabase();

            this.newsDatabase = NewsDatabase.Init(databaseFactory);

            logger.Info("NewsDatabaseService has been initialized.");
        }
Ejemplo n.º 8
0
        public MongoDbService(IAspLogger logger, IOptions <DatabaseOptions> databaseOptions)
        {
            var mongoCredentials = new MongoDbCredentials(
                databaseOptions.Value.MongoDb.User,
                databaseOptions.Value.MongoDb.Password,
                databaseOptions.Value.MongoDb.Database,
                databaseOptions.Value.MongoDb.Host);

            this.databaseFactory = DatabaseFactory.Init(mongoCredentials);

            logger.Info("MongoDbService has been initialized.");
        }
Ejemplo n.º 9
0
        public SmsRuService(IAspLogger logger, IOptions <SmsRuOptions> options)
        {
            this.logger    = logger;
            this.login     = options.Value.Login;
            this.password  = options.Value.Password;
            this.apiId     = options.Value.ApiId;
            this.partnerId = options.Value.PartnerId;
            this.from      = options.Value.From;
            this.translit  = options.Value.Translit;
            this.test      = options.Value.Test;

            Worker = new ParallelGatherSingle <SmsMessage>(DoSendSms);

            logger.Info($"SmsRuService has been initialized.");
        }
Ejemplo n.º 10
0
        public MongoRoleStore(IAspLogger logger, IMongoDbService mongoDbService)
        {
            this.logger = logger;

            roles = mongoDbService.GetDatabase().MongoDatabase.GetCollection <IdentityRole>(ROLES_COLLECTION_NAME);

            if (!ManagedIndicies)
            {
                ManagedIndicies = true;

                roles.Indexes.CreateOne(
                    Builders <IdentityRole> .IndexKeys.Ascending(r => r.NormalizedName), new CreateIndexOptions
                {
                    Unique     = true,
                    Sparse     = false,
                    Background = true
                });

                logger.Info("MongoRoleStore has been initialized.");
            }
        }
Ejemplo n.º 11
0
        private void DoSendSms(SmsMessage sms)
        {
            logger.Info("Sending a sms message.");

            Task.Run(async() => await Send(sms.To, sms.Text)).GetAwaiter().GetResult();
        }