Example #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            bool   passed       = false;
            bool   userfound    = false;
            string loginoremail = "LOGIN";

            aEmail = txtEmail.Text;

            if (txtEmail.Text == "")
            {
                lblEmail.ForeColor = System.Drawing.Color.Red;
            }
            else if (txtPassword.Text == "")
            {
                lblPassword.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                if (Internet.EmailIsValid(txtEmail.Text) == true)
                {
                    loginoremail = "EMAIL";
                }

                UsersDB   _db = new UsersDB();
                DataTable _dt = _db.ExecuteQuery("select * from USERS");
                foreach (DataRow _row in _dt.Rows)
                {
                    if (_row[loginoremail].ToString() == txtEmail.Text) // user found
                    {
                        userfound = true;
                        aName     = _row["NAME"].ToString();
                        aEmail    = _row["EMAIL"].ToString();
                        if (_row["PASS"].ToString() == txtPassword.Text) // TODO password decrypt?
                        {
                            passed = true;
                            MMUtils.SetRegistry("", "CurrentUserName", aName);
                            MMUtils.SetRegistry("", "CurrentUserEmail", aEmail);
                            if (checkBoxRemember.Checked == true)
                            {
                                MMUtils.SetRegistry("", "RememberMe", "1");
                                MMUtils.SetRegistry("", "RememberedUserName", aName);
                                MMUtils.SetRegistry("", "RememberedUserEmail", aEmail);
                            }
                            break;
                        }
                        else //password wrong
                        {
                            string _arg = MMUtils.GetString("loginDlg.login.text");
                            if (loginoremail == "EMAIL")
                            {
                                _arg = MMUtils.GetString("loginDlg.Email.text");
                            }
                            lblPasswordNoMatch.Text = String.Format(MMUtils.GetString("loginDlg.wrongpassword.text"), _arg);
                        }
                    }
                }

                _db.Dispose();

                if (!userfound)
                {
                    lblUserNoExists.Text = MMUtils.GetString("loginDlg.usernoexists.text");
                }

                if (passed)
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
Example #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (Internet.EmailIsValid(txtEmail.Text) == false)
            {
                lblRequired.Text = MMUtils.GetString("newuserDlg.wrongemail.text"); //wrong email format
            }
            else if (txtEmail.Text == "" || txtLogin.Text == "" || txtName.Text == "" || txtPassword.Text == "")
            {
                lblRequired.Text = MMUtils.GetString("newuserDlg.allfieldsrequired.text");
            }
            else
            {
                aLogin           = txtLogin.Text;
                aPassword        = txtPassword.Text; //TODO crypt password?
                lblRequired.Text = "";

                using (UsersDB dbUsers = new UsersDB())
                {
                    DataTable _dt = dbUsers.ExecuteQuery("select * from USERS");
                    foreach (DataRow _row in _dt.Rows)
                    {
                        if (_row["LOGIN"].ToString() == txtLogin.Text) //this login already exists!
                        {
                            lblRequired.Text = MMUtils.GetString("newuserDlg.loginexists.text");
                            break;
                        }
                        else if (_row["EMAIL"].ToString() == txtEmail.Text) //this email already exists!
                        {
                            lblRequired.Text = MMUtils.GetString("newuserDlg.emailexists.text");
                            break;
                        }
                    }
                }

                if (lblRequired.Text == "")
                {
                    string _role = "";
                    if (rbtnAdmin.Checked)
                    {
                        _role = "Admin";
                    }
                    else if (rbtnAdmin.Checked)
                    {
                        _role = "DAdmin";
                    }
                    else
                    {
                        _role = "Member";
                    }

                    using (UsersDB _db = new UsersDB())
                    {
                        _db.ExecuteNonQuery("INSERT INTO USERS VALUES(" +
                                            "`" + txtName.Text + "`," +
                                            "`" + txtEmail.Text + "`," +
                                            "`" + aLogin + "`," +
                                            "`" + aPassword + "`," +
                                            "`" + _role + "`, ``, ``, 0, 0)");
                    }

                    //TODO может отправить письмо?
                    this.DialogResult = DialogResult.OK;
                }
            }
        }