Пример #1
0
        public static async Task AccountCreate(IHttpContext context)
        {
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);

            if (!Server.LogedInHash.TryGetValue(guid, out Contact user) || user.Accesslevel < Server.Level_Admin)
            {
                await Home(context);

                return;
            }

            #region Form auslesen
            Dictionary <string, string> payload = Server.Payload(context);
            //payload.TryGetValue("Id",out string idStr); //Wird automatisch vergeben
            payload.TryGetValue("name", out string name);
            payload.TryGetValue("password", out string password);
            payload.TryGetValue("CompanyId", out string CompanyIdStr);
            payload.TryGetValue("viaEmail", out string viaEmail);
            payload.TryGetValue("viaAlwaysEmail", out string viaAlwaysEmail);
            payload.TryGetValue("email", out string email);
            payload.TryGetValue("viaPhone", out string viaPhone);
            payload.TryGetValue("phone", out string phoneStr);
            //KeyWord bei Neuanlage nicht vergebbar
            payload.TryGetValue("MaxInactiveHours", out string maxInactiveHoursStr);
            payload.TryGetValue("Accesslevel", out string accesslevelStr);
            #endregion

            #region Kontakt erstellen
            Contact contact = new Contact
            {
                Name      = name,
                EntryTime = DateTime.UtcNow,
                Password  = Tab_Contact.Encrypt(password),
                Email     = email,
            };

            if (int.TryParse(CompanyIdStr, out int companyId))
            {
                contact.CompanyId = companyId;
            }

            if (int.TryParse(maxInactiveHoursStr, out int maxInactiveHours))
            {
                contact.MaxInactiveHours = maxInactiveHours;
            }

            if (int.TryParse(accesslevelStr, out int accesslevel))
            {
                contact.Accesslevel = accesslevel;
            }

            if (ulong.TryParse(phoneStr, out ulong phone))
            {
                contact.Phone = phone;
            }

            contact.Via = Tab_Contact.Communication.Unknown;

            if (viaEmail != null)
            {
                contact.Via |= Tab_Contact.Communication.Email;
            }
            if (viaAlwaysEmail != null)
            {
                contact.Via |= Tab_Contact.Communication.AlwaysEmail;
            }
            if (viaPhone != null)
            {
                contact.Via |= Tab_Contact.Communication.Sms;
            }
            #endregion

            bool success = MelBoxSql.Tab_Contact.Insert(contact);
            string alert;

            if (success)
            {
                alert = Html.Alert(3, "Neuen Kontakt gespeichert", "Der Kontakt " + name + " wurde erfolgreich neu erstellt.");
                Tab_Log.Insert(Tab_Log.Topic.Database, 2, "Der Kontakt >" + name + "< wurde neu erstellt durch >" + user.Name + "< [" + user.Accesslevel + "]");
            }
            else
            {
                alert = Html.Alert(1, "Fehler beim speichern des Kontakts", "Der Kontakt " + name + " konnte nicht in der Datenbank gespeichert werden.");
            }

            await Server.PageAsync(context, "Benutzerkonto erstellen", alert);
        }
Пример #2
0
        public static async Task AccountUpdate(IHttpContext context)
        {
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);

            if (!Server.LogedInHash.TryGetValue(guid, out Contact user))
            {
                await Home(context);

                return;
            }

            #region Form auslesen
            Dictionary <string, string> payload = Server.Payload(context);
            payload.TryGetValue("Id", out string idStr);
            payload.TryGetValue("name", out string name);
            payload.TryGetValue("password", out string password);
            payload.TryGetValue("CompanyId", out string CompanyIdStr);
            payload.TryGetValue("viaEmail", out string viaEmail);
            payload.TryGetValue("viaAlwaysEmail", out string viaAlwaysEmail);
            payload.TryGetValue("email", out string email);
            payload.TryGetValue("viaPhone", out string viaPhone);
            payload.TryGetValue("phone", out string phoneStr);
            payload.TryGetValue("Keyword", out string keyWord);
            payload.TryGetValue("MaxInactiveHours", out string maxInactiveHoursStr);
            payload.TryGetValue("Accesslevel", out string accesslevelStr);
            #endregion

            #region Kontakt erstellen
            Contact where = new Contact();

            if (int.TryParse(idStr, out int Id))
            {
                where.Id = Id;
            }

            Contact set = new Contact
            {
                Name      = name,
                EntryTime = DateTime.UtcNow,
                KeyWord   = keyWord
            };

            if (password.Length > 0)
            {
                set.Password = Tab_Contact.Encrypt(password);
            }

            set.Email = email;


            if (int.TryParse(CompanyIdStr, out int companyId))
            {
                set.CompanyId = companyId;
            }

            if (int.TryParse(maxInactiveHoursStr, out int maxInactiveHours))
            {
                set.MaxInactiveHours = maxInactiveHours;
            }

            if (int.TryParse(accesslevelStr, out int accesslevel))
            {
                //kann maximal eigenen Access-Level vergeben.
                if (accesslevel > user.Accesslevel)
                {
                    accesslevel = user.Accesslevel;
                }

                set.Accesslevel = accesslevel;
            }

            if (ulong.TryParse(phoneStr, out ulong phone))
            {
                set.Phone = phone;
            }

            set.Via = Tab_Contact.Communication.Unknown;

            if (viaEmail != null)
            {
                set.Via |= Tab_Contact.Communication.Email;
            }
            if (viaAlwaysEmail != null)
            {
                set.Via |= Tab_Contact.Communication.AlwaysEmail;
            }
            if (viaPhone != null)
            {
                set.Via |= Tab_Contact.Communication.Sms;
            }
            #endregion

            bool success = Id > 0 && MelBoxSql.Tab_Contact.Update(set, where);

            string alert;

            if (success)
            {
                alert = Html.Alert(3, "Kontakt gespeichert", "Der Kontakt [" + Id + "] " + name + " wurde erfolgreich geändert.");
                Tab_Log.Insert(Tab_Log.Topic.Database, 2, "Der Kontakt [" + Id + "] >" + name + "< wurde geändert durch >" + user.Name + "< [" + user.Accesslevel + "]");
            }
            else
            {
                alert = Html.Alert(1, "Fehler beim speichern des Kontakts", "Der Kontakt [" + Id + "] " + name + " konnte in der Datenbank nicht geändert werden.");
            }

            await Server.PageAsync(context, "Benutzerkonto ändern", alert);
        }
Пример #3
0
        public static async Task RegisterProcessing(IHttpContext context)
        {
            #region Form auslesen
            Dictionary <string, string> payload = Server.Payload(context);
            //payload.TryGetValue("Id",out string idStr); //Wird automatisch vergeben
            payload.TryGetValue("name", out string name);
            payload.TryGetValue("password", out string password);
            payload.TryGetValue("CompanyId", out string CompanyIdStr);
            payload.TryGetValue("viaEmail", out string viaEmail);
            payload.TryGetValue("email", out string email);
            payload.TryGetValue("viaPhone", out string viaPhone);
            payload.TryGetValue("phone", out string phoneStr);
            //KeyWord nicht vergebbar
            //payload.TryGetValue("MaxInactiveHours", out string maxInactiveHoursStr);
            //payload.TryGetValue("Accesslevel", out string accesslevelStr);
            #endregion

            #region Kontakt erstellen
            Contact contact = new Contact
            {
                Name = name
            };

            if (MelBoxSql.Tab_Contact.Select(contact).Rows.Count > 0)
            {
                string error = Html.Alert(1, "Registrierung fehlgeschlagen", $"Der Benutzername {name} ist bereits vergeben." + @"<a href='/' class='w3-bar-item w3-button w3-teal w3-margin'>Nochmal</a>");
                await Server.PageAsync(context, "Benutzerregistrierung fehlgeschlagen", error);

                return;
            }

            contact.EntryTime = DateTime.UtcNow;
            contact.Password  = Tab_Contact.Encrypt(password);
            contact.Email     = email;

            if (int.TryParse(CompanyIdStr, out int companyId))
            {
                contact.CompanyId = companyId;
            }

            contact.MaxInactiveHours = 0;
            contact.Accesslevel      = 0;

            if (ulong.TryParse(phoneStr, out ulong phone))
            {
                contact.Phone = phone;
            }

            contact.Via = Tab_Contact.Communication.Unknown;

            if (viaEmail != null)
            {
                contact.Via |= Tab_Contact.Communication.Email;
            }
            if (viaPhone != null)
            {
                contact.Via |= Tab_Contact.Communication.Sms;
            }
            #endregion

            bool success = MelBoxSql.Tab_Contact.Insert(contact);

            string alert;

            if (success)
            {
                alert = Html.Alert(3, $"Erfolgreich registriert", $"Willkommen {name}!<br/> Die Registrierung muss noch durch einen Administrator bestätigt werden, bevor Sie sich einloggen können. Informieren Sie einen Administrator.");
                Tab_Log.Insert(Tab_Log.Topic.Database, 2, $"Neuer Benutzer >{name}< im Web-Portal registriert.");
            }
            else
            {
                alert = Html.Alert(1, "Registrierung fehlgeschlagen", "Es ist ein Fehler bei der Registrierung aufgetreten. Wenden Sie sich an den Administrator.");
            }


            await Server.PageAsync(context, "Benutzerregistrierung", alert);
        }