public void ProcessRequest(HttpContext context)
        {
            string key = context.Request.QueryString.Get("key");

            if (key == null || key == "")
            {
                context.Response.StatusCode = 404;
                context.Response.Write("no access key provided");
                return;
            }

            var user = AuthPool.GetRecordByKey(key);

            if (user == null)
            {
                context.Response.StatusCode = 403;
                context.Response.Write("no access record was found");
                return;
            }

            //string username = user.Username;
            //int status = (int)user.status;

            //context.Response.Cookies.Add(new HttpCookie("username", username));
            //context.Response.Cookies.Add(new HttpCookie("status", status.ToString()));
            context.Response.Cookies.Add(new HttpCookie("access-key", key));
            context.Response.WriteFile(AppDomain.CurrentDomain.BaseDirectory + "/default.html");
        }
 public void Close()
 {
     socket.Close();
     Manager.UserDisconnect(Username);
     AuthPool.BeginRemoveObject(Username);
     LogProvider.AppendRecord(string.Format("[{0}] disconnected", Username));
 }
        public void ProcessRequest(HttpContext context)
        {
            string input = null;

            using (StreamReader sr = new StreamReader(context.Request.InputStream))
            {
                input = sr.ReadLine();
            }
            Dictionary <string, string> obj = JsonConvert.DeserializeObject <Dictionary <string, string> >(input);

            AuthPool.AppendRecord(new AuthPool.PoolObject(
                                      obj["username"],
                                      obj["key"],
                                      int.Parse(obj["status"]),
                                      obj["banTill"]));
        }
Exemplo n.º 4
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "auth")
            {
                return(false);
            }

            string key = request.Args.ToString();

            AuthPool.PoolObject obj = AuthPool.GetRecordByKey(key);

            if (obj == null)
            {
                client.SendMessage(ResponseConstructor.GetErrorNotification("authorization failed", "login"));
                return(true);
            }
            if (Manager.FindClient(obj.Username) != null)
            {
                client.SendMessage(ResponseConstructor.GetErrorNotification("You have already logged in", "login"));
                client.Close();
                return(true);
            }
            client.Username = obj.Username;
            switch (obj.status)
            {
            case AuthStatus.User:
                client.Role = new User(client);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("user", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as user", client.Username));
                break;

            case AuthStatus.Banned:
                client.Role = new BannedUser(client, obj.banTill);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("banned", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as banned user", client.Username));
                break;

            case AuthStatus.Admin:
                client.Role = new Admin(client);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("admin", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as admin", client.Username));
                break;
            }
            Manager.AddClient(client);
            return(true);
        }