Example #1
0
 protected override after_show show_view(mwa.cmds.cmd c = null)
 {
     this.main.set_title("Login");
     this.state = state_login.none;
     txt_utente.Focus();
     return(new after_show());
 }
Example #2
0
        protected void check_login()
        {
            try {
                string login = txt_utente.Text, password = txt_password.Text;
                if (login == "")
                {
                    this.main.set_status_err("ma chi sei?"); txt_utente.Focus(); return;
                }

                utente u = crypt.encode_tobase64(login) == mwl.cfg.cfg.key("ad_usr") ? new utente(0, "admin", "", true)
          : utente.dl.get_from_login(login);
                if (!u.is_admin)
                {
                    if (u == null)
                    {
                        this.main.set_status_err("non sei registrato!"); txt_utente.Text = ""; return;
                    }
                    if (u.is_scaduto)
                    {
                        this.main.set_status_err("il tuo utente è scaduto!"); txt_utente.Text = ""; return;
                    }
                    if (u.disactive)
                    {
                        this.main.set_status_err("il tuo utente è stato disattivato!"); txt_utente.Text = ""; txt_utente.Focus(); return;
                    }
                }
                else
                {
                    // admin to password
                    if (this.state == state_login.none)
                    {
                        lbl_pass.Visible = txt_password.Visible = true;
                        this.state       = state_login.to_password;
                        txt_password.Focus(); return;
                    }
                }

                // to activate
                if (u.is_to_activate)
                {
                    // activate key
                    if (this.state == state_login.none)
                    {
                        lbl_pass.Text    = "Activate Key";
                        lbl_pass.Visible = txt_password.Visible = true;

                        this.main.set_status_info("Inserisci la chiave di attivazione!");
                        txt_password.Focus();
                        this.state = state_login.to_activate;
                        return;
                    }
                    // check key
                    else if (this.state == state_login.to_activate)
                    {
                        if (txt_password.Text == "")
                        {
                            this.main.set_status_err("devi inserire la chiave di attivazione!"); txt_password.Focus(); return;
                        }
                        utente uu = utente.dl.check_key_to_activate(login, txt_password.Text);
                        if (uu == null)
                        {
                            this.main.set_status_err("la chiave di attivazione non è corretta!"); txt_password.Text = ""; txt_password.Focus(); return;
                        }

                        lbl_pass.Text = "Imposta la password";
                        this.main.set_status_info("Imposta la tua password!");

                        lbl_conf_pass.Visible = txt_conf_pasword.Visible = true;

                        txt_password.Text = "";
                        txt_password.Focus();
                        this.state = state_login.set_password;
                        return;
                    }
                    // set password - login
                    else if (this.state == state_login.set_password)
                    {
                        string pwd = txt_password.Text, pwd2 = txt_conf_pasword.Text;
                        utente.dl.check_pwd(pwd, pwd2);
                        utente.dl.login_new_pass(u.id, pwd);

                        // login
                        if (chk_ricordami.Checked)
                        {
                            this.main.save_remember(login, password);
                        }
                        utente.dl.login(u.id);
                        this.main.login(u);
                        return;
                    }
                }
                else
                {
                    // to password
                    if (this.state == state_login.none)
                    {
                        lbl_pass.Visible = txt_password.Visible = true;
                        this.state       = state_login.to_password;
                        txt_password.Focus(); return;
                    }
                }

                // check login
                if (state == state_login.to_password)
                {
                    if (password == "")
                    {
                        txt_password.Focus(); throw new Exception("Devi inserire la password!");
                    }

                    // admin?
                    if (crypt.encode_tobase64(login) == mwl.cfg.cfg.key("ad_usr") &&
                        crypt.encode_tobase64(password) == mwl.cfg.cfg.key("ad_pwd"))
                    {
                        if (chk_ricordami.Checked)
                        {
                            this.main.save_remember(login, password);
                        }
                        this.main.login(new utente(0, "admin", crypt.decrypt(mwl.cfg.cfg.key("ad_mail"), password), true));
                        return;
                    }

                    u = utente.dl.check_password(login, password);
                    if (u == null)
                    {
                        throw new Exception($"l'utente '{login}' non esiste o hai sbagliato la password!");
                    }

                    // codice d'attivazione
                    if (!u.activated)
                    {
                        throw new Exception("Il tuo utente non è attivo!");
                    }

                    // login
                    if (chk_ricordami.Checked)
                    {
                        this.main.save_remember(login, password);
                    }
                    utente.dl.login(u.id);
                    this.main.login(u);
                }
            } catch (Exception ex) { this.main.set_status_err(ex); }
        }