Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merged with master branch

  • Loading branch information...
commit 739850ec6095e42c3aac17bfcec3ec197c856aae 1 parent c184837
Ivan Penchev authored
Showing with 51 additions and 18 deletions.
  1. +9 −3 README
  2. +42 −15 mojoforum.pl
12 README
View
@@ -8,11 +8,17 @@ Developed by Ivan Penchev for Google Code-in Contest.
HOW-TO INSTALL:
1. Install Perl - http://learn.perl.org/installing/
-2. Install Mojolicious Framework -http://mojolicio.us/
-3. Download the Mojoforum application and run it through cmd or terminal:
+2. Download the Mojoforum application and install it through cmd/terminal:
+perl Makefile.PL
+cpanm --installdeps .
+
+Note that if you don't have cpanm, you can install it like this:
+$ curl -L cpanmin.us | perl - --sudo App::cpanminus
+
+3. Start the application:
/path/to/mojoforum.pl daemon
4. Open your browser and load the app's home page which will be http://127.0.0.1:3000/.
-If the database file is missing the app should be automatically installed.
+If the database file is missing or empty the app should be automatically installed.
IMPORTANT: data directory should have write access permissions
57 mojoforum.pl
View
@@ -4,9 +4,9 @@
use DBI;
-my $ver = 0.1;
-my $dbfile = 'data/mojoblog.sqlite';
-my $conn = DBI->connect("dbi:SQLite:dbname=$dbfile", '', '');
+my $ver = '0.1.1';
+my $dbfile = 'data/mojoforum.sqlite';
+my $conn = DBI->connect("dbi:SQLite:dbname=$dbfile", '', '',{sqlite_unicode=>1});
helper db => sub {
return $conn;
@@ -40,7 +40,7 @@
posts int default 0,
published datetime not null
)
- }, undef, 'DONE') or die $self->db->errstr;
+ }) or die $self->db->errstr;
$self->db->do( q{
CREATE TABLE IF NOT EXISTS posts (
id integer primary key autoincrement not null,
@@ -50,24 +50,27 @@
topic_id integer not null,
published datetime not null
)
- }, undef, 'DONE') or die $self->db->errstr;
+ }) or die $self->db->errstr;
$self->db->do( q{
CREATE TABLE IF NOT EXISTS users (
id integer primary key autoincrement not null,
- username varchar not null,
- email varchar,
+ email varchar not null,
password varchar not null,
name varchar,
account_type int default 0 not null
)
});
- my $username = 'admin';
- my $password = sha1_sum 'admin';
- $self->db->do( qq{
- INSERT INTO users (username, password, account_type) VALUES ('$username', '$password', -1)
- });
$self->render;
}
+} => 'install';
+
+post '/install/admin/create/' => sub {
+ my $self = shift;
+ my $email = $self->param('admin_email');
+ my $password = sha1_sum $self->param('admin_password');
+ $self->db->do( qq{
+ INSERT INTO users (email, password, account_type) VALUES ('$email', '$password', -1)
+ });
} => 'installed';
get '/new/topic' => 'newtopic';
@@ -91,7 +94,7 @@
my $date_published = DateTime->now;
$self->db->do( qq{
INSERT INTO posts (title, author, content, topic_id, published) VALUES ('$post_title', '$post_author', '$post_content', '$topic_id', '$date_published')
- }, undef, 'DONE') or die $self->db->errstr;
+ }) or die $self->db->errstr;
$self->db->do( qq { UPDATE topics SET posts=posts+1 WHERE id=$topic_id } );
$self->redirect_to("/topic/$topic_id");
};
@@ -103,7 +106,7 @@
my $date_published = DateTime->now;
$self->db-> do( qq{
INSERT INTO topics (title, author, published) VALUES ('$topic_title', '$topic_author', '$date_published')
- }, undef, 'DONE') or die $self->db->errstr;
+ }) or die $self->db->errstr;
$self->redirect_to('/');
};
@@ -162,10 +165,34 @@
<a href="/new/post/<%= @$topic[0]->{id} %>" class="btn large primary"> New Post </a>
</div>
+@@ install.html.ep
+% title 'Forum database successfully installed :: Registration';
+% layout 'main';
+<h2> Your forum database was successfully installed </h2>
+<h5>Now please enter email and password for your admin account.</h5>
+<form method="post" action="/install/admin/create">
+ <div class="clearfix">
+ <label>Email:</label>
+ <div class="input">
+ <input type="text" name="admin_email">
+ </div>
+ </div>
+ <div class="clearfix">
+ <label>Password:</label>
+ <div class="input">
+ <input type="password" name="admin_password">
+ </div>
+ </div>
+ <div class="actions">
+ <input type="submit" class="btn primary" value="Create">
+ </div>
+</form>
+
@@ installed.html.ep
% title 'Forum successfully installed';
% layout 'main';
-<h2> Your forum was successfully installed </h2>
+<h2>Congratulations! Your forum was succesfully installed.</h2>
+<p> Now you can invite all your friends and let the fun begin. </p>
<a href="/">Go back to the home page</a>
@@ newpost.html.ep
Please sign in to comment.
Something went wrong with that request. Please try again.