Permalink
Browse files

initial import

  • Loading branch information...
leafo committed Nov 30, 2012
0 parents commit c9159e9356e4dbc89b07295f402da66010d67386
@@ -0,0 +1,5 @@
+*.lua
+.tup
+logs/
+lapis
+nginx.conf.compiled
@@ -0,0 +1,3 @@
+# MoonRocks
+
+Hello!
@@ -0,0 +1 @@
+include_rules
@@ -0,0 +1 @@
+: foreach *.moon |> moonc %f |> %B.lua
@@ -0,0 +1,80 @@
+
+types {
+ text/html html htm shtml;
+ text/css css;
+ text/xml xml;
+ image/gif gif;
+ image/jpeg jpeg jpg;
+ application/x-javascript js;
+ application/atom+xml atom;
+ application/rss+xml rss;
+
+ text/mathml mml;
+ text/plain txt;
+ text/vnd.sun.j2me.app-descriptor jad;
+ text/vnd.wap.wml wml;
+ text/x-component htc;
+
+ image/png png;
+ image/tiff tif tiff;
+ image/vnd.wap.wbmp wbmp;
+ image/x-icon ico;
+ image/x-jng jng;
+ image/x-ms-bmp bmp;
+ image/svg+xml svg svgz;
+ image/webp webp;
+
+ application/java-archive jar war ear;
+ application/mac-binhex40 hqx;
+ application/msword doc;
+ application/pdf pdf;
+ application/postscript ps eps ai;
+ application/rtf rtf;
+ application/vnd.ms-excel xls;
+ application/vnd.ms-powerpoint ppt;
+ application/vnd.wap.wmlc wmlc;
+ application/vnd.google-earth.kml+xml kml;
+ application/vnd.google-earth.kmz kmz;
+ application/x-7z-compressed 7z;
+ application/x-cocoa cco;
+ application/x-java-archive-diff jardiff;
+ application/x-java-jnlp-file jnlp;
+ application/x-makeself run;
+ application/x-perl pl pm;
+ application/x-pilot prc pdb;
+ application/x-rar-compressed rar;
+ application/x-redhat-package-manager rpm;
+ application/x-sea sea;
+ application/x-shockwave-flash swf;
+ application/x-stuffit sit;
+ application/x-tcl tcl tk;
+ application/x-x509-ca-cert der pem crt;
+ application/x-xpinstall xpi;
+ application/xhtml+xml xhtml;
+ application/zip zip;
+
+ application/octet-stream bin exe dll;
+ application/octet-stream deb;
+ application/octet-stream dmg;
+ application/octet-stream eot;
+ application/octet-stream iso img;
+ application/octet-stream msi msp msm;
+
+ audio/midi mid midi kar;
+ audio/mpeg mp3;
+ audio/ogg ogg;
+ audio/x-m4a m4a;
+ audio/x-realaudio ra;
+
+ video/3gpp 3gpp 3gp;
+ video/mp4 mp4;
+ video/mpeg mpeg mpg;
+ video/quicktime mov;
+ video/webm webm;
+ video/x-flv flv;
+ video/x-m4v m4v;
+ video/x-mng mng;
+ video/x-ms-asf asx asf;
+ video/x-ms-wmv wmv;
+ video/x-msvideo avi;
+}
@@ -0,0 +1,51 @@
+
+db = require "lapis.db"
+bcrypt = require "bcrypt"
+
+import Model from require "lapis.db.model"
+import slugify, underscore from require "lapis.util"
+
+class Users extends Model
+ @timestamp: true
+
+ @create: (username, password, email) =>
+ encrypted_password = bcrypt.digest password, bcrypt.salt 5
+ slug = slugify username
+
+ if @check_unique_constraint "username", username
+ return nil, "Username already taken"
+
+ if @check_unique_constraint "slug", slug
+ return nil, "Username already taken"
+
+ if @check_unique_constraint "email", email
+ return nil, "Email already taken"
+
+ Model.create @, {
+ :username, :encrypted_password, :email, :slug
+ }
+
+ @login: (username, password) =>
+ user = Users\find { :username }
+ if user and bcrypt.verify password, user.encrypted_password
+ user
+ else
+ nil, "Incorrect username or password"
+
+ @read_session: (r) =>
+ if user_session = r.session.user
+ user = @find user_session.id
+ if user\salt! == user_session.key
+ user
+
+ write_session: (r) =>
+ r.session.user = {
+ id: @id
+ key: @salt!
+ }
+
+ salt: =>
+ @encrypted_password\sub 1, 29
+
+
+{ :Users }
@@ -0,0 +1,65 @@
+worker_processes 1;
+error_log stderr notice;
+daemon off;
+
+events {
+ worker_connections 1024;
+}
+
+
+http {
+ include mime.types;
+
+ upstream database {
+ postgres_server ${{pg HEROKU_POSTGRESQL_ROSE_URL}};
+ }
+
+ server {
+ listen ${{PORT}};
+ lua_code_cache off;
+
+ location / {
+ default_type text/html;
+ set $_url "";
+ content_by_lua_file "web.lua";
+ }
+
+ location /static/ {
+ alias static/;
+ }
+
+ location /favicon.ico {
+ alias static/favicon.ico;
+ }
+
+ location = /query {
+ internal;
+ postgres_pass database;
+ postgres_query $echo_request_body;
+ }
+
+ location = /proxy {
+ internal;
+
+ rewrite_by_lua "
+ local req = ngx.req
+
+ for k,v in pairs(req.get_headers()) do
+ if k ~= 'content-length' then
+ req.clear_header(k)
+ end
+ end
+
+ if ngx.ctx.headers then
+ for k,v in pairs(ngx.ctx.headers) do
+ req.set_header(k, v)
+ end
+ end
+ ";
+
+ resolver 8.8.8.8;
+ proxy_http_version 1.1;
+ proxy_pass $_url;
+ }
+ }
+}
@@ -0,0 +1,7 @@
+dependencies = {
+ "https://raw.github.com/leafo/heroku-openresty/master/heroku-openresty-dev-1.rockspec",
+ "https://raw.github.com/leafo/lua-date/master/date-dev-1.rockspec",
+ "https://raw.github.com/leafo/cloud_storage/master/cloud_storage-dev-1.rockspec",
+ "https://raw.github.com/leafo/lapis/master/lapis-dev-1.rockspec"
+}
+
Oops, something went wrong.

0 comments on commit c9159e9

Please sign in to comment.