shopqi-app 0.1.0

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.
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = ShopqiApp
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ShopqiApp'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
@@ -0,0 +1,9 @@
1
+ #= require jquery
2
+ #= require jquery_ujs
3
+ #= require_tree .
4
+
5
+ #= require twitter/bootstrap/dropdown.js
6
+
7
+ $(document).ready ->
8
+ $('#shop').focus()
9
+ $('.dropdown-toggle').dropdown()
@@ -0,0 +1,60 @@
1
+ /*
2
+ *= require_tree .
3
+ */
4
+
5
+ // CSS Reset
6
+ @import "twitter/bootstrap/reset.less";
7
+
8
+ // Core variables and mixins
9
+ @import "twitter/bootstrap/variables.less"; // Modify this for custom colors, font-sizes, etc
10
+ @import "twitter/bootstrap/mixins.less";
11
+
12
+ // Grid system and page structure
13
+ @import "twitter/bootstrap/scaffolding.less";
14
+ @import "twitter/bootstrap/grid.less";
15
+ @import "twitter/bootstrap/layouts.less";
16
+
17
+ // Base CSS
18
+ @import "twitter/bootstrap/type.less";
19
+ //@import "twitter/bootstrap/code.less";
20
+ @import "twitter/bootstrap/forms.less";
21
+ //@import "twitter/bootstrap/tables.less";
22
+
23
+ // Components: common
24
+ @import "twitter/bootstrap/sprites.less";
25
+ @import "twitter/bootstrap/dropdowns.less";
26
+ @import "twitter/bootstrap/wells.less";
27
+ //@import "twitter/bootstrap/component-animations.less";
28
+ //@import "twitter/bootstrap/close.less";
29
+
30
+ // Components: Buttons & Alerts
31
+ @import "twitter/bootstrap/buttons.less";
32
+ //@import "twitter/bootstrap/button-groups.less";
33
+ //@import "twitter/bootstrap/alerts.less"; // Note: alerts share common CSS with buttons and thus have styles in buttons.less
34
+
35
+ // Components: Nav
36
+ @import "twitter/bootstrap/navs.less";
37
+ @import "twitter/bootstrap/navbar.less";
38
+ //@import "twitter/bootstrap/breadcrumbs.less";
39
+ //@import "twitter/bootstrap/pagination.less";
40
+ //@import "twitter/bootstrap/pager.less";
41
+
42
+ // Components: Popovers
43
+ //@import "twitter/bootstrap/modals.less";
44
+ //@import "twitter/bootstrap/tooltip.less";
45
+ //@import "twitter/bootstrap/popovers.less";
46
+
47
+ // Components: Misc
48
+ //@import "twitter/bootstrap/thumbnails.less";
49
+ @import "twitter/bootstrap/labels-badges.less";
50
+ //@import "twitter/bootstrap/progress-bars.less";
51
+ //@import "twitter/bootstrap/accordion.less";
52
+ //@import "twitter/bootstrap/carousel.less";
53
+ @import "twitter/bootstrap/hero-unit.less";
54
+
55
+ // Utility classes
56
+ @import "twitter/bootstrap/utilities.less"; // Has to be last to override when necessary
57
+
58
+ body {
59
+ margin-top: 50px;
60
+ margin-bottom: 100px; }
@@ -0,0 +1,6 @@
1
+ module ShopqiApp
2
+ class ApplicationController < ActionController::Base
3
+ include ApplicationHelper
4
+ protect_from_forgery
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ module ShopqiApp
2
+ class SessionsController < ApplicationController
3
+
4
+ def new
5
+ if params[:shop].present?
6
+ redirect_to "/auth/shopqi?shop=#{params[:shop].to_s.strip}"
7
+ end
8
+ end
9
+
10
+ def create
11
+ if data = request.env['omniauth.auth']
12
+ session[:shopqi] = {
13
+ url: params[:shop],
14
+ access_token: data['credentials']['token'],
15
+ shop: data['extra']['raw_info']['shop']
16
+ }
17
+ redirect_to main_app.root_path
18
+ else
19
+ flash[:error] = "Could not log in to store."
20
+ redirect_to login_path
21
+ end
22
+ end
23
+
24
+ def shopqi_login
25
+ if signed_in?
26
+ redirect_to main_app.root_path
27
+ else
28
+ redirect_to login_path(shop: params[:shop])
29
+ end
30
+ end
31
+
32
+ def destroy
33
+ session[:shopqi] = nil
34
+ redirect_to main_app.root_path
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ module ShopqiApp
2
+ module ApplicationHelper
3
+ def authenticate_shop! # 必须通过认证
4
+ redirect_to root_path unless signed_in?
5
+ end
6
+
7
+ def signed_in?
8
+ session[:shopqi]
9
+ end
10
+
11
+ def current_shop
12
+ session[:shopqi] && session[:shopqi][:shop]
13
+ end
14
+
15
+ def shop_url
16
+ "http://#{current_shop['shopqi_domain']}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ class SecretSetting < Settingslogic
2
+ source "#{Rails.root}/config/app_secret_config.yml"
3
+ namespace Rails.env
4
+ load!
5
+ end
@@ -0,0 +1,35 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title ShopQi App Example
5
+ = stylesheet_link_tag "application"
6
+ = javascript_include_tag "application"
7
+ = csrf_meta_tags
8
+ %body
9
+ .navbar.navbar-fixed-top
10
+ .navbar-inner
11
+ .container
12
+ %a.brand(href="/") ShopQi App Example
13
+ -if current_shop
14
+ %ul.nav.pull-right
15
+ %li.dropdown
16
+ =link_to shop_url, class: 'dropdown-toggle', data: { toggle: :dropdown } do
17
+ =current_shop['shopqi_domain']
18
+ %b.caret
19
+ %ul.dropdown-menu
20
+ %li
21
+ =link_to shop_url, target: :_blank do
22
+ %i.icon-home
23
+ 商店前台
24
+ %li
25
+ =link_to "#{shop_url}/admin", target: :_blank do
26
+ %i.icon-cog
27
+ 商店后台
28
+ %li.divider
29
+ %li
30
+ =link_to sign_out_path do
31
+ %i.icon-off
32
+ 退出
33
+
34
+ #main.container
35
+ = yield
@@ -0,0 +1,8 @@
1
+ .content
2
+ .page-header
3
+ %h1
4
+ 安装应用
5
+ %small 请输入商店 URL 地址
6
+ = form_tag login_path, :class => 'form-search' do
7
+ = text_field_tag 'shop', nil, :placeholder => '商品 URL 地址', :class => 'btn-large', :id => 'shop'
8
+ = submit_tag '安装', :class => 'btn btn-primary btn-large'
@@ -0,0 +1,16 @@
1
+ Rails.application.config.middleware.use OmniAuth::Builder do
2
+ provider :shopqi,
3
+ SecretSetting.oauth.client_id,
4
+ SecretSetting.oauth.secret,
5
+ :scope => SecretSetting.oauth.scope,
6
+ :callback_path => '/app/callback',
7
+ :setup => lambda {|env|
8
+ params = Rack::Utils.parse_query(env['QUERY_STRING'])
9
+ #site_url = "https://#{params['shop']}"
10
+ site_url = "http://#{params['shop']}"
11
+ Rails.logger.info(env['omniauth.strategy'])
12
+ env['omniauth.strategy'].options[:client_options][:site] = site_url
13
+ }
14
+ end
15
+
16
+ OmniAuth.config.on_failure{|env| raise env['omniauth.error']}
@@ -0,0 +1,6 @@
1
+ ShopqiApp::Engine.routes.draw do
2
+ match 'login' => 'sessions#new'
3
+ get 'callback_login' => 'sessions#shopqi_login' # 从 ShopQi 后台管理点击应用直接登录
4
+ get 'callback' => 'sessions#create'
5
+ get 'sign_out' => 'sessions#destroy'
6
+ end
@@ -0,0 +1,10 @@
1
+ require "shopqi_app/engine"
2
+ require 'haml' # fixed haml: Missing template
3
+ require 'less-rails-bootstrap'
4
+ require 'omniauth'
5
+ require 'settingslogic'
6
+ require 'omniauth-shopqi'
7
+ require 'shopkit'
8
+
9
+ module ShopqiApp
10
+ end
@@ -0,0 +1,12 @@
1
+ module ShopqiApp
2
+ class Engine < Rails::Engine
3
+ isolate_namespace ShopqiApp
4
+
5
+ config.generators do |g|
6
+ g.template_engine :haml
7
+ g.test_framework :rspec, :views => false
8
+ g.integration_tool :rspec
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ShopqiApp
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :shopqi_app do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shopqi-app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - saberma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: omniauth-shopqi
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.1.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: shopkit
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: haml
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 3.1.6
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 3.1.6
78
+ - !ruby/object:Gem::Dependency
79
+ name: less-rails-bootstrap
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.13
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.0.13
94
+ - !ruby/object:Gem::Dependency
95
+ name: settingslogic
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 2.0.8
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 2.0.8
110
+ - !ruby/object:Gem::Dependency
111
+ name: sqlite3
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rspec-rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 2.10.1
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 2.10.1
142
+ description: ShopQi app engine.
143
+ email:
144
+ - mahb45@gmail.com
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - app/helpers/shopqi_app/application_helper.rb
150
+ - app/controllers/shopqi_app/application_controller.rb
151
+ - app/controllers/shopqi_app/sessions_controller.rb
152
+ - app/models/secret_setting.rb
153
+ - app/assets/javascripts/shopqi_app/application.js.coffee
154
+ - app/assets/stylesheets/shopqi_app/application.css.less.erb
155
+ - app/views/shopqi_app/sessions/new.html.haml
156
+ - app/views/layouts/shopqi_app/application.html.haml
157
+ - config/initializers/omniauth.rb
158
+ - config/routes.rb
159
+ - lib/shopqi-app.rb
160
+ - lib/shopqi_app/version.rb
161
+ - lib/shopqi_app/engine.rb
162
+ - lib/tasks/shopqi_app_tasks.rake
163
+ - MIT-LICENSE
164
+ - Rakefile
165
+ - README.rdoc
166
+ homepage: https://github.com/saberma/shopqi-app
167
+ licenses: []
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ segments:
179
+ - 0
180
+ hash: -618896387
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ none: false
183
+ requirements:
184
+ - - ! '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ segments:
188
+ - 0
189
+ hash: -618896387
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 1.8.24
193
+ signing_key:
194
+ specification_version: 3
195
+ summary: ShopQi app engine.
196
+ test_files: []