Exemple #1
0
 static void TestRegisterUser()
 {
     // Test RegisterUser()
     try
     {
         PrintTitle("Testing RegisterUser()");
         FoeServerUser.RegisterUser(sampleEmail);
         Console.WriteLine("User registered.");
     }
     catch (Exception except)
     {
         Console.WriteLine(except.ToString());
     }
 }
Exemple #2
0
        private void DoRegistration()
        {
            SqlConnection conn         = FoeServerDb.OpenDb();
            SqlConnection completeConn = FoeServerDb.OpenDb();

            // Query that gets all pending requests.
            SqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = "select * from Requests where Status='P' and ProcessorEmail=@processorEmail and RequestType=@requestType";
            cmd.Parameters.Add("@processorEmail", System.Data.SqlDbType.NVarChar, 256);
            cmd.Parameters.Add("@requestType", System.Data.SqlDbType.NVarChar, 10);
            cmd.Prepare();

            // Query that marks request as "C" (Completed)
            SqlCommand completeCmd = completeConn.CreateCommand();

            completeCmd.CommandText = "update Requests set DtProcessed=@dtProcessed, Status='C' where id=@id";
            completeCmd.Parameters.Add("@dtProcessed", System.Data.SqlDbType.DateTime);
            completeCmd.Parameters.Add("@id", System.Data.SqlDbType.Int);
            completeCmd.Prepare();

            //FoeDebug.Print("Getting pending requests.");

            // Get all pending requests
            cmd.Parameters["@processorEmail"].Value = FoeServerRegistry.Get("ProcessorEmail");
            cmd.Parameters["@requestType"].Value    = FoeServerRequest.RequestTypeToString(RequestType.Registration);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                int    id        = (int)FoeServerDb.GetInt32(reader, "Id");
                string userEmail = FoeServerDb.GetString(reader, "UserEmail");
                string requestId = FoeServerDb.GetString(reader, "RequestId");

                //FoeDebug.Print("Processing " + userEmail);

                // Create new user account
                FoeUser user = FoeServerUser.RegisterUser(userEmail);

                // Mark request as "C" (Completed)
                completeCmd.Parameters["@dtProcessed"].Value = DateTime.Now;
                completeCmd.Parameters["@id"].Value          = id;
                completeCmd.ExecuteNonQuery();

                // Send response back to user
                SmtpServer server  = FoeServerMessage.GetDefaultSmtpServer();
                string     subject = "Re: Register " + requestId + " by Newbie";

                FoeServerMessage.SendMessage(server, FoeServerRegistry.Get("ProcessorEmail"), user.Email, subject, user.UserId);

                FoeServerLog.Add(_processName, FoeServerLog.LogType.Message, "Completed registration for " + userEmail);

                //FoeDebug.Print("Sent reply to " + userEmail);
                //FoeDebug.Print("");
            }
            reader.Close();

            // Close connections
            conn.Close();
            completeConn.Close();
        }