Skip to content

Commit

Permalink
Disabled Tests (dep didnt like docker), removed MLH + their sponsors …
Browse files Browse the repository at this point in the history
…branding, allowed names to be set from the editor (so no MyMLH)
  • Loading branch information
bahorn committed Mar 7, 2019
1 parent bae0bb1 commit 7c18c19
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 112 deletions.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ruby:latest

COPY ./ /app/

WORKDIR /app/

# Setup
RUN bundle install

CMD /app/bootstrap.sh
13 changes: 2 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ruby '2.4.0'
ruby '2.5.3'
source 'https://rubygems.org'

gem 'activemodel-serializers-xml'
Expand All @@ -11,6 +11,7 @@ gem 'sinatra-contrib'
gem 'zippy'
gem 'omniauth'
gem 'omniauth-mlh'
gem 'foreman'

group :development do
gem 'sinatra-reloader'
Expand All @@ -20,13 +21,3 @@ group :development, :test do
gem 'pry'
gem 'rake'
end

group :test do
gem 'capybara'
gem 'capybara-webkit'
gem 'capybara_minitest_spec'
gem 'database_cleaner'
gem 'faker'
gem 'minitest'
gem 'rack-test'
end
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PKG=covhacksoc/no-light
TAG=latest

PORT=8000

build:
docker build -t $(PKG):$(TAG) .

run:
docker run -p $(PORT):$(PORT) -e PORT=$(PORT) -it $(PKG):$(TAG)
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: rackup config.ru -p $PORT
web: rackup config.ru -p $PORT -o 0.0.0.0
2 changes: 2 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
foreman start
90 changes: 25 additions & 65 deletions no_light_sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ class NoLightSinatra < Sinatra::Base
use Airbrake::Rack::Middleware unless ENV['RACK_ENV'] == 'test'
enable :sessions

use OmniAuth::Builder do
provider :mlh, ENV['MY_MLH_KEY'], ENV['MY_MLH_SECRET'], scope: 'default'
end

set public_folder: 'public', static: true

configure do
DEFAULT_BRANDING = ''
ENVIRONMENTS = {
'development' => { 'uri' => 'mongodb://localhost/no_light_development' },
'test' => { 'uri' => 'mongodb://localhost/no_light_test' },
'development' => { 'uri' => 'mongodb://192.168.0.40/no_light_development' },
'test' => { 'uri' => 'mongodb://192.168.0.40/no_light_test' },
'production' => { 'uri' => ENV['MONGODB_URI'] }
}

Expand All @@ -39,81 +35,45 @@ class NoLightSinatra < Sinatra::Base
erb :default_page
end

get '/auth/mlh/callback' do
auth = request.env["omniauth.auth"]
session[:user_id] = auth["uid"]
session[:full_name] = "#{auth[:info][:first_name]} #{auth[:info][:last_name]}"
next_page = session[:redirect]

if next_page
session[:redirect] = nil
redirect '%s' % next_page
else
redirect '/'
end
end

get '/logout' do
session.clear
redirect '/'
end


post '/submit' do
authorize do
@submission = Submission.new(get_submit_params)

if @submission.already_exists?
erb :error, locals: {
title: "Error - Already Submitted",
message: "You have already submitted this code under your name (\"#{@submission.name}\")."
}
else
@submission.save
erb :submitted
end
@submission = Submission.new(get_submit_params)
if @submission.already_exists?
erb :error, locals: {
title: "Error - Already Submitted",
message: "You have already submitted this code under your name (\"#{@submission.name}\")."
}
else
@submission.save
erb :submitted
end
end

get '/:hackathon.zip' do
authorize do
@submissions = Submission.by_hackathon(params[:hackathon])
@submissions = Submission.by_hackathon(params[:hackathon])

if @submissions.count > 0
create_zip_folder(@submissions)
set_response_headers
download_zip_folder
else
erb :error, locals: {
title: "Error - No Submissions",
message: "We did not receive any submissions for your event (\"#{params[:hackathon]}\")."
}
end
if @submissions.count > 0
create_zip_folder(@submissions)
set_response_headers
download_zip_folder
else
erb :error, locals: {
title: "Error - No Submissions",
message: "We did not receive any submissions for your event (\"#{params[:hackathon]}\")."
}
end
end

get '/:hackathon' do
authorize do
show_editor(DEFAULT_BRANDING)
end
show_editor(DEFAULT_BRANDING)
end

get '/:hackathon/:branding?' do
authorize do
show_editor(params[:branding])
end
show_editor(params[:branding])
end

private

def authorize
if session[:user_id]
yield
else
session[:redirect] = request.fullpath
redirect '/auth/mlh'
end
end

def show_editor(custom_branding)
@body_class = ['editor', custom_branding].join(' ')
erb :editor
Expand All @@ -127,7 +87,7 @@ def get_submit_params
get_submit_params = params[:submission] || {}
get_submit_params.merge({
'seconds' => seconds_from(params[:submission][:seconds]),
'name' => session[:full_name]
'name' => params[:submission][:name]
})
end

Expand Down
25 changes: 6 additions & 19 deletions public/css/extended.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
src: url('/fonts/code-new-roman.otf');
}

@font-face {
font-family: 'MLH Outage';
src: url('/fonts/outage.ttf');
}

/** GENERAL STYLING **/

html, body {
Expand All @@ -35,22 +30,14 @@ body.editor {
text-align: center;
}

/** LOGO **/

#container a.mlh {
display: block;

background: url("/img/mlh/mlh.png") no-repeat center center;
background-size: auto 90px;

width: 100%;
height: 180px;
}

#container img {
max-width: 40%;
}

#gamelink {
color: #333;
}

/** HEADER **/

header {
Expand All @@ -70,7 +57,7 @@ header #submit {
padding: 15px;
background: #999;
vertical-align: top;
font-family: 'MLH Outage', 'Arial', 'Verdana', 'Times New Roman';
font-family: 'Arial', 'Verdana', 'Times New Roman';
}

header #submit:active {
Expand Down Expand Up @@ -120,7 +107,7 @@ form {
border-bottom: 2px solid #eee;
color: #333;
margin: 20px 0;
font-family: 'MLH Outage', 'Arial', 'Verdana', 'Times New Roman';
font-family: 'Arial', 'Verdana', 'Times New Roman';
}

#container h1.error {
Expand Down
Binary file removed public/fonts/outage.ttf
Binary file not shown.
Binary file removed public/img/mlh/mlh-white.png
Binary file not shown.
Binary file removed public/img/mlh/mlh.png
Binary file not shown.
Binary file removed public/img/sponsors/blackrock.png
Binary file not shown.
Binary file removed public/img/sponsors/bloomberg.png
Binary file not shown.
Binary file removed public/img/sponsors/dell-windows.png
Binary file not shown.
Binary file removed public/img/sponsors/github.png
Binary file not shown.
Binary file removed public/img/sponsors/kcl.png
Binary file not shown.
6 changes: 2 additions & 4 deletions views/default_page.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div id="container">
<a href="https://mlh.io" target="_blank" class="mlh" alt="Major League Hacking" title="Major League Hacking"></a>

<h1>Welcome</h1>
<p>To use, visit <strong>http://no-light.mlh.io/[enter hackathon name]</strong></p>
</div>
<p>To play, click <strong><a href="/covhack2019" class="gamelink">here</a></strong></p>
</div>
8 changes: 2 additions & 6 deletions views/editor.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
<input type="hidden" name="submission[seconds]" value="<%= Time.now %>" id="submission_seconds" />

<header>
<input type="text" id="submission_name" name="submission[name]" placeholder="Nickname..."/>
<button type="submit" id="submit">!light</button> <!-- Submit button -->

<div id="sponsors">
<img src="/img/mlh/mlh-white.png" alt="Major League Hacking" title="Major League Hacking">
<div class="custom-branding"></div>
</div>
</header>

<textarea name="submission[html]" id="submission_html" spellcheck="false" placeholder="Enter your code here ..."></textarea>
Expand All @@ -17,4 +13,4 @@
<div id="characters"><em>0</em> CHARS</div>
<div id="lines"><em>0</em> LINES</div>
</div>
</form>
</form>
3 changes: 1 addition & 2 deletions views/error.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div id="container">
<a href="https://mlh.io" target="_blank" class="mlh"></a>
<h1 class="error"><%= title %></h1>
<p><%= message %></p>
</div>
</div>
4 changes: 2 additions & 2 deletions views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<title>No Light Powered by MLH</title>
<title>No Light</title>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
Expand All @@ -31,4 +31,4 @@
</p>
<% end %>
</body>
</html>
</html>
2 changes: 0 additions & 2 deletions views/submitted.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div id="container">
<a href="https://mlh.io" target="_blank" class="mlh"></a>

<h1>Submission received - <%= @submission.name %></h1><br>
<span id="code">
It took you <%= @submission.to_min_secs %> minutes.
Expand Down

0 comments on commit 7c18c19

Please sign in to comment.