Esempio n. 1
0
        /// <summary>
        /// Event handler that gets called when the create button is clicked.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void OnCreateButton_Click(object source, EventArgs e)
        {
            if (!ValidPage)
            {
                TopNav.ShowError(GetString("ALLFIELDSREQUIRED"));
            }
            else
            {
                // Verify that the retyped password matches.
                if (Password.Text == RetypedPassword.Text)
                {
                    try
                    {
                        web.CreateUser(
                            UserName.Text,
                            Password.Text,
                            Guid.NewGuid().ToString(),
                            FirstName.Text,
                            LastName.Text,
                            FullName.Text,
                            String.Empty,
                            String.Empty);

                        // Return back to the referring page.
                        string url = web.TrimUrl(ReferringPage);
                        Page.Response.Redirect(url, true);
                    }
                    catch (Exception ex)
                    {
                        TopNav.ShowError(GetString("ERRORCANNOTCREATEUSER"), ex);
                    }
                }
                else
                {
                    TopNav.ShowError(GetString("PASSWORDSDONOTMATCH"));
                }
            }
        }
Esempio n. 2
0
      /// <summary>
      /// Main to start the execution
      /// </summary>
      /// <param name="args"></param>
      public static void Main(string[] args)
      {
          if (args.Length == 0)
          {
              Console.WriteLine("A command line utility to manage users in a Simias Server domain.");
              Console.WriteLine("UserCmd.exe action <options>");
              return;
          }

          ParseCommandLine(args);

          if (action == "help")
          {
              ShowUseage();
              return;
          }

          if (action == null || url == null)
          {
              Console.WriteLine("missing mandatory command line arguments");
              return;
          }

          if (adminName == null)
          {
              Console.Write("Please enter simias admin: ");
              adminName = Console.ReadLine();

              Console.Write("password: "******"/\:";

          admin.Url  = url.TrimEnd(notEndingWith.ToCharArray());
          admin.Url += "/simias10/iFolderAdmin.asmx";

          if (action == "create")
          {
              if (username == null || password == null)
              {
                  Console.WriteLine("missing mandatory command line arguments");
                  return;
              }

              // Make the web service call to register/create the user
              iFolderUser user = null;

              try
              {
                  user = admin.CreateUser(
                      username,
                      password,
                      null,
                      first,
                      last,
                      full,
                      null,
                      email);

                  if (user != null)
                  {
                      Console.WriteLine("Successful");
                  }
              }
              catch (WebException we)
              {
                  if (we.Message.LastIndexOf("401") != 0)
                  {
                      Console.WriteLine("Failed - Invalid admin credentials");
                  }
                  else
                  {
                      Console.Write("Failed - ");
                      Console.WriteLine(we.Message);
                  }
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Failed creating {0}'s account", username);
              }
          }
          else
          if (action == "delete")
          {
              try
              {
                  bool status = admin.DeleteUser(username);
                  if (verbose == true)
                  {
                      Console.WriteLine("Deleting user {0}  Status {1)", username, status.ToString());
                  }
              }
              catch (WebException we)
              {
                  if (we.Message.LastIndexOf("401") != 0)
                  {
                      Console.WriteLine("Failed - Invalid admin credentials");
                  }
                  else
                  {
                      Console.Write("Failed - ");
                      Console.WriteLine(we.Message);
                  }
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Failed deleting {0}'s account", username);
              }
          }
          else
          if (action == "modify")
          {
              iFolderUser user      = null;
              bool        exception = false;
              try
              {
                  user = admin.GetUser(username);
              }
              catch (WebException we)
              {
                  if (we.Message.LastIndexOf("401") != 0)
                  {
                      Console.WriteLine("Failed - Invalid admin credentials");
                  }
                  else
                  {
                      Console.Write("Failed - ");
                      Console.WriteLine(we.Message);
                  }
                  exception = true;
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Failed deleting {0}'s account", username);
                  exception = true;
              }

              if (user != null)
              {
                  if (quota != null)
                  {
                      bool       changed    = false;
                      UserPolicy userPolicy = admin.GetUserPolicy(user.ID, null);
                      if (quota != null)
                      {
                          if (verbose == true)
                          {
                              Console.WriteLine("Changing quota from {0} to {1}", userPolicy.SpaceLimit, Convert.ToInt64(quota));
                          }
                          userPolicy.SpaceLimit = Convert.ToInt64(quota);
                          changed = true;
                      }

                      if (changed == true)
                      {
                          admin.SetUserPolicy(userPolicy);
                      }
                  }

                  if (email != null || first != null || last != null || full != null)
                  {
                      if (first != null)
                      {
                          user.FirstName = first;
                      }

                      if (last != null)
                      {
                          user.LastName = last;
                      }

                      if (full != null)
                      {
                          user.FullName = full;
                      }

                      if (email != null)
                      {
                          user.Email = email;
                      }

                      // Write the changes
                      admin.SetUser(user.ID, user);
                  }

                  if (password != null)
                  {
                      bool status = admin.SetPassword(username, password);
                      if (verbose == true)
                      {
                          Console.WriteLine("SetPassord for {0} - {1}", username, status.ToString());
                      }
                  }
              }
              else if (exception == false)
              {
                  Console.WriteLine("Failed - user {0} does not exist", username);
              }
          }
          else
          if (action == "list")
          {
              try
              {
                  iFolderUserSet userSet = admin.GetUsers(0, 0);
                  //admin.GetUsersBySearch( SearchProperty.UserName, SearchOperation.BeginsWith, "*", 0, 0 );

                  foreach (iFolderUser user in userSet.Items)
                  {
                      Console.Write("ID: {0}  ", user.ID);
                      Console.Write("User: {0}  ", user.UserName);
                      if (user.FullName != null && user.FullName != "")
                      {
                          Console.Write("Fullname: {0}  ", user.FullName);
                      }

                      Console.Write("Enabled: {0}  ", user.Enabled.ToString());
                      Console.WriteLine();
                  }
              }
              catch (WebException we)
              {
                  if (we.Message.LastIndexOf("401") != 0)
                  {
                      Console.WriteLine("Failed - Invalid admin credentials");
                  }
                  else
                  {
                      Console.Write("Failed - ");
                      Console.WriteLine(we.Message);
                  }
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Failed getting a list of users");
              }
          }
          else
          if (action == "setpwd")
          {
              if (username == null || username == String.Empty || password == null)
              {
                  Console.WriteLine("missing mandatory command line arguments");
                  return;
              }

              try
              {
                  bool status = admin.SetPassword(username, password);
                  Console.WriteLine("SetPassord for {0} - {1}", username, status.ToString());
              }
              catch (WebException we)
              {
                  if (we.Message.LastIndexOf("401") != 0)
                  {
                      Console.WriteLine("Failed - Invalid admin credentials");
                  }
                  else
                  {
                      Console.Write("Failed - ");
                      Console.WriteLine(we.Message);
                  }
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Failed setting {0}'s password", username);
              }
          }
          else
          {
              Console.WriteLine("Error: invalid action");
          }

          return;
      }