public void load_cmds(utente u, string path_cmds) { this.list = new List <cmd>(); mwl.xml.xml_doc d = new mwl.xml.xml_doc(path_cmds); foreach (mwl.xml.xml_node ng in d.nodes("//cmds/cmd-group")) { cmd_group grp = new cmd_group(ng.get_attr("title"), ng.get_attr("view") , ng.get_attr("type") != "" ? (cmd.type_cmd)Enum.Parse(typeof(cmd.type_cmd), ng.get_attr("type")) : cmd.type_cmd.none); if (grp.type == cmd.type_cmd.admin && !u.is_admin) { continue; } foreach (mwl.xml.xml_node nc in ng.nodes("cmd")) { cmd c = new cmd(grp) { prefix = nc.get_attr("prefix"), only_active_view = nc.get_bool("only_active_view"), view = nc.get_attr("view", grp.view) , action = nc.get_attr("action"), des = nc.get_attr("des"), action_optional = nc.get_attr("action-opt") == "true" , obj = nc.get_attr("object"), subobj = nc.get_attr("subobj"), subobj2 = nc.get_attr("subobj2") , hidden = nc.get_attr("hidden") == "true" , type = nc.get_attr("type") != "" ? (cmd.type_cmd)Enum.Parse(typeof(cmd.type_cmd), nc.get_attr("type")) : cmd.type_cmd.none }; if (c.type == cmd.type_cmd.admin && !u.is_admin) { continue; } this.list.Add(c); } } }
private void dgv_utenti_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } DataGridView dgv = (DataGridView)sender; utente u = (utente)dgv.Rows[e.RowIndex].DataBoundItem; string cn = dgv.Columns[e.ColumnIndex].Name; if (cn == "login") { if (u.is_to_activate) { e.CellStyle.ForeColor = e.CellStyle.SelectionForeColor = Color.DarkOrange; } else if (u.is_scaduto) { e.CellStyle.ForeColor = e.CellStyle.SelectionForeColor = Color.Tomato; } } else { if (u.is_scaduto) { e.CellStyle.ForeColor = e.CellStyle.SelectionForeColor = Color.LightGray; } } } catch { } }
private void btn_ok_Click(object sender, EventArgs e) { try { if (this.new_user) { string login = txt_utente.Text, email = txt_mail.Text , pwd = txt_new_password.Text, pwd2 = txt_conf_password.Text; if (login == "") { throw new Exception("Devi scrivere l'utente!"); } if (utente.dl.exists_login(login)) { throw new Exception("E' già registato un utente '" + login + "'!"); } utente u = utente.dl.insert(login, email, out string key); if (this.web_users != null) { this.web_users.add_utente(u); } this.main.back_view(); } else { this.web_users.update_utente(this.utente, txt_mail.Text, txt_new_password.Text, txt_conf_password.Text); this.main.back_view(); } } catch (Exception ex) { this.main.set_status_err(ex); } }
protected override void load_objects(object data = null) { base.load_objects(data); utente u = logged.utente(); bool logged_admin = u.is_admin; add_script($@"function change_notes(el) {{ fnc('change-notes', [$(el).text()]); }}"); this.add_html($@"<div class='row mb-5'> <div class='col-sm-8'> <span class='fs-140 d-block'> <span style='font-size:60%;margin-right:5px;color:{css_clr(style.fc1)};'>user:</span> <span>{u.login}</span></span> {(!logged_admin ? $@"<span class='fs-80 d-block op-6' placeholder='breve descrizione utente' contenteditable onclick=""document.execCommand('selectAll',false,null)"" onblur='change_notes(this)'>{(!string.IsNullOrEmpty(u.notes) ? u.notes : "breve descrizione")}</span>" : "<span class='fs-80 d-block op-6'>utente amministratore</span>")} </div> <div class='col-sm-4'> {(!string.IsNullOrEmpty(u.mail) ? $@"<span class='f-r fs-80' style='float:right;font-size:85%;color:{css_clr(style.fc1)};'> <span class='op-6'>mail:</span>{u.mail}</span>" : "")} </div> </div><hr/>"); this.add_elements(def_view.defs .Where(x => x.system_view == false && x.sub_view == false && (logged_admin || (!logged_admin && !x.admin_view))) .OrderBy(x => x.title_view).Select(x => new web_def_view(x))); }
protected void check_login() { try { string login = txt_utente.Text, password = txt_password.Text; if (login == "") { throw new Exception("Devi scrivere chi sei!"); } if (password == "") { throw new Exception("Devi inserire la password!"); } // admin? if (crypt.encode_tobase64(login) == cfg.key("ad_usr") && crypt.encode_tobase64(password) == cfg.key("ad_pwd")) { this.main.login(new elements.utente(0, "admin", crypt.decrypt(cfg.key("ad_mail"), password), true, "utente amminstratore")); return; } utente u = utente.al.check_login(login, password); if (u == null) { throw new Exception($"l'utente '{login}' non esiste o hai sbagliato la password!"); } // codice d'attivazione if (u.is_to_activate) { lbl_back_key.Visible = lbl_key.Visible = txt_key.Visible = true; if (txt_key.Text == "") { txt_key.Focus(); throw new Exception("Devi inserire la chiave d'attivazione!"); } if (txt_key.Text.ToUpper() != u.active_key.ToUpper()) { throw new Exception("La chiave d'attivazione inserita non è corretta!"); } u.active(); } if (chk_ricordami.Checked) { this.main.save_remember(login, password); } this.main.login(u); } catch (Exception ex) { this.main.set_status_err(ex, true); } }
public void login(utente u) { try { set_status("CARICAMENTO DATI UTENTE...", center: true); logged.login(u); cmb_cmds.logged_user(u); this.show_view(typeof(vw_home)); set_status(); } catch (Exception ex) { set_status_err(ex); } }
private void frm_main_Shown(object sender, EventArgs e) { try { // pulisco gli utente vecchi non attivati elements.utente.al.clean_unactive(); // remember utente u = check_remember(); if (u != null) { this.login(u); return; } show_view(typeof(vw_login)); } catch (Exception ex) { set_status_err(ex); } }
public void update_utente(utente u, string mail, string pwd, string pwd2) { if (pwd != "") { if (pwd2 == "") { throw new Exception("Devi confermare la password!"); } utente.dl.check_pwd(pwd, pwd2); } u.change_mail(mail); if (pwd != "") { utente.dl.login_new_pass(u.id, pwd); } this.upd_element(u.id); }
public override web_res fnc(string name, string[] args = null) { try { web_res r = base.fnc(name, args); if (!r.not_elab) { return(r); } if (name == "change-notes") { utente u = logged.utente(); u.change_notes(args[0]); return(web_res.is_ok()); } } catch (Exception ex) { this.main.set_status_err(ex); } return(web_res.is_not_elab()); }
protected override after_show show_view(mwa.cmds.cmd c = null) { try { this.loading = true; if (this.empty) { if (this.new_user) { this.title_view = "Nuovo Utente"; txt_utente.Focus(); lbl_pass.Visible = lbl_pass2.Visible = txt_new_password.Visible = txt_conf_password.Visible = pb_disattiva.Visible = false; btn_ok.Text = "aggiungi"; } else { utente u = this.utente; lbl_pass.Text = "Reimposta Password"; txt_mail.Focus(); if (u.is_to_activate) { lbl_pass.Visible = lbl_pass2.Visible = txt_new_password.Visible = txt_conf_password.Visible = pb_disattiva.Visible = false; } else { if (u.disactive) { pb_disattiva.Image = Properties.Resources.guarantee_32; pb_disattiva.Tag = "attiva"; base_tooltip1.SetToolTip(pb_disattiva, "riabilita l'utente assegnandogli una chiave di attivazione"); } else { pb_disattiva.Image = Properties.Resources.dont_touch_32; pb_disattiva.Tag = "disattiva"; base_tooltip1.SetToolTip(pb_disattiva, "disabilita l'utente"); } } txt_utente.Text = u.login; txt_utente.ReadOnly = true; txt_mail.Text = u.mail; btn_ok.Text = "aggiorna"; (new light_view(this.main.style, this.wb_footer)).set_html($@"<div class='op-6'><span class='mr-3 text-muted no-wrap'>id: {u.id}</span> <span class='mr-3 no-wrap'>Inserito: {u.dt_ins.Value.ToString("dddd dd MMMM yyyy")}</span> {(u.is_to_activate ? $"<span class='mr-3 no-wrap light'>Si deve attivare, key: {u.active_key}</span>" : "")} {(u.is_scaduto ? "<span class='mr-3 no-wrap warning'>Utente scaduto</span>" : "")} {(u.activated ? $@"<span class='mr-3 no-wrap'>Attivato: {u.dt_activate.Value.ToString("dddd dd MMMM yyyy")}</span>" : "")} {(u.disactive ? $@"<span class='mr-3 warning'>Disattivato</span>" : "")} {(u.last_login.HasValue ? $"<span class='mr-3 no-wrap op-6'>Ultimo login: {u.last_login.Value.ToString("dddd dd MMMM yyyy")}</span>" : "")}</div>"); } } } finally { this.loading = false; } return(new after_show(true)); }
public vw_user(web_users wv, utente u, frm_main main = null) : base(main) { InitializeComponent(); this.web_users = wv; this.utente = u; }
public web_user_row(utente u) { this.utente = u; this.id_element = this.utente.id; }
public void add_utente(utente u) { this.insert_begin("[web-element=users]", new_element(new web_user_row(u)).get_html()); }
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); } }
public void logged_user(utente u) { this.Text = ""; this.commands.load_cmds(u, mwl.cfg.cfg.get_key("cmds-path")); }