Exemple #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!IsValidated())
            {
                return;
            }
            // Check Username
            var usr = UserFacade.Select(txtUsername.Text.Trim());

            if (usr == null)  // Username not exist
            {
                lblMsg.Text = "Invalid username or password";
                txtUsername.Focus();
                SessionLogFacade.Log(Type.Priority_Warning, Module, Type.Log_Login, "Username="******" not exist");
                return;
            }
            // Check password
            if (!UserFacade.IsPwdCorrect(usr.Id, txtPassword.Text))
            {
                lblMsg.Text = "Invalid username or password";
                txtUsername.Focus();
                SessionLogFacade.Log(Type.Priority_Warning, Module, Type.Log_Login, "Password not correct");
                return;
            }
            //todo: validate start on, end on, status

            App.session.UserId   = usr.Id;
            App.session.Username = usr.Username;
            SessionFacade.Save(App.session);

            SessionLogFacade.Log(Type.Priority_Information, Module, Type.Log_Login, "Username="******" authenticates OK");
            // Save username
            App.setting.Set("Username", txtUsername.Text.Trim());
            App.setting.Save();

            DialogResult = System.Windows.Forms.DialogResult.OK;
        }