コード例 #1
0
        public static string JoinClass(string CommandPara)
        {
            SQLManager.Connection.Close();

            JoinClassCommand Command = new JoinClassCommand();
            ResultWithNoData Result  = new ResultWithNoData();

            Command = JsonConvert.DeserializeObject <JoinClassCommand>(CommandPara);

            CodeEMailCIDSafe tmp = InviteCodesSafe.getData(Command.EMail);

            if (tmp == null)
            {
                Result.statusCode = 202;
                return(JsonConvert.SerializeObject(Result));
            }

            if (Command.Code == tmp.Code)
            {
                InviteCodesSafe.RemoveData(Command.EMail);
                using (MySqlCommand mysqlCommand = SQLManager.Connection.CreateCommand())
                {
                    SQLManager.Connection.Open();
                    mysqlCommand.CommandText = "UPDATE `users` SET `CID` = '" + tmp.CID + "' WHERE `EMail` = '" + Command.EMail + "'";

                    mysqlCommand.ExecuteNonQuery();

                    SQLManager.Connection.Close();
                }

                using (MySqlCommand mysqlCommand = SQLManager.Connection.CreateCommand())
                {
                    SQLManager.Connection.Open();

                    mysqlCommand.CommandText = "UPDATE users SET HasSelected = 1 WHERE EMail = ?email";

                    mysqlCommand.Parameters.AddWithValue("?email", Command.EMail);

                    mysqlCommand.ExecuteNonQuery();

                    SQLManager.Connection.Close();
                }

                Result.statusCode = 201;
            }
            else
            {
                Result.statusCode = 202;
            }

            return(JsonConvert.SerializeObject(Result));
        }
コード例 #2
0
        private static string SendInvite(string CommandPara)
        {
            SQLManager.Connection.Close();

            SendInviteCommand Command = new SendInviteCommand();
            ResultWithNoData  Result  = new ResultWithNoData();
            Random            rand    = new Random();
            int cid = 0;

            Command = JsonConvert.DeserializeObject <SendInviteCommand>(CommandPara);

            if (CheckUserData(Command.EMail, Command.Hash) == false)
            {
                Result.statusCode = 270;

                return(JsonConvert.SerializeObject(Result));
            }

            using (MySqlCommand mysqlCommand = SQLManager.Connection.CreateCommand())
            {
                SQLManager.Connection.Open();

                mysqlCommand.CommandText = "SELECT CID FROM classes WHERE Creator='" + Command.EMail + "'";

                MySqlDataReader mysqlreader;

                mysqlreader = mysqlCommand.ExecuteReader();

                if (mysqlreader.HasRows)
                {
                    mysqlreader.Read();

                    cid = mysqlreader.GetInt32("CID");
                }
                else
                {
                    mysqlreader.Close();
                    SQLManager.Connection.Close();
                    return(JsonConvert.SerializeObject(Result));
                }

                mysqlreader.Close();
                SQLManager.Connection.Close();
            }

            using (MySqlCommand mysqlCommand = SQLManager.Connection.CreateCommand())
            {
                mysqlCommand.CommandText = "SELECT EMail FROM users WHERE EMail='" + Command.EMail_Target + "'";

                SQLManager.Connection.Open();
                MySqlDataReader mysqlreader;

                mysqlreader = mysqlCommand.ExecuteReader();

                if (mysqlreader.HasRows)
                {
                    mysqlreader.Read();

                    string MySQL_EMail = mysqlreader.GetString("EMail");
                    if (MySQL_EMail.Equals(Command.EMail_Target, StringComparison.InvariantCultureIgnoreCase))
                    {
                        mysqlreader.Close();
                        SQLManager.Connection.Close();
                    }
                    else
                    {
                        mysqlreader.Close();
                        SQLManager.Connection.Close();
                        Result.statusCode = 202;
                        return(JsonConvert.SerializeObject(Result));
                    }
                }
                else
                {
                    mysqlreader.Close();
                    SQLManager.Connection.Close();
                    Result.statusCode = 202;
                    return(JsonConvert.SerializeObject(Result));
                }
            }

            int random = rand.Next(0, 999999);

            Mail_Server.sendClassInviteCode(random, Command.EMail_Target);

            InviteCodesSafe.addData(Command.EMail_Target, random, cid);

            Result.statusCode = 201;

            return(JsonConvert.SerializeObject(Result));
        }