protected async void RecoverMyPassword(object sender, EventArgs e)
        {
            string PasswordVerficationUrl = $"https://{Request.Url.Host}:{Request.Url.Port}/Views/Accounts/ChangePasswordVerification";
            string ErrorMessage           = string.Empty;

            if (string.IsNullOrWhiteSpace(EmailEnter.Text))
            {
                Account account = accountSql.Get(UsernameEnter.Text);
                if (account != null)
                {
                    if (await emailTool.SendEmail(account, "Password Change Request", "",
                                                  $"Hello {account.FirstName}, <br> your karbon password change token is {passwordRecoveryToken} <br> {PasswordVerficationUrl}"))
                    {
                        Debug.WriteLine("Email was sent to user email address.");
                        Session["Success"] = "Please check your email address for Password Recovery";
                        Response.Redirect("~/Views/Accounts/Login", false);
                    }
                    else
                    {
                        Debug.WriteLine("Email FAILED to send");
                        ErrorMessage += $"Email FAILED to send {LineBreak}";
                        Response.Redirect("~/Views/Accounts/Login", false);
                    }
                }
                else
                {
                    Debug.WriteLine($"Account with the username {UsernameEnter.Text} does not exist");
                    ErrorMessage += $"Account with the username {UsernameEnter.Text} does not exist {LineBreak}";
                }
            }
            else
            {
                Account account = accountSql.GetWithEmail(EmailEnter.Text);
                if (account != null)
                {
                    await emailTool.SendEmail(account, "Password Recovery", "", $"Hello {account.FirstName},\n" +
                                              $"you karbon password recovery token is is {passwordRecoveryToken} <br> {PasswordVerficationUrl}\n");

                    Debug.WriteLine("Email was sent to users email address.");
                    Response.Redirect("~/Views/Accounts/Login", false);
                }
                else
                {
                    Debug.WriteLine($"Account with the email {EmailEnter.Text} does not exist");
                    ErrorMessage += $"Account with the email {EmailEnter.Text} does not exist {LineBreak}";
                }
            }
            RecoveryPasswordError.Text = PreFormatError(ErrorMessage);
        }
        protected async void RecoverMyUsername(object sender, EventArgs e)
        {
            string  ErrorMessage = string.Empty;
            Account account      = accountSql.GetWithEmail(EmailEnter.Text);

            if (account != null)
            {
                if (await email.SendEmail(account, "Username Recovery", $"Hello {account.FirstName},\n" +
                                          $"you karbon username is {account.Username}.\n"))
                {
                    Debug.WriteLine("Email was sent to user email address.");
                    Session["Success"] = "Please check your email address for Username Recovery";
                    Response.Redirect("~/Views/Accounts/Login", false);
                }
                else
                {
                    Debug.WriteLine("Email FAILED to send");
                    ErrorMessage += $"Email FAILED to send {LineBreak}";
                }
            }
            else
            {
                Debug.WriteLine($"Account with the email {EmailEnter.Text} does not exist");
                ErrorMessage += $"Account with the email {EmailEnter.Text} does not exist {LineBreak}";
            }
            RecoveryUsernameError.Text = PreFormatError(ErrorMessage);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            EmailTool emailTool = new EmailTool();
            Account   account   = new Account("username", "*****@*****.**", "fname", "lname", "password", "");

            emailTool.SendEmail(account, "test", "test1234").Wait();
        }
コード例 #4
0
        protected async void CreateAccount(object sender, EventArgs e)
        {
            string CreateVerficationUrl = $"https://{Request.Url.Host}:{Request.Url.Port}/Views/Accounts/Verification";
            string ErrorMessage         = string.Empty;

            if (IsValidName(FirstName.Text))
            {
                ErrorMessage += $"First Name should only contain characters {LineBreak}";
            }
            if (IsValidName(LastName.Text))
            {
                ErrorMessage += $"Last Name should only contain characters {LineBreak}";
            }
            if (IsValidUsername(Username.Text))
            {
                ErrorMessage += $"Invalid Username format {LineBreak}";
            }
            if (IsValidEmail(Email.Text))
            {
                ErrorMessage += $"Invalid Email Format {LineBreak}";
            }
            if (IsValidPassword(Password.Text))
            {
                ErrorMessage += $"Invalid Password Format {LineBreak}";
            }
            if (Password.Text == ConfirmPassword.Text && string.IsNullOrEmpty(ErrorMessage))
            {
                Account account = new Account
                {
                    Username  = Username.Text,
                    Email     = Email.Text,
                    FirstName = FirstName.Text,
                    LastName  = LastName.Text,
                    Password  = Password.Text,
                    Skills    = "false" //Not Verified
                };
                if (await emailTool.SendEmail(account, "Account Verification", "",
                                              $"Hello {account.FirstName}, <br> your karbon activation token is {verfToken} <br> {CreateVerficationUrl}"))
                {
                    accountSql.Insert(account);
                    Debug.WriteLine("Verfication Token successfully sent and account added.");
                    Session["Success"] = "Create Account Successful";
                    Response.Redirect("~/Views/Accounts/Login", false);
                }
                else
                {
                    CreateError.Text += "Error: unable to send email";
                    Debug.WriteLine("Error: unable to send email");
                }
            }
            else
            {
                CreateError.Text += "Error: passwords did not match.";
                Debug.WriteLine("Error: passwords did not match");
            }
            CreateError.Text = PreFormatError(ErrorMessage);
        }