Пример #1
0
        public async Task <SendEmailVerificationResult> SendEmailVerification(SendEmailVerificationCommand config)
        {
            var webRoot    = _env.WebRootPath;
            var pathToFile = webRoot + "\\Template\\try.html";

            var builder = new BodyBuilder();

            using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
            {
                builder.HtmlBody = SourceReader.ReadToEnd();
            }

            var client      = new SendGridClient(config.ApiKey);
            var from        = new EmailAddress(config.SenderEmail, config.SenderName);
            var to          = new EmailAddress(config.ReceiverEmail, config.ReceiverName);
            var htmlContent = string.Format(builder.HtmlBody, config.Link);

            var msg = MailHelper.CreateSingleEmail(
                from,
                to,
                config.Subject,
                config.TextContent,
                htmlContent);

            msg.SetClickTracking(false, false);
            var response = await client.SendEmailAsync(msg);

            return(new SendEmailVerificationResult
            {
                Response = response
            });
        }
Пример #2
0
        public async Task <CreateAccountResult> CreateAccount(CreateAccountCommand creds)
        {
            var status = "";

            //Username Check
            if (UserExists(creds.Username).Result.Exists)
            {
                status = "Taken";
                return(new CreateAccountResult
                {
                    Status = status
                });
            }

            //Password Check
            if (creds.Password != creds.PasswordValidator)
            {
                status = "PasswordNotMatch";
                return(new CreateAccountResult
                {
                    Status = status
                });
            }

            var newUser = new AppUser
            {
                UserName  = creds.Username,
                FirstName = creds.FirstName,
                LastName  = creds.LastName,
                Email     = creds.Email,
                Role      = creds.Role
            };

            var result = await _userManager.CreateAsync(newUser, creds.Password);

            if (result.Succeeded)
            {
                var emailConfig = new SendEmailVerificationCommand
                {
                    Link          = CreateEmailVerificationToken(newUser).Link,
                    ApiKey        = GetValueInSection("EmailConfig", "SendGridApiKey"),
                    SenderEmail   = GetValueInSection("EmailConfig", "SenderEmail"),
                    SenderName    = GetValueInSection("EmailConfig", "SenderName"),
                    ReceiverEmail = newUser.Email,
                    ReceiverName  = newUser.FirstName,
                    Subject       = GetValueInSection("EmailVerification", "Subject")
                };

                var response = SendEmailVerification(emailConfig).Result.Response;
                status = "Success";

                return(new CreateAccountResult
                {
                    Status = status
                });
            }

            status = "Invalid";
            return(new CreateAccountResult
            {
                Status = status
            });
        }