Exemplo n.º 1
0
        public string RegisterUser(string email, string password, string username, string birthday, string gender, string country)
        {
            //-1 username or email already exists, -2 invalid birthday
            try

            {
                database db = new database(database.maindb);
                if (String.IsNullOrEmpty(birthday)) birthday = "";
                if (String.IsNullOrEmpty(country)) country = "";

                db.AddParam("?username", username);
                db.AddParam("?email", email);

                MySqlDataReader rd = db.ExecuteReader("select * from users where lower(email)=lower(?email) or lower(username)=lower(?username)");
                if (rd.HasRows) return "-1";

                DateTime dateValue;
                if (!DateTime.TryParse(birthday, out dateValue) && birthday != "") return "-2";

                int sex = 0;
                switch (gender)
                {
                    case "Gender":
                        sex = 0;
                        break;
                    case "Male":
                        sex = 1;
                        break;
                    case "Female":
                        sex = 2;
                        break;
                }
                db.AddParam("?password", password);
                db.AddParam("?birthday", birthday);
                db.AddParam("?country", country);
                db.AddParam("?gender", sex);

                db.ExecuteNonQuery("insert into users(email,username,password,gender,country,birthday) values (?email,?username,?password,?gender,?country,?birthday)");
                return "1";
            }
            catch (Exception e)
            { return e.ToString(); }
        }
Exemplo n.º 2
0
        public IActionResult GetHard()
        {
            Random rand = new Random();
            string code = "";
            Dictionary<string, string> answers = new Dictionary<string, string>();

            Countries.Question question;
            string description = "";
            string name = "";
            int error = 0;
            string random_id = "";
            try
            {

                database db = new database(database.maindb);
            Begin:
                error = 0;
                int id1 = rand.Next(1, 213771);
                int id2 = rand.Next(1, 213771);
                int id3 = rand.Next(1, 213771);
                int id4 = rand.Next(1, 213771);
                answers = new Dictionary<string, string>();
                string answer_code = "";
                MySqlDataReader rd = db.ExecuteReader("select code from diseasestatistics where id=" + id1 + " or id=" + id2 + " or id=" + id3 + " or id=" + id4);
                int count = 0;
                while (rd.Read())
                {
                    count++;
                    code = rd.GetString("code");
                    if (count == 1)
                        answer_code = code;

                    answers.Add(code, "");
                }
                ViewBag.answers = answers;
                SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org");

                foreach (KeyValuePair<string, string> answer in answers.ToList())
                {
                    code = answer.Key;
                    string query = @"SELECT * WHERE {
                            ?url <http://dbpedia.org/ontology/icd10> ?ID.
                            ?url rdfs:label ?name.
                            ?url <http://dbpedia.org/ontology/abstract> ?description.
                            filter regex(str(lcase(?ID)), concat(lcase('" + code[0] + "'), '[" + code[1] + "][" + code[2] + "][.]?[0-9]?') )" +
                                "filter(langMatches(lang(?name), 'EN'))" +
                                "filter(langMatches(lang(?description), 'EN'))" +
                                "} limit 1";
                    SparqlResultSet results = endpoint.QueryWithResultSet(query);
                    if (results.Count > 0 && answer_code == answer.Key)
                    {

                        random_id = RandomString(15);
                        name = results[0]["name"].ToString().Remove(results[0]["name"].ToString().Length - 3);
                        description = results[0]["description"].ToString();
                        db.ExecuteNonQuery("insert into questions(random_id,answer) values ('" + random_id + "','" + name + "')");

                    }
                    else if (results.Count == 0)
                    {
                        query = @"SELECT * WHERE {
                            ?url <http://dbpedia.org/ontology/icd10> ?ID.
                            ?url rdfs:label ?name.
                            ?url <http://dbpedia.org/ontology/abstract> ?description.
                            filter regex(str(lcase(?ID)), concat(lcase('" + code[0] + "'), '[" + code[1] + "][0-9][.]?[0-9]?') )" +
                           "filter(langMatches(lang(?name), 'EN'))" +
                           "filter(langMatches(lang(?description), 'EN'))" +
                           "} limit 1";
                        results = endpoint.QueryWithResultSet(query);
                        if (results.Count > 0 && answer_code == answer.Key)
                        {

                            random_id = RandomString(15);
                            name= results[0]["name"].ToString().Remove(results[0]["name"].ToString().Length - 3);
                            description = results[0]["description"].ToString();
                            db.ExecuteNonQuery("insert into questions(random_id,answer) values ('" + random_id + "','" + name + "')");

                        }

                    }
                    if (results.Count > 0) answers[answer.Key] = results[0]["name"].ToString().Remove(results[0]["name"].ToString().Length - 3);
                    else error = 1;
                }
                if (error == 1) goto Begin;
                description = description.Replace(name, "***");
                description = description.Replace(name.ToLower(), "***");
                description = description.Remove(description.Length - 3);
                question = new Countries.Question(answers, description, random_id);

            }
            catch (Exception e) { return new ObjectResult(e.ToString()); }
            return new ObjectResult(question);
        }
Exemplo n.º 3
0
        public string FBLogin(string token)
        {
            try
            {
                WebClient wc = new WebClient();
                wc.Proxy = null;

                string res = wc.DownloadString("https://graph.facebook.com/me?fields=email,name,first_name,last_name,gender&access_token=" + token);
                Dictionary<string, string> response = JsonConvert.DeserializeObject<Dictionary<string, string>>(res);
                if (response.ContainsKey("name"))
                {
                    string id = response["id"];
                    string email = response["email"];
                    database db = new database(database.maindb);
                    db.AddParam("?fbid", id);
                    db.AddParam("?email", email);
                    db.AddParam("?username", response["first_name"]+response["last_name"]);

                    switch (response["gender"])
                    {
                        case "male":
                            db.AddParam("?gender", 1);
                            break;
                        case "female":
                            db.AddParam("?gender", 2);
                            break;
                        default:
                            db.AddParam("?gender", 0);
                            break;
                    }

                    MySqlDataReader rd;

                    rd = db.ExecuteReader("select * from users where facebookid = ?fbid or email = ?email");

                    if (rd.HasRows)
                        while (rd.Read())
                        {
                            Context.Session.SetInt32("on", 1);
                            Context.Session.SetString("email", rd.GetString("email"));
                            Context.Session.SetString("username", rd.GetString("username"));
                            Context.Session.SetInt32("id", rd.GetInt32("id"));
                            Context.Session.SetString("myname", rd.GetString("lastname") + " " + rd.GetString("firstname"));
                            break;
                            // return "2";
                        }
                    else
                    {
                        db.ExecuteNonQuery("insert into users (email,username,gender,facebookid) values (?email,?username,?gender,?fbid)");
                        rd = db.ExecuteReader("select * from users where facebookid = ?fbid or email = ?email");
                        while (rd.Read())
                        {
                            Context.Session.SetInt32("on", 1);
                            Context.Session.SetString("email", rd.GetString("email"));
                            Context.Session.SetInt32("id", rd.GetInt32("id"));
                            Context.Session.SetString("username", rd.GetString("username"));
                            Context.Session.SetInt32("gender", rd.GetInt32("gender"));
                        }
                        //return "3";
                    }

                    db.Close();

                    return "1";
                }
                else
                    return "0";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }