Ejemplo n.º 1
0
        private void SendVerificationEmail(MailAddress from, MailAddress to, string verificationCode)
        {
            //show progress bar
            string             status         = "Sending new verification code, please wait...";
            ProgressViewerForm progressViewer = new ProgressViewerForm(status);

            progressViewer.Location = new Point(this.Location.X - 55, this.Location.Y + 60);
            progressViewer.Show();
            _progressViewerObject = progressViewer;

            //email subject and body
            string subject = "Email Verification for MyCost";
            string message = "Dear User,\n\n" +
                             "Thank you for registering account with MyCost Finance Management App. " +
                             "Please use the following verification code to verify your email from MyCost app. \n\n" +
                             "Your email verification code is: " + verificationCode + ".\n\n" +
                             "Verifying your email is important because if you ever forget your password / username, " +
                             "you will not be able to recover your password / username without a verified email. \n\n" +
                             "Thank you\n" +
                             "MyCost Team";

            //send verification code to user's email
            Mailer mailer = new Mailer
            {
                From    = from,
                To      = to,
                Subject = subject,
                Message = message
            };

            mailer.EmailSendingSuccessEventHandler += OnSendingVerificationEmailSuccess;
            mailer.EmailSendingFailedEventHandler  += OnSendingVerificationEmailFailed;
            _mailerObject = mailer;
            mailer.SendEmail();
        }
Ejemplo n.º 2
0
        private void UpdateEmailButtonClicked(object sender, EventArgs e)
        {
            if (NewEmailTextBox.ForeColor != Color.Black || NewEmailTextBox.Text.Length < 1)
            {
                NewEmailTextBox.Text      = "New Email";
                NewEmailTextBox.ForeColor = Color.Red;
            }
            else if (PasswordForEmailTextBox.ForeColor != Color.Black || PasswordForEmailTextBox.Text.Length < 1)
            {
                PasswordForEmailTextBox.Text         = "Password";
                PasswordForEmailTextBox.ForeColor    = Color.Red;
                PasswordForEmailTextBox.PasswordChar = '\0';
            }
            else if (!IsValidEmail(NewEmailTextBox.Text))
            {
                NewEmailTextBox.ForeColor = Color.Red;

                string message = "Invalid Email. Please check your email address again.";

                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //disable all controls so that user cannot change anything
                //after the button is pressed
                DisableAllControls();

                string originalEmail         = NewEmailTextBox.Text;
                string emailVerificationCode = GenerateRandomNumberString(6);
                string password = PasswordForEmailTextBox.Text;

                //encrypt the email with the original cypher key
                string encryptedEmail = StringCipher.Encrypt(originalEmail, GlobalSpace.CypherKey);
                string encryptedEmergencyCypherKey = StringCipher.Encrypt(GlobalSpace.CypherKey, originalEmail);

                //show progress bar
                string             status         = "Updating your email, please wait...";
                ProgressViewerForm progressViewer = new ProgressViewerForm(status);
                progressViewer.Location = new Point(this.Location.X + 98, this.Location.Y + 200);
                progressViewer.Show();
                _progressViewerObject = progressViewer;

                //send webrequest to update email
                WebHandler webRequest = new WebHandler();
                webRequest.WebRequestSuccessEventHandler += OnUpdateEmailSuccess;
                webRequest.WebRequestFailedEventHandler  += OnUpdateEmailFailed;
                _webHandlerObject = webRequest;
                webRequest.UpdateEmail(originalEmail, encryptedEmail, emailVerificationCode, password, encryptedEmergencyCypherKey);
            }
        }
Ejemplo n.º 3
0
        private void VerifyEmailButtonClicked(object sender, EventArgs e)
        {
            //show progress bar
            string             status         = "Verifying your email, please wait...";
            ProgressViewerForm progressViewer = new ProgressViewerForm(status);

            progressViewer.Location = new Point(this.Location.X - 55, this.Location.Y + 60);
            progressViewer.Show();
            _progressViewerObject = progressViewer;

            WebHandler webHandler = new WebHandler();

            webHandler.WebRequestSuccessEventHandler += OnEmailVerificationSuccess;
            webHandler.WebRequestFailedEventHandler  += OnEmailVerificationFailed;
            _webHandlerObject = webHandler;
            webHandler.VerifyEmail(VerificationCodeTextBox.Text);
        }
Ejemplo n.º 4
0
        private void LoginUser()
        {
            //if fore-color of a textBox is not black, that means the textbox
            //contains the placeholder text and user didn't enter any value
            string username = UsernameTextBox.ForeColor == Color.Black?
                              UsernameTextBox.Text : "";
            string password = PasswordTextBox.ForeColor == Color.Black?
                              PasswordTextBox.Text : "";

            if (username.Length < 1)
            {
                ShowErrorMessage("Please enter username.");
                return;
            }
            else if (password.Length < 1)
            {
                ShowErrorMessage("Please enter password.");
                return;
            }

            //disable all controls so that the user cannot
            //change anything until the login process ends
            DisableAllControls();

            //show progress bar
            string             status         = "Verifying your login credentials, please wait...";
            ProgressViewerForm progressViewer = new ProgressViewerForm(status);

            progressViewer.Location = new Point(this.Location.X + 70, this.Location.Y + 100);
            progressViewer.Show();
            _progressViewerObject = progressViewer;

            //send web request to verify user's login credentials
            WebHandler webRequest = new WebHandler();

            webRequest.WebRequestSuccessEventHandler += OnLoginSuccess;
            webRequest.WebRequestFailedEventHandler  += OnLoginFailed;
            _webHandlerObject = webRequest;
            webRequest.AuthenticateUser(username, password);
        }
Ejemplo n.º 5
0
        private void RegisterUser()
        {
            //if fore-color of a textBox is not black, that means the TextBox
            //contains the placeholder text and user didn't enter any value
            string username = UsernameTextBox.ForeColor == Color.Black?
                              UsernameTextBox.Text : "";
            string password = PasswordTextBox.ForeColor == Color.Black?
                              PasswordTextBox.Text : "";
            string confirmPassword = ConfirmPasswordTextBox.ForeColor == Color.Black?
                                     ConfirmPasswordTextBox.Text : "";
            string email = EmailTextBox.ForeColor == Color.Black ? EmailTextBox.Text : "";
            string emailVerificationCode = GenerateRandomNumberString(6);


            //make server request to generate a new activation code
            //and assign the new activation code to the private variable _activationCode
            _activationCode = "";
            GetActivationCode();

            if (username.Length < 1)
            {
                ShowErrorMessage("Please enter a username.");
                return;
            }
            else if (password.Length < 1)
            {
                ShowErrorMessage("Please enter a password.");
                return;
            }
            else if (confirmPassword != password)
            {
                ShowErrorMessage("Password does not match.");
                return;
            }
            else if (_activationCode.Length < 1)
            {
                //error message is already shown when the call to get activation code failed
                return;
            }
            else if (email.Length < 1 || !IsValidEmail(email))
            {
                ShowErrorMessage("The email address you have provided is not vaild.");
                return;
            }
            else if (!AgreeCheckBox.Checked)
            {
                ShowErrorMessage("You need to agree to our terms and policy to register.");
                return;
            }

            //disable all controls so that the user cannot change
            //anything until the registration process ends
            DisableAllControls();

            //show progress bar
            string             status         = "Creating your account, please wait...";
            ProgressViewerForm progressViewer = new ProgressViewerForm(status);

            progressViewer.Location = new Point(this.Location.X + 70, this.Location.Y + 200);
            progressViewer.Show();
            _progressViewerObject = progressViewer;

            //generate a unique cypher key for this user for encrypting this user's info
            //save the encrypted version of the cypher key in database
            string cypherKey                   = GenerateRandomString(70);
            string encryptedCypherKey          = StringCipher.Encrypt(cypherKey, password);
            string encryptedEmergencyCypherKey = StringCipher.Encrypt(cypherKey, email);

            //encrypt the email with the original cypher key
            string encryptedEmail = StringCipher.Encrypt(email, cypherKey);

            //send web request to create new user account
            WebHandler webRequest = new WebHandler();

            webRequest.WebRequestSuccessEventHandler += OnRegisterSuccess;
            webRequest.WebRequestFailedEventHandler  += OnRegisterFailed;
            _webHandlerObject = webRequest;
            webRequest.RegisterNewUser(username, password, _activationCode, encryptedCypherKey, encryptedEmergencyCypherKey, encryptedEmail, email, emailVerificationCode);
        }