diff --git a/app.rb b/app.rb index 0341cd13..d1eb27c5 100644 --- a/app.rb +++ b/app.rb @@ -12,6 +12,10 @@ before do redirect '/' if request.post? && !csrf_safe? end +not_found do + slim :'not_found' +end + get '/?' do dashboard_if_signed_in slim :index @@ -418,6 +422,38 @@ get '/password_reset_confirm' do redirect '/' end +get '/contact' do + slim :'contact' +end + +post '/contact' do + + @errors = [] + + if params[:email].empty? || params[:subject].empty? || params[:body].empty? + @errors << 'Please fill out all fields' + end + + if !recaptcha_valid? + @errors << 'Captcha was not filled out (or was filled out incorrectly)' + end + + if !@errors.empty? + slim :'contact' + else + EmailWorker.perform_async({ + from: 'web@neocities.org', + replyto: params[:email], + to: 'contact@neocities.org', + subject: "[NeoCities] Contact: #{params[:subject]}", + body: params[:body] + }) + + flash[:success] = 'Your contact has been sent.' + redirect '/' + end +end + def require_admin redirect '/' unless signed_in? && current_site.is_admin end diff --git a/views/about.slim b/views/about.slim index 03fc47c3..b1f14a6c 100644 --- a/views/about.slim +++ b/views/about.slim @@ -52,6 +52,6 @@ h3 Sponsorships, press, speaking invites, general inquiries: - h3: a href="mailto:kyledrake@gmail.com" Contact Me Directly + h3: a href="/contact" Contact Me Directly h4 style="margin-top: 30px; margin-bottom: 30px" Thanks. You are great! Now go and make an awesome web site! diff --git a/views/contact.slim b/views/contact.slim new file mode 100644 index 00000000..a7673dc6 --- /dev/null +++ b/views/contact.slim @@ -0,0 +1,33 @@ +javascript: + var RecaptchaOptions = { + theme : 'clean' + }; + +- if !@errors.empty? + .row + .span8.offset2 + .alert.alert-block.alert-error + - @errors.each do |error| + p = error + +.row + .span8.offset2 + h2 style="margin-bottom: 20px" Contact Us + + form action="/contact" method="POST" + input name="csrf_token" type="hidden" value="#{csrf_token}" + + label Email address + input type="email" name="email" placeholder="Your Email" style="width: 300px" value="#{params[:email]}" + + label Subject + input type="text" name="subject" placeholder="Subject" style="width: 400px" value="#{params[:subject]}" + + label Comments + textarea name="body" style="width: 600px" rows="10" #{params[:body]} + + label Fill out captcha so we know you're not a robot + == recaptcha_tag :challenge, ssl: true + + div style="margin-top: 30px; margin-bottom: 50px" + input.btn.btn-large.btn-success type="submit" value="Send" \ No newline at end of file diff --git a/views/not_found.slim b/views/not_found.slim new file mode 100644 index 00000000..0743718e --- /dev/null +++ b/views/not_found.slim @@ -0,0 +1,7 @@ +.row + .span8.offset2.text-center + h2 Not Found + h4 We could not find the requested page. Our apologies. + h5 It you believe this to be in error, please contact us and report the problem. Thank you! + - if request.referer + a href="#{request.referer}" Go Back \ No newline at end of file