Example #1
0
        public async Task <bool> SendRegistrationEmail(RegistrationEmail registrationEmail)
        {
            try
            {
                using (httpClient)
                {
                    StringContent content = CreateEmailJsonObject(registrationEmail);

                    var emailResponse = await httpClient.PostAsync("accounts/registrationemail", content);

                    if (!emailResponse.IsSuccessStatusCode)
                    {
                        var responseContent = await emailResponse.Content.ReadAsStringAsync();

                        logger.LogWarning(string.Format("Error in Sending RegistrationEmail. Reason: {0}. Response Content: {1}",
                                                        emailResponse.ReasonPhrase, responseContent));
                        return(false);
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                logger.LogError(string.Format("Error in EmailProvider - SendRegistrationEmail. {0}", ex.Message));
                return(false);
            }
        }
Example #2
0
        public void SendRegistrationEmail(string recipient, string toAddress)
        {
            var email = new RegistrationEmail(recipient, toAddress).GetMailMessage();

            try
            {
                Console.WriteLine("Sending registration confirmation email - please wait...");
                _smtpClient.Send(email);
                Console.WriteLine("Registration email sent successfully.");
            }
            catch (Exception e)
            {
                Console.WriteLine($"An error occurred while sending the registration email: {e.Message}");
            }
        }
Example #3
0
        private async Task GenerateEmailAsync(User user, ReturnUrlRequest?returnUrl, CancellationToken token)
        {
            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            code = UrlEncoder.Default.Encode(code);
            var url = returnUrl?.Url;

            if (!Url.IsLocalUrl(url))
            {
                url = null;
            }
            TempData[EmailTime] = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);

            var link = Url.Link("ConfirmEmail", new { user.Id, code, returnUrl = url, referral = TempData[HomeController.Referral] });

            TempData[Email] = user.Email;
            var message = new RegistrationEmail(user.Email, HtmlEncoder.Default.Encode(link), CultureInfo.CurrentUICulture);
            await _queueProvider.InsertMessageAsync(message, token);
        }
Example #4
0
        public ActionResult Index(HomeViewModel model)
        {
            try
            {
                //Generating account number.
                string newAccountNumber = GetAccountNumber();

                if (!ModelState.IsValid)
                {
                    model.ResultMessage = "Hiba Történt!";
                    return(View(model));
                }
                //Generating token for registry with GUID.
                var token = Guid.NewGuid();

                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    // Token data with 1 hour expiry.
                    var newToken = new TokenManager
                    {
                        TokenKey    = token.ToString(),
                        TokenIssued = DateTime.Now,
                        TokenExpiry = DateTime.Now.AddHours(1),
                        IsActive    = true
                    };

                    //Creating new Account.
                    var newAccountRequest = new CurrentAccount
                    {
                        AccountNumber        = newAccountNumber,
                        Balance              = 0,
                        EmailAddress         = model.To,
                        TokenManagerTokenKey = token.ToString()
                    };

                    // adding new user to database
                    db.CurrentAccount.Add(newAccountRequest);

                    // adding token to database
                    db.TokenManager.Add(newToken);

                    db.SaveChanges();
                    transaction.Commit();
                }

                // URI address for the user to click on, in the sent email.
                Uri uriAddress = RegistrationEmail.GetActivationUri(token.ToString());

                // Using the data configured in the webconfig for sending Mail.
                var sendMail     = new MailAddress(WebConfigurationManager.AppSettings[RegistrationEmail.SmtpUser], WebConfigurationManager.AppSettings[RegistrationEmail.SmtpUserDisplayName]);
                var receiverMail = new MailAddress(model.To);
                var password     = WebConfigurationManager.AppSettings[RegistrationEmail.SmtpPassword];
                var subject      = RegistrationEmail.Subject;
                var body         = RegistrationEmail.GetBodyContent(model.Name, uriAddress.ToString(), newAccountNumber);

                // Creating new SMTP client, if necessary change data accordingly in webconfig.
                using (var smtp = new SmtpClient
                {
                    Host = WebConfigurationManager.AppSettings[RegistrationEmail.SmtpServer],
                    Port = Convert.ToInt32(WebConfigurationManager.AppSettings[RegistrationEmail.SmtpPort]),
                    EnableSsl = Convert.ToBoolean(WebConfigurationManager.AppSettings[RegistrationEmail.SmtpSSL]),
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(sendMail.Address, password)
                })
                {
                    var mailMessage = new MailMessage(sendMail.ToString(), model.To)
                    {
                        Subject = subject,
                        Body    = body
                    };

                    smtp.Send(mailMessage);
                    model.ResultMessage = "Email kiküldve!";
                }

                return(View(model));
            }
            catch
            {
                //Catching Exception and displaying error Message.

                model.ResultMessage = "Hiba Történt!";
                return(View(model));
            }
        }
Example #5
0
        private void CreateCustomer()
        {
            Console.WriteLine("Enter your First Name");
            var firstName = Console.ReadLine();

            Console.WriteLine("Enter your Last Name");
            var lastName = Console.ReadLine();

            Console.WriteLine("Enter your Email");
            var email = Console.ReadLine();

            while (!email.Contains("@"))
            {
                Console.WriteLine("Email is not valid. Enter a valid email.");
                email = Console.ReadLine();
            }
            while (_customerRepository.GetCustomerEmail(email))
            {
                Console.WriteLine("This email already exists. Enter a non existing email.");
                email = Console.ReadLine();
            }

            Console.WriteLine("Enter your User Name");
            var userName = Console.ReadLine();

            while (userName != userName.ToLower())
            {
                Console.WriteLine("User name should be in lower cases");
                userName = Console.ReadLine();
            }

            Console.WriteLine("Enter your date of birth \n Year");
            var year = int.Parse(Console.ReadLine());

            Console.WriteLine("Month");
            var month = int.Parse(Console.ReadLine());

            Console.WriteLine("Day");
            var day = int.Parse(Console.ReadLine());


            while (!DateOfBirth.DateValidation(day, month, year))
            {
                Console.WriteLine("Date of brth is not correct");
                Console.WriteLine("Year");
                year = int.Parse(Console.ReadLine());
                Console.WriteLine("Month");
                month = int.Parse(Console.ReadLine());
                Console.WriteLine("Day");
                day = int.Parse(Console.ReadLine());
            }

            var      date        = $"{year}/{month}/{day}";
            DateTime dateOfBirth = Convert.ToDateTime(date);

            string password;
            string password1;

            Console.WriteLine("Create a password");
            password = Console.ReadLine();
            var regex = new Regex(@"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{12,}$");

            while (!regex.Match(password).Success)
            {
                Console.WriteLine("Password is not according to standards. Create a password");
                password = Console.ReadLine();
            }

            do
            {
                Console.WriteLine("Repeat your password");
                password1 = Console.ReadLine();

                if (password != password1)
                {
                    Console.WriteLine("Passowrd does not match");
                }
            } while (password != password1);

            customer         = _customerService.CreateCustomer(firstName, lastName, email, userName, password, dateOfBirth.Date);
            _isAuthenticated = true;


            Console.WriteLine("You registered successfuly.");

            RegistrationEmail.SendRegistrationEmail(email);
        }