public bool HandleRequest(Client client, HttpListenerContext context, params string[] args)
        {
            this.context = context;

            if (client.Connected())
            {
                context.Redirect("../home");
                return true;
            }

            if (context.GetMethod() == HttpMethod.GET)
            {
                this.ShowRegister(client);
            }
            else if (context.GetMethod() == HttpMethod.POST)
            {
                Dictionary<string, string> requestData = context.GetData();

                if (requestData.ContainsKey("username") && requestData.ContainsKey("password"))
                {
                    string username = requestData["username"];
                    string password = PasswordManager.Hash(requestData["password"]);

                    User user = UserManager.CreateUser(username, password);
                    if (user != null)
                    {
                        if (UserManager.Login(username, requestData["password"], client))
                        {
                            context.Redirect("../home");
                            return true;
                        }
                    }
                    else
                    {
                        this.ShowRegister(client, new Error("Couldn't create the user!"));
                        return false;
                    }
                }

                this.ShowRegister(client, new Error("Something wrong happened there!"));
            }

            return true;
        }
        public bool HandleRequest(Client client, HttpListenerContext context, params string[] args)
        {
            this.context = context;

            if (client.Connected())
            {
                context.Redirect("../home");
                return true;
            }   

            if (context.GetMethod() == HttpMethod.GET)
            {
                this.ShowLogin(client);
            }
            else if(context.GetMethod() == HttpMethod.POST)
            {
                Dictionary<string, string> requestData = context.GetData();

                if (requestData.ContainsKey("username") && requestData.ContainsKey("password"))
                {
                    string username = requestData["username"];
                    string password = requestData["password"];

                    if (UserManager.Login(username, password, client))
                    {
                        context.Redirect("../home");
                    }
                    else
                    {
                        this.ShowLogin(client, new Error("Invalid username or password"));
                    }
                }
                else
                {
                    this.ShowLogin(client, new Error("Error"));
                }
            }

            return true;
        }
Пример #3
0
        public bool HandleRequest(Client client, HttpListenerContext context, params string[] args)
        {
            if (!UserManager.Connected(client))
            {
                context.Redirect("../login");
                return true;
            }

            User user = UserManager.GetUser(UserManager.GetUserID(client));

            Home_Template template = new Home_Template(user);
            context.Send(template.Render());

            return true;
        }