예제 #1
0
파일: Login.cs 프로젝트: evelinad/Talk2Me
        public static Login Desserialize(byte[] data)
        {
            Login result = new Login();
            using (MemoryStream m = new MemoryStream(data))
            {
                using (BinaryReader reader = new BinaryReader(m))
                {

                    result.Username = reader.ReadString();
                    result.Password = reader.ReadString();
                }
            }
            return result;
        }
예제 #2
0
            public void ProcessRequest()
            {
                try {
                    string input = new StreamReader(context.Request.InputStream).ReadToEnd();
                    string msg = context.Request.HttpMethod + " " + context.Request.Url;
                    Console.Write(msg);
                    context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                    context.Response.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");

                    StringBuilder sb = new StringBuilder();

                    var delimiter = input.IndexOf("?");
                    var data = "";
                    if (delimiter == -1) {
                        delimiter = input.Length;
                    } else {
                        data = input.Substring(delimiter + 1);
                    }
                    var name = input.Substring(0, delimiter);
                    Console.WriteLine(" " + name);

                    if (name.ToLower() == "login") {
                        var parameters = HttpUtility.ParseQueryString(data);
                        var login = new Login(parameters["login"], parameters["password"]); //json.Deserialize<Login>(data);
                        var id = DB.checkLogin(login.login, login.password);
                        if (id == 1) {
                            /*var loginCookie = new Cookie();
                            loginCookie.Name = "Session";
                            var cookie = "";
                            do {
                                cookie = System.Web.Security.Membership.GeneratePassword(22, 11);
                            } while (DB.checkCookie(cookie) != -1);
                            DB.addCookie(cookie, id);
                            loginCookie.Value = cookie;
                            loginCookie.Expires = DateTime.Now.AddDays(1);

                            context.Response.Cookies.Add(loginCookie);*/
                            sb.Append("success");
                        } else {
                            sb.Append("fail");
                        }
                    /*} /*else if (name.ToLower() == "logout") {
                        var cook = getCookie(context);
                        if (cook != null) {
                            var expCookie = new Cookie();
                            expCookie.Name = "Session";
                            expCookie.Expires = DateTime.Now.AddDays(-1d);
                            context.Response.Cookies.Add(expCookie);
                            if (DB.checkCookie(cook.Value) != -1) {
                                DB.deleteCookie(cook.Value);
                            }
                        }*/
                    } else if (name.ToLower() == "coordinates") {
                        /*Console.Write("LOLOL!");
                        var cook = getCookie(context);
                        if (cook != null) {
                            //var id = DB.checkCookie(cook.Value);
                            //if (id != -1) {*/
                                var id = 1;
                                var coords = DB.getCoordinates(id);
                                var json = new System.Web.Script.Serialization.JavaScriptSerializer();
                                  foreach(var coordinate in coords){
                                    sb.Append(String.Format(CultureInfo.InvariantCulture, "{0};{1};{2};", coordinate.x, coordinate.y, coordinate.comment));
                                }
                            //}
                        }

                    byte[] b = Encoding.UTF8.GetBytes(sb.ToString());
                    context.Response.ContentLength64 = b.Length;
                    var stream = context.Response.OutputStream;
                    stream.Write(b, 0, b.Length);
                    stream.Flush();
                    stream.Close();
                } catch (Exception e) {
                    Console.WriteLine(e);
                }
            }
예제 #3
0
 public static void InvokeLogin(LoginEventArgs e)
 {
     Login?.Invoke(e);
 }
예제 #4
0
        public static void handleLogin(User user)
        {
            Login login = Login.Instance;

            login.verifyLoginData(user);
        }
예제 #5
0
 public static void InvokeLogin(Mobile m) => Login?.Invoke(m);
예제 #6
0
파일: Server.cs 프로젝트: evelinad/Talk2Me
        public static void message(Login mess, Socket handler)
        {
            // TODO INTEROGARE BAZA DE DATE, user valid
            if (!map.ContainsKey(mess.Username))
            {
                map.Add(mess.Username, handler);

            }
            else
                map[mess.Username] = handler;
            String a = "" + mess.Username + " " + mess.Password;
            Console.WriteLine(a);
            // TODO TRIMITERE MESAJ
        }