scottmotte-merb_auth_slice_multisite 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/app/controllers/application.rb +5 -0
- data/app/helpers/application_helper.rb +64 -0
- data/app/models/site.rb +36 -0
- data/app/views/layout/merb_auth_slice_multisite.html.erb +16 -0
- data/config/database.yml +33 -0
- data/config/dependencies.rb +34 -0
- data/config/init.rb +76 -0
- data/config/router.rb +5 -0
- data/public/javascripts/master.js +0 -0
- data/public/stylesheets/master.css +2 -0
- data/stubs/app/controllers/application.rb +2 -0
- metadata +21 -1
data/VERSION.yml
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Merb
|
2
|
+
module MerbAuthSliceMultisite
|
3
|
+
module ApplicationHelper
|
4
|
+
|
5
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
6
|
+
#
|
7
|
+
# @return <String>
|
8
|
+
# A path relative to the public directory, with added segments.
|
9
|
+
def image_path(*segments)
|
10
|
+
public_path_for(:image, *segments)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
14
|
+
#
|
15
|
+
# @return <String>
|
16
|
+
# A path relative to the public directory, with added segments.
|
17
|
+
def javascript_path(*segments)
|
18
|
+
public_path_for(:javascript, *segments)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
22
|
+
#
|
23
|
+
# @return <String>
|
24
|
+
# A path relative to the public directory, with added segments.
|
25
|
+
def stylesheet_path(*segments)
|
26
|
+
public_path_for(:stylesheet, *segments)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Construct a path relative to the public directory
|
30
|
+
#
|
31
|
+
# @param <Symbol> The type of component.
|
32
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
33
|
+
#
|
34
|
+
# @return <String>
|
35
|
+
# A path relative to the public directory, with added segments.
|
36
|
+
def public_path_for(type, *segments)
|
37
|
+
::MerbAuthSliceMultisite.public_path_for(type, *segments)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Construct an app-level path.
|
41
|
+
#
|
42
|
+
# @param <Symbol> The type of component.
|
43
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
44
|
+
#
|
45
|
+
# @return <String>
|
46
|
+
# A path within the host application, with added segments.
|
47
|
+
def app_path_for(type, *segments)
|
48
|
+
::MerbAuthSliceMultisite.app_path_for(type, *segments)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Construct a slice-level path.
|
52
|
+
#
|
53
|
+
# @param <Symbol> The type of component.
|
54
|
+
# @param *segments<Array[#to_s]> Path segments to append.
|
55
|
+
#
|
56
|
+
# @return <String>
|
57
|
+
# A path within the slice source (Gem), with added segments.
|
58
|
+
def slice_path_for(type, *segments)
|
59
|
+
::MerbAuthSliceMultisite.slice_path_for(type, *segments)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/app/models/site.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class Site
|
2
|
+
include DataMapper::Resource
|
3
|
+
include DataMapper::Timestamp
|
4
|
+
|
5
|
+
# Schema
|
6
|
+
property :id, Serial
|
7
|
+
property :domain, String, :nullable => :false, :length => (1..40), :unique => true, :format => /(\.[a-z]{2,4})$/
|
8
|
+
property :subdomain, String, :nullable => :false, :length => (1..40), :unique => true, :format => /^[a-zA-Z0-9\-]*?$/
|
9
|
+
property :created_at, DateTime
|
10
|
+
property :updated_at, DateTime
|
11
|
+
|
12
|
+
# Relationships/Associates
|
13
|
+
has n, :users, :order => [:login.asc]
|
14
|
+
|
15
|
+
# Validations
|
16
|
+
validates_with_method :check_subdomain
|
17
|
+
|
18
|
+
ReservedSubdomains = %w[backstage admin blog dev ftp mail email pop pop3 imap smtp stage stats status www]
|
19
|
+
def check_subdomain
|
20
|
+
if ReservedSubdomains.include?(self.subdomain)
|
21
|
+
[false, "Subdomain '#{self.subdomain}' is reserved."]
|
22
|
+
else
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Hooks
|
28
|
+
before :valid?, :remove_http_and_www
|
29
|
+
def remove_http_and_www
|
30
|
+
if domain
|
31
|
+
domain.gsub!('http://', '')
|
32
|
+
domain.gsub!('www.', '')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
5
|
+
<title>Fresh MerbAuthSliceMultisite Slice</title>
|
6
|
+
<link href="<%= public_path_for :stylesheet, 'master.css' %>" type="text/css" charset="utf-8" rel="stylesheet" media="all" />
|
7
|
+
<script src="<%= public_path_for :javascript, 'master.js' %>" type="text/javascript" charset="utf-8"></script>
|
8
|
+
</head>
|
9
|
+
<!-- you can override this layout at slices/merb_auth_slice_multisite/app/views/layout/merb_auth_slice_multisite.html.erb -->
|
10
|
+
<body class="merb_auth_slice_multisite-slice">
|
11
|
+
<div id="container">
|
12
|
+
<h1>MerbAuthSliceMultisite Slice</h1>
|
13
|
+
<div id="main"><%= catch_content :for_layout %></div>
|
14
|
+
</div>
|
15
|
+
</body>
|
16
|
+
</html>
|
data/config/database.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
# This is a sample database file for the DataMapper ORM
|
3
|
+
development: &defaults
|
4
|
+
# These are the settings for repository :default
|
5
|
+
adapter: sqlite3
|
6
|
+
database: sample_development.db
|
7
|
+
|
8
|
+
# Add more repositories
|
9
|
+
# repositories:
|
10
|
+
# repo1:
|
11
|
+
# adapter: sqlite3
|
12
|
+
# database: sample_1_development.db
|
13
|
+
# repo2:
|
14
|
+
# ...
|
15
|
+
|
16
|
+
test:
|
17
|
+
<<: *defaults
|
18
|
+
database: sample_test.db
|
19
|
+
|
20
|
+
# repositories:
|
21
|
+
# repo1:
|
22
|
+
# database: sample_1_test.db
|
23
|
+
|
24
|
+
production:
|
25
|
+
<<: *defaults
|
26
|
+
database: production.db
|
27
|
+
|
28
|
+
# repositories:
|
29
|
+
# repo1:
|
30
|
+
# database: sample_production.db
|
31
|
+
|
32
|
+
rake:
|
33
|
+
<<: *defaults
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# dependencies are generated using a strict version, don't forget to edit the dependency versions when upgrading.
|
2
|
+
merb_gems_version = "1.0.10"
|
3
|
+
dm_gems_version = "0.9.10"
|
4
|
+
do_gems_version = "0.9.11"
|
5
|
+
|
6
|
+
# For more information about each component, please read http://wiki.merbivore.com/faqs/merb_components
|
7
|
+
dependency "merb-core", merb_gems_version
|
8
|
+
dependency "merb-action-args", merb_gems_version
|
9
|
+
dependency "merb-assets", merb_gems_version
|
10
|
+
dependency("merb-cache", merb_gems_version) do
|
11
|
+
Merb::Cache.setup do
|
12
|
+
register(Merb::Cache::FileStore) unless Merb.cache
|
13
|
+
end
|
14
|
+
end
|
15
|
+
dependency "merb-helpers", merb_gems_version
|
16
|
+
dependency "merb-mailer", merb_gems_version
|
17
|
+
dependency "merb-slices", merb_gems_version
|
18
|
+
dependency "merb-auth-core", merb_gems_version
|
19
|
+
dependency "merb-auth-more", merb_gems_version
|
20
|
+
dependency "merb-auth-slice-password", merb_gems_version
|
21
|
+
dependency "merb-param-protection", merb_gems_version
|
22
|
+
dependency "merb-exceptions", merb_gems_version
|
23
|
+
|
24
|
+
dependency "data_objects", do_gems_version
|
25
|
+
dependency "do_mysql", do_gems_version # If using another database, replace this
|
26
|
+
dependency "dm-core", dm_gems_version
|
27
|
+
dependency "dm-aggregates", dm_gems_version
|
28
|
+
dependency "dm-migrations", dm_gems_version
|
29
|
+
dependency "dm-timestamps", dm_gems_version
|
30
|
+
dependency "dm-types", dm_gems_version
|
31
|
+
dependency "dm-validations", dm_gems_version
|
32
|
+
dependency "dm-serializer", dm_gems_version
|
33
|
+
|
34
|
+
dependency "merb_datamapper", merb_gems_version
|
data/config/init.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# ==== Standalone MerbAuthSliceMultisite configuration
|
3
|
+
#
|
4
|
+
# This configuration/environment file is only loaded by bin/slice, which can be
|
5
|
+
# used during development of the slice. It has no effect on this slice being
|
6
|
+
# loaded in a host application. To run your slice in standalone mode, just
|
7
|
+
# run 'slice' from its directory. The 'slice' command is very similar to
|
8
|
+
# the 'merb' command, and takes all the same options, including -i to drop
|
9
|
+
# into an irb session for example.
|
10
|
+
#
|
11
|
+
# The usual Merb configuration directives and init.rb setup methods apply,
|
12
|
+
# including use_orm and before_app_loads/after_app_loads.
|
13
|
+
#
|
14
|
+
# If you need need different configurations for different environments you can
|
15
|
+
# even create the specific environment file in config/environments/ just like
|
16
|
+
# in a regular Merb application.
|
17
|
+
#
|
18
|
+
# In fact, a slice is no different from a normal # Merb application - it only
|
19
|
+
# differs by the fact that seamlessly integrates into a so called 'host'
|
20
|
+
# application, which in turn can override or finetune the slice implementation
|
21
|
+
# code and views.
|
22
|
+
#
|
23
|
+
require(File.join(File.expand_path(File.dirname(__FILE__)),"..","lib","merb_auth_slice_multisite"))
|
24
|
+
|
25
|
+
require 'config/dependencies.rb'
|
26
|
+
use_orm :datamapper
|
27
|
+
use_test :rspec
|
28
|
+
use_template_engine :erb
|
29
|
+
|
30
|
+
# borrowed from http://github.com/ck/merb-auth-slice-activation/
|
31
|
+
Merb::BootLoader.before_app_loads do
|
32
|
+
DataMapper.setup(:default, "sqlite3::memory:")
|
33
|
+
|
34
|
+
class User
|
35
|
+
include DataMapper::Resource
|
36
|
+
include Merb::Authentication::Mixins::UserBelongsToSite
|
37
|
+
|
38
|
+
property :id, Serial
|
39
|
+
property :email, String
|
40
|
+
property :login, String
|
41
|
+
end
|
42
|
+
|
43
|
+
class Merb::Authentication
|
44
|
+
def self.user_class
|
45
|
+
::User
|
46
|
+
end
|
47
|
+
|
48
|
+
def store_user(user)
|
49
|
+
return nil if user.nil?
|
50
|
+
user.login
|
51
|
+
end
|
52
|
+
def fetch_user(user_id)
|
53
|
+
User.first(:login => login)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
Merb::Config.use do |c|
|
60
|
+
# Sets up a custom session id key which is used for the session persistence
|
61
|
+
# cookie name. If not specified, defaults to '_session_id'.
|
62
|
+
# c[:session_id_key] = '_session_id'
|
63
|
+
|
64
|
+
# The session_secret_key is only required for the cookie session store.
|
65
|
+
c[:session_secret_key] = 'ef573d4e2d6f9bf3a713cd45eb4f9411dfba94ef'
|
66
|
+
|
67
|
+
# There are various options here, by default Merb comes with 'cookie',
|
68
|
+
# 'memory', 'memcache' or 'container'.
|
69
|
+
# You can of course use your favorite ORM instead:
|
70
|
+
# 'datamapper', 'sequel' or 'activerecord'.
|
71
|
+
c[:session_store] = 'cookie'
|
72
|
+
|
73
|
+
# When running a slice standalone, you're usually developing it,
|
74
|
+
# so enable template reloading by default.
|
75
|
+
c[:reload_templates] = true
|
76
|
+
end
|
data/config/router.rb
ADDED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scottmotte-merb_auth_slice_multisite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scottmotte
|
@@ -41,6 +41,26 @@ files:
|
|
41
41
|
- spec/models/site_spec.rb
|
42
42
|
- spec/requests
|
43
43
|
- spec/spec_helper.rb
|
44
|
+
- app/controllers
|
45
|
+
- app/controllers/application.rb
|
46
|
+
- app/helpers
|
47
|
+
- app/helpers/application_helper.rb
|
48
|
+
- app/models
|
49
|
+
- app/models/site.rb
|
50
|
+
- app/views
|
51
|
+
- app/views/layout
|
52
|
+
- app/views/layout/merb_auth_slice_multisite.html.erb
|
53
|
+
- config/database.yml
|
54
|
+
- config/dependencies.rb
|
55
|
+
- config/init.rb
|
56
|
+
- config/router.rb
|
57
|
+
- public/javascripts
|
58
|
+
- public/javascripts/master.js
|
59
|
+
- public/stylesheets
|
60
|
+
- public/stylesheets/master.css
|
61
|
+
- stubs/app
|
62
|
+
- stubs/app/controllers
|
63
|
+
- stubs/app/controllers/application.rb
|
44
64
|
- LICENSE
|
45
65
|
has_rdoc: true
|
46
66
|
homepage: http://github.com/scottmotte/merb_auth_slice_multisite
|