not found page, contacts

This commit is contained in:
Kyle Drake 2013-07-13 10:45:15 -04:00
parent 3995a64db1
commit d7819fd25f
4 changed files with 77 additions and 1 deletions

36
app.rb
View file

@ -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

View file

@ -52,6 +52,6 @@
</form>
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!

33
views/contact.slim Normal file
View file

@ -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"

7
views/not_found.slim Normal file
View file

@ -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 <a href="/contact">contact us</a> and report the problem. Thank you!
- if request.referer
a href="#{request.referer}" Go Back