Help - Search - Members - Calendar
Full Version: Multi-Blog, Multi-User - Best Way
Movable Type Community Forum > Additional Resources > Tips and Tricks
CRM114
Hello -

I'd like to set up a Movable Type server for teacher webpages. So, I'd like to be the administrator, create the blog, and tell the teacher how to log in and post and how to view.

What is the best way to do this? Currently, I created a user with all privileges. Then I created some users and gave them access only to their blog (which I created). I had to create their blog and create a new web directory for their blog.

Is there a better way to do this that I am missing? Thanks.
eoligarry
QUOTE
Is there a better way to do this that I am missing?


I've been working on a similar thing. I'm trying to make account creation fairly seamless so that a student here can fill out a form (here: http://sax.pomona.edu/mt/request_weblog.html), the processed text of which is sent to an administrator, and the administrator can run a quick perl script that sets the account up.

Here's part of the code I'm using:

CODE
#!/usr/bin/perl

use lib qw(/Volumes/Backups/Documents/MT-2.64-full-lib/lib);
use lib qw(/Volumes/Backups/Documents/MT-2.64-full-lib/extlib);

## You'll want to change the libs above...I have them listed like that because they are in a different directory than this perl script.

use MT;
use MT::Blog;
use MT::Author;
use MT::Permission;
use MT::Template;
use MT::TemplateMap;

...
...

# this code creates the directories and sets their permissions:
mkdir("$blog_path",0777) or die "Cannot mkdir $blog_path";
   mkdir("$blog_archive_path",0777) or die "Cannot mkdir $blog_archive_path";
chmod(0777,$blog_path)
       or die "Hmm...couldn't chmod $blog_path";
chmod(0777,$blog_archive_path)
       or die "Hmm...couldn't chmod $blog_archive_path";

##
## The following (*all* of the following code) comes nearly
## verbatim out of mt-load.cgi
##
##







  ## Load the appropriate template headers (to be used below when
   ## mapping template IDs and etc.)
   my $tmpl_list;
   eval { $tmpl_list = require 'MT/default-templates.pl' };
   die "Can't find default template list; where is 'default-templates.pl'?\n"
       . "Error: $@\n"
       if $@ || !$tmpl_list || ref($tmpl_list) ne 'ARRAY' || !@$tmpl_list;

   ## Create an instance of the MT object.  This initializes the ObjectDriver
   print "\tInitializing ObjectDriver...\n";
   my $mt = MT->new( Config => $path_to_cfg )
       or die "Error finding (or using) \'mt.cfg\':\n", MT->errstr;

   print "\tLoading new weblog \'$blog_name\'...\n";
   my $blog = MT::Blog->new;
   $blog->name($blog_name);
   $blog->archive_type("Individual,Monthly");
   $blog->archive_type_preferred("Individual");
   $blog->site_path($blog_path);
   $blog->site_url($blog_url);
   $blog->archive_path($blog_archive_path);
   $blog->archive_url($blog_archive_url);
   $blog->server_offset(-8);  # Pacific Standard Time
   $blog->days_on_index(7);
   $blog->words_in_excerpt(40);
   $blog->file_extension('html');
   $blog->convert_paras(1);
   $blog->convert_paras_comments(1);
   $blog->sanitize_spec(0);
   $blog->ping_weblogs(0);
   $blog->ping_blogs(0);
   $blog->allow_comments_default(1);
   $blog->language('en');
   $blog->sort_order_posts('descend');
   $blog->sort_order_comments('ascend');
   $blog->status_default(1);
   $blog->save
       or die $blog->errstr;

 print "\tLoading new user \'$name\'...\n";
   my $author = MT::Author->new;
   $author->name($name);
   $author->set_password($passwd);
   $author->email($email);
   $author->can_create_blog(0);
   $author->can_view_log(0);
   $author->preferred_language('en-us');
   $author->created_by(1);  # Created by the original user...if the user
                            # with ID 1 is deleted, this assignment will
                            # probably fail.  Setting it to null would work,
                            # but then that user will be unaccessible from
                            # any other account, making it essentially un-
                            # deletable from the web interface (though it
                            # would still be possible [though unwise, because
                            # it would mess up the permissions of which user
                            # is associated with which blog] by interacting
                            # with the SQL tables [possibly through
                            # phpMyAdmin] directly.


   $author->save
       or die $author->errstr;

print "\tLoading moveabletype permissions...\n";
   require MT::Permission;
   my $perms = MT::Permission->new;
   $perms->author_id($author->id);
   $perms->blog_id($blog->id);
   $perms->set_full_permissions;
   $perms->can_edit_config(1);
   unless ( $faculty ) {
       $perms->can_edit_authors(0);
       # $perms->can_edit_config(0); ## If you want to take away the permission
                                     ## to edit weblog config, un-comment this.
   }
   $perms->save or die $perms->errstr;

print "\tLoading templates...\n";
   require MT::Template;

   my @arch_tmpl;
   for my $val (@$tmpl_list) {
       $val->{text} = $mt->translate_templatized($val->{text});
       my $obj = MT::Template->new;
       $obj->set_values($val);
       $obj->blog_id($blog->id);
       $obj->save or die $obj->errstr;
       if ($val->{type} eq 'archive' || $val->{type} eq 'individual' ||
           $val->{type} eq 'category') {
           push @arch_tmpl, $obj;
       }
   }

   print "\tMapping templates to blog archive types...\n";
   require MT::TemplateMap;

for my $tmpl (@arch_tmpl) {
       my(@at);
       if ($tmpl->type eq 'archive') {
           @at = qw( Daily Weekly Monthly );
       } elsif ($tmpl->type eq 'category') {
           @at = qw( Category );
       } elsif ($tmpl->type eq 'individual') {
           @at = qw( Individual );
       }
       for my $at (@at) {
           print "\tMapping template ID '", $tmpl->id, "' to '$at'\n";
           my $map = MT::TemplateMap->new or die "Couldn't create map";
           $map->archive_type($at);
           $map->is_preferred(1);
           $map->template_id($tmpl->id);
           $map->blog_id($tmpl->blog_id);
           $map->save
               or die "Save failed: ", $map->errstr;
       }


Some things have been left out of that, but this should give you the idea.

I don't know if it's the best way, but it's faster and easier than doing it by logging into MT from a web browser every time you want to give another person an account...
silentcolors
hi,
i'm also interested in creating some way of automatic account-setting-up and i expected it would be easier than what it actually is. the first problem i've found is the passoword encryption.
so if you have finally set up this piece of code to create accounts through a form or something, i would be sooo grateful (as i see i won't be able to develop it by myself). and if you have, i would of course give you credit...

thank you in advance. smile.gif

PD. i understand php, but i have no idea of perl... sad.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.