Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create multi-user support behind the scenes, but hack it so that we
really only have the single user atm
- Loading branch information
1 parent
0c1b2c7
commit b2cbed0
Showing
24 changed files
with
185 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class ActionsController < ApplicationController | ||
before_filter :authenticate | ||
|
||
def invoke | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
class PhotosController < ApplicationController | ||
before_filter :authenticate | ||
before_filter :initial_photo_scan | ||
|
||
acts_as_iphone_controller :test_mode => true | ||
|
||
def index | ||
@items = Photo.find(:all).map do |p| | ||
@items = Photo.find_all_by_user_id(current_user.id, :all).map do |p| | ||
item = ListModel.new(nil, | ||
render_to_string(:partial => "tile", | ||
:locals => { :item => p}), | ||
photo_url(p)) | ||
user_photo_url(current_user, p)) | ||
end | ||
end | ||
|
||
def show | ||
@item = Photo.find_by_id(params[:id], :limit => 1) | ||
raise "Denied!" unless @item.user_id == current_user.id | ||
@actions = ActionsFramework.actions.select{|x| ActionsFramework[x].can_invoke? @item}.map{|x| ActionsFramework[x]} | ||
end | ||
|
||
def destroy | ||
item = Photo.find_by_id(params[:id], :limit => 1) | ||
raise "Denied!" unless @item.user_id == current_user.id | ||
item.destroy | ||
|
||
redirect_to :action => 'index' | ||
end | ||
|
||
private | ||
|
||
def initial_photo_scan | ||
if Photo.count == 0 | ||
logger.info "No known photos to display, scanning '#{current_user.import_path}'..." | ||
PhotoCollectorWorker.async_collect(:root_folder => current_user.import_path, :user_id => current_user.id) | ||
end | ||
|
||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class SessionsController < Clearance::SessionsController | ||
private | ||
def url_after_create | ||
photos_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class UsersController < Clearance::UsersController | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class Actionentry < ActiveRecord::Base | ||
belongs_to :photo | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class User < ActiveRecord::Base | ||
include Clearance::User | ||
has_many :photos | ||
|
||
before_save :initialize_import_path | ||
|
||
private | ||
|
||
def initialize_import_path | ||
# HACK: This is a constant for now | ||
logger.fatal "WHAT THE FUCK" | ||
self.import_path = PHOTO_IMPORT_FOLDER | ||
end | ||
|
||
class << self | ||
def photo_import_folder | ||
return PHOTO_IMPORT_FOLDER | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
%h2 | ||
Change your password | ||
|
||
%p | ||
Your password has been reset. Choose a new password below. | ||
|
||
- semantic_form_for(:user, | ||
- :url => user_password_path(@user, :token => @user.confirmation_token), | ||
- :html => { :method => :put }) do |form| | ||
= form.error_messages | ||
- form.inputs do | ||
= form.input :password, :as => :password, :label => "Choose password" | ||
= form.input :password_confirmation, :as => :password, :label => "Confirm password" | ||
|
||
- form.buttons do | ||
= form.commit_button "Save this password" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
%h2 | ||
Reset your password | ||
|
||
%p | ||
We will email you a link to reset your password. | ||
- semantic_form_for :password, :url => passwords_path do |form| | ||
- form.inputs do | ||
= form.input :email, :label => "Email address" | ||
- form.buttons do | ||
= form.commit_button "Reset password" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%h2 Sign in | ||
- semantic_form_for :session, :url => session_path do |form| | ||
- form.inputs do | ||
= form.input :email | ||
= form.input :password, :as => :password | ||
- form.buttons do | ||
= form.commit_button "Sign in" | ||
|
||
%ul | ||
%li | ||
= link_to "Sign up", new_user_path | ||
%li | ||
= link_to "Forgot password?", new_password_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#flash | ||
- flash.each do |key, value| | ||
%div{ :id => "flash_#{key}" } | ||
= h value | ||
- end | ||
%div{ :id => "flash_#{key}" } | ||
= h value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- form.inputs do | ||
= form.input :email | ||
= form.input :password | ||
= form.input :password_confirmation, :label => "Confirm password" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%h2 | ||
Sign up | ||
- semantic_form_for @user do |form| | ||
= form.error_messages | ||
= render :partial => "/users/inputs", :locals => { :form => form } | ||
- form.buttons do | ||
= form.commit_button "Sign up" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class ClearanceCreateUsers < ActiveRecord::Migration | ||
def self.up | ||
create_table(:users) do |t| | ||
t.string :email | ||
t.string :encrypted_password, :limit => 128 | ||
t.string :salt, :limit => 128 | ||
t.string :confirmation_token, :limit => 128 | ||
t.string :remember_token, :limit => 128 | ||
t.boolean :email_confirmed, :default => false, :null => false | ||
t.timestamps | ||
end | ||
|
||
add_index :users, [:id, :confirmation_token] | ||
add_index :users, :email | ||
add_index :users, :remember_token | ||
end | ||
|
||
def self.down | ||
drop_table :users | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddUserIdToPhoto < ActiveRecord::Migration | ||
def self.up | ||
add_column :photos, :user_id, :integer | ||
end | ||
|
||
def self.down | ||
remove_column :photos, :user_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddImportPathToUser < ActiveRecord::Migration | ||
def self.up | ||
add_column :users, :import_path, :string | ||
end | ||
|
||
def self.down | ||
remove_column :users, :import_path | ||
end | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Factory.sequence :email do |n| | ||
"user#{n}@example.com" | ||
end | ||
|
||
Factory.define :user do |user| | ||
user.email { Factory.next :email } | ||
user.password { "password" } | ||
user.password_confirmation { "password" } | ||
end | ||
|
||
Factory.define :email_confirmed_user, :parent => :user do |user| | ||
user.email_confirmed { true } | ||
end |