示例#1
0
        //reset password
        private void btnFind_Click(object sender, EventArgs e)
        {
            FormPassValue.loginForm = this.Owner;

            CancelEventArgs cea = new CancelEventArgs();

            txtPasswordConfirm_Validating(sender, cea);
            txtPassword_Validating(sender, cea);
            txtCode_Validating(sender, cea);

            //validate input pass
            if (cea.Cancel == false)
            {
                if (this.txtCode.Text.Trim().Equals(this.verificationCode))
                {
                    if (this.txtPasswordConfirm.Text.Trim().Equals(this.txtPassword.Text.Trim()))
                    {
                        UserService.UserServiceClient client = new UserService.UserServiceClient();
                        int    userId          = Convert.ToInt32(client.QueryUserIdByName(this.userName));
                        string encryptPassword = EncryptUtils.EncryptPassword(this.txtPassword.Text.Trim());

                        try
                        {
                            client.UpdatePassword(encryptPassword, userId);
                            FormPassValue.isSendEmail = false;

                            this.customTimer.GetTimer().Enabled = false;
                            TipForm tipForm = new TipForm();
                            tipForm.SetMessage(ResourceCulture.GetString(CHANGE_PASSWORD_SUCCESS));
                            tipForm.SetIsShowCancel(false);
                            tipForm.ShowDialog();
                            this.DialogResult = DialogResult.OK;
                            this.Owner.Show();
                        }
                        catch (Exception ex)
                        {
                            Log4NetHelper.WriteErrorLog(typeof(ResetPassword), ex);

                            TipForm tipForm = new TipForm();
                            tipForm.SetMessage(ResourceCulture.GetString(CHANGE_PASSWORD_UNSUCCESS));
                            tipForm.SetIsShowCancel(false);
                            tipForm.ShowDialog();
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    else
                    {
                        this.lblErrorMessage.Text = ResourceCulture.GetString(NOT_CONSISTENT);
                        this.lblErrorMessage.Show();
                    }
                }
                else
                {
                    this.lblErrorMessage.Text = ResourceCulture.GetString(VALIDATION_CODE_ERROR);
                    this.lblErrorMessage.Show();
                    currentTime++;

                    if (currentTime == totalTime)
                    {
                        this.DialogResult = DialogResult.Cancel;
                        this.Owner.Show();
                    }
                }
            }
        }
        /// <summary>
        /// send email
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFind_Click(object sender, EventArgs e)
        {
            CancelEventArgs cea = new CancelEventArgs();

            txtUsername_Validating(sender, cea);
            txtEmail_Validating(sender, cea);

            if (cea.Cancel == false)
            {
                UserService.UserServiceClient client = new UserService.UserServiceClient();
                bool result = client.ValidateUserAndEmail(this.txtUsername.Text.Trim(), this.txtEmail.Text.Trim());

                //If has sent email, refuse send again in one minute.
                if (FormPassValue.isSendEmail)
                {
                    TipForm tipForm = new TipForm();
                    tipForm.SetMessage(ResourceCulture.GetString(HAS_SEND_MAIL));
                    tipForm.SetIsShowCancel(false);
                    tipForm.ShowDialog();

                    this.DialogResult = DialogResult.OK;
                    this.Owner.Show();
                    return;
                }

                //validate user pass
                if (result == true)
                {
                    Guid   guid             = Guid.NewGuid();
                    string verificationCode = guid.ToString().Substring(0, 8);

                    bool isSuccess = SendEmail.SendingEmail(SEND_EMAIL_ADDRESS, SENDER_PASSWORD, this.txtEmail.Text.Trim(),
                                                            ResourceCulture.GetString(TITLE), ResourceCulture.GetString(CONTENT_ONE) + verificationCode, HOST);

                    if (isSuccess)
                    {
                        FormPassValue.isSendEmail = true;

                        TipForm tipForm = new TipForm();
                        tipForm.SetMessage(ResourceCulture.GetString(EMAIL_HAS_SEND));
                        tipForm.SetIsShowCancel(false);
                        tipForm.IsOpenTimer(true);
                        DialogResult tipResult = tipForm.ShowDialog();

                        if (tipResult == DialogResult.OK || tipResult == DialogResult.Cancel)
                        {
                            tipForm.GetCustomTimer().GetTimer().Enabled = false;

                            ResetPassword form = new ResetPassword();
                            form.SetVerificationCode(verificationCode);
                            form.SetUserName(this.txtUsername.Text.Trim());
                            form.SetEMail(this.txtEmail.Text.Trim());
                            form.SetCount(tipForm.GetCustomTimer().GetCount());
                            form.OpenTimer();
                            form.ShowDialog(this.Owner);

                            this.DialogResult = DialogResult.OK;
                        }
                        // time out
                        else if (tipResult == DialogResult.Ignore)
                        {
                            this.btnFind.Text = ResourceCulture.GetString(RESEND);
                        }
                    }
                    else
                    {
                        TipForm tipForm = new TipForm();
                        tipForm.SetMessage(ResourceCulture.GetString(EMAIL_SEND_FAIL));
                        tipForm.SetIsShowCancel(false);
                        tipForm.ShowDialog();

                        this.DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    this.lblErrorMessage.Text = ResourceCulture.GetString(USER_AND_EMAIL_NOT_MATCH);
                    this.lblErrorMessage.Show();
                }
            }
        }