mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
add logic for tutorial requirement
This commit is contained in:
parent
01aab733bb
commit
2ff8365651
9 changed files with 32 additions and 9 deletions
|
@ -104,6 +104,10 @@ post '/create' do
|
|||
return {result: 'error'}.to_json
|
||||
end
|
||||
|
||||
if defined?(BlackBox.tutorial_required?) && BlackBox.tutorial_required?(@site, request)
|
||||
@site.tutorial_required = true
|
||||
end
|
||||
|
||||
if !@site.valid?
|
||||
flash[:error] = @site.errors.first.last.first
|
||||
return {result: 'error'}.to_json
|
||||
|
|
|
@ -38,5 +38,15 @@ get '/tutorial/:section/:page/?' do
|
|||
|
||||
@title = "#{params[:section].upcase} Tutorial - #{@page}/10"
|
||||
|
||||
|
||||
if @page == '9'
|
||||
unless csrf_safe?
|
||||
signout
|
||||
redirect '/'
|
||||
end
|
||||
current_site.tutorial_required = false
|
||||
current_site.save_changes validate: false
|
||||
end
|
||||
|
||||
erb "tutorial/layout".to_sym
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ end
|
|||
|
||||
def require_login
|
||||
redirect '/' unless signed_in? && current_site
|
||||
redirect '/tutorial/html/1' if current_site.tutorial_required && !(request.path =~ /tutorial/)
|
||||
end
|
||||
|
||||
def signed_in?
|
||||
|
|
9
migrations/124_sites_tutorial_required.rb
Normal file
9
migrations/124_sites_tutorial_required.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
Sequel.migration do
|
||||
up {
|
||||
DB.add_column :sites, :tutorial_required, :boolean, default: false
|
||||
}
|
||||
|
||||
down {
|
||||
DB.drop_column :sites, :tutorial_required
|
||||
}
|
||||
end
|
|
@ -41,7 +41,9 @@
|
|||
</li>
|
||||
<li class="divider"></li>
|
||||
<% end %>
|
||||
<% unless current_site.tutorial_required %>
|
||||
<li><a href="/dashboard">Edit</a></li>
|
||||
<% end %>
|
||||
<li><a href="<%= current_site.uri %>" target="_blank">View</a></li>
|
||||
<li><a href="/site/<%= current_site.username %>/stats">Stats</a></li>
|
||||
<li class="divider"></li>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<div class="stat tips"><strong><%= site.tips_dataset.count %></strong> <span>tips</span></div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<% if current_site == site %>
|
||||
<% if current_site == site && !current_site.tutorial_required %>
|
||||
<a href="/dashboard" class="btn-Action edit"><i class="fa fa-edit" title="Edit"></i> Edit Site</a>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
</div>
|
||||
|
||||
<script>
|
||||
sessionStorage.setItem('tutorialHtml', '')
|
||||
$('#checkButton').on('click', function(button) {
|
||||
checkHomework($('#nameInput').val())
|
||||
})
|
||||
|
|
|
@ -44,6 +44,6 @@
|
|||
}
|
||||
|
||||
sessionStorage.setItem('tutorialHtml', html)
|
||||
ok('Great, you did it!', '/tutorial/html/9')
|
||||
ok('Great, you did it!', '/tutorial/html/9?csrf_token=<%= Rack::Utils.escape csrf_token %>')
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
$('#saveToSite').on('click', function() {
|
||||
$.ajax({
|
||||
url: '/site_files/save/index.html?csrf_token=<%= Rack::Utils.escape csrf_token %>',
|
||||
url: '/site_files/upload?csrf_token=<%= Rack::Utils.escape csrf_token %>&filename=<%= Rack::Utils.escape 'index.html' %>&site_id=<%= current_site.id %>',
|
||||
data: sessionStorage.getItem('tutorialHtml'),
|
||||
processData: false,
|
||||
contentType: false,
|
||||
|
@ -29,11 +29,7 @@
|
|||
alert('There has been an error saving your file, please try again. If it continues to fail, make a copy of the file locally so you don\'t lose your changes!')
|
||||
},
|
||||
success: function(response){
|
||||
if(response == 'ok') {
|
||||
window.location = '/tutorial/html/10'
|
||||
} else {
|
||||
alert('There has been an error saving your file, please try again. If it continues to fail, make a copy of the file locally so you don\'t lose your changes!')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue