Ejemplo n.º 1
0
        public IHttpContext Login(IHttpContext context)
        {
            string caption = "Login";      //Überschrift der Seite
            string newGuid = string.Empty; //Nur füllen, wenn neue Benutzeranmeldung
            string payload = context.Request.Payload;
            Dictionary <string, string> args = MelBoxWeb.ReadPayload(payload);

            ReadGlobalFields(args);

            StringBuilder builder = new StringBuilder();

            if (args.ContainsKey("name") && args.ContainsKey("password"))
            {
                string name     = args["name"]; //.Replace('+', ' ');
                string password = args["password"];

                newGuid = MelBoxWeb.CheckLogin(name, password);

                if (newGuid.Length == 0)
                {
                    builder.Append(MelBoxWeb.HtmlAlert(2, "Login fehlgeschlagen", "Login für Benutzer '" + name + "' fehlgeschlagen.<br>Benutzer und Passwort korrekt?"));
                }
                else
                {
                    User newLogedInUser = MelBoxWeb.GetUserFromGuid(newGuid);
                    guid            = newGuid;
                    logedInUserName = newLogedInUser.Name;
                    logedInUserId   = newLogedInUser.Id;
                    isAdmin         = newLogedInUser.IsAdmin;
                }
            }

            if (guid.Length == 0 || logedInUserId == 0)
            {
                builder.Append(MelBoxWeb.HtmlLogin());
            }
            else
            {
                builder.Append(MelBoxWeb.HtmlAlert(4, isAdmin ? "Angemeldet als Administrator" : "Angemeldet als Benutzer", string.Format("[{0}] {1}", logedInUserId, logedInUserName)));
                builder.Append(MelBoxWeb.HtmlLogout());
            }
#if DEBUG
            builder.Append("<p class='w3-pink'>" + payload + "</p>");
#endif
            context.Response.SendResponse(MelBoxWeb.HtmlCanvas(builder.ToString(), caption, logedInUserName, newGuid));
            return(context);
        }
Ejemplo n.º 2
0
        private void ReadGlobalFields(Dictionary <string, string> args)
        {
            if (args.ContainsKey("guid"))
            {
                guid = args["guid"];
                User user = MelBoxWeb.GetUserFromGuid(guid);

                if (user != null)
                {
                    logedInUserName = user.Name;
                    logedInUserId   = user.Id;
                    isAdmin         = user.IsAdmin;
                }
            }

            if (args.ContainsKey("pageTitle"))
            {
                requestingPage = args["pageTitle"];
            }
#if DEBUG
            // Console.WriteLine("Aufruf von {0} durch: [{1}] {2} - Admin: {3} | {4}", requestingPage, logedInUserId, logedInUserName, isAdmin, guid);
#endif
        }