Session token/IP based user authentication added

This commit is contained in:
Christoph Haas 2015-06-14 12:33:18 +02:00
parent d866f17405
commit c87011ff84
3 changed files with 11 additions and 4 deletions

View file

@ -24,6 +24,8 @@ class PackagesController < ApplicationController
@package = Package.find_by(name: params[:name])
end
# POST target of the screenshots upload form.
# Checks upload images and creates a new Screenshot record for it.
def upload_image
@package = Package.find_by(name: params[:name])
@ -33,13 +35,15 @@ class PackagesController < ApplicationController
new_screenshot = @package.screenshots.new(image: img)
# Check if the image was valid
unless new_screenshot.valid?
errors = new_screenshot.errors[:image].join(' and ')
flash['alert'] = "Sorry - the image #{errors}"
else
if new_screenshot.valid?
new_screenshot.uploaderhash = session[:token]
new_screenshot.uploaderip = session[:ip]
new_screenshot.save
successful_upload_count += 1
Log.log "Screenshot #{new_screenshot.id} uploaded successfully."
else
errors = new_screenshot.errors[:image].join(' and ')
flash['alert'] = "Sorry - the image #{errors}"
end
if successful_upload_count > 0