Session token/IP based user authentication added
This commit is contained in:
parent
d866f17405
commit
c87011ff84
3 changed files with 11 additions and 4 deletions
|
|
@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base
|
||||||
# and show them even before moderation.
|
# and show them even before moderation.
|
||||||
def create_user_token
|
def create_user_token
|
||||||
session[:token] ||= SecureRandom.hex
|
session[:token] ||= SecureRandom.hex
|
||||||
|
session[:ip] ||= request.remote_ip
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ class PackagesController < ApplicationController
|
||||||
@package = Package.find_by(name: params[:name])
|
@package = Package.find_by(name: params[:name])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# POST target of the screenshots upload form.
|
||||||
|
# Checks upload images and creates a new Screenshot record for it.
|
||||||
def upload_image
|
def upload_image
|
||||||
@package = Package.find_by(name: params[:name])
|
@package = Package.find_by(name: params[:name])
|
||||||
|
|
||||||
|
|
@ -33,13 +35,15 @@ class PackagesController < ApplicationController
|
||||||
new_screenshot = @package.screenshots.new(image: img)
|
new_screenshot = @package.screenshots.new(image: img)
|
||||||
|
|
||||||
# Check if the image was valid
|
# Check if the image was valid
|
||||||
unless new_screenshot.valid?
|
if new_screenshot.valid?
|
||||||
errors = new_screenshot.errors[:image].join(' and ')
|
new_screenshot.uploaderhash = session[:token]
|
||||||
flash['alert'] = "Sorry - the image #{errors}"
|
new_screenshot.uploaderip = session[:ip]
|
||||||
else
|
|
||||||
new_screenshot.save
|
new_screenshot.save
|
||||||
successful_upload_count += 1
|
successful_upload_count += 1
|
||||||
Log.log "Screenshot #{new_screenshot.id} uploaded successfully."
|
Log.log "Screenshot #{new_screenshot.id} uploaded successfully."
|
||||||
|
else
|
||||||
|
errors = new_screenshot.errors[:image].join(' and ')
|
||||||
|
flash['alert'] = "Sorry - the image #{errors}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if successful_upload_count > 0
|
if successful_upload_count > 0
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@
|
||||||
a.black.fancybox href=screenshot.image.url(:large, timestamp: false) rel='fancybox-thumb' title=screenshot.caption
|
a.black.fancybox href=screenshot.image.url(:large, timestamp: false) rel='fancybox-thumb' title=screenshot.caption
|
||||||
= image_tag(screenshot.image.url(:large, timestamp: false), alt: screenshot.caption)
|
= image_tag(screenshot.image.url(:large, timestamp: false), alt: screenshot.caption)
|
||||||
.imgcaption =screenshot.caption
|
.imgcaption =screenshot.caption
|
||||||
|
// TODO: Show information only if admin
|
||||||
|
p Uploader IP=#{screenshot.uploaderip} / Token=#{screenshot.uploaderhash}
|
||||||
// TODO: Enable button only if admin or uploader
|
// TODO: Enable button only if admin or uploader
|
||||||
a.button.tiny.alert[
|
a.button.tiny.alert[
|
||||||
href=delete_screenshot_path(@package.name, screenshot.id)
|
href=delete_screenshot_path(@package.name, screenshot.id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue