openstax_connect 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/openstax/connect/dev/users_controller.rb +1 -13
- data/app/controllers/openstax/connect/sessions_controller.rb +9 -6
- data/app/views/openstax/connect/dev/users/login.html.erb +17 -0
- data/app/views/openstax/connect/users/_action_search.html.erb +1 -1
- data/config/initializers/02_extend_builtins.rb +3 -1
- data/config/routes.rb +2 -7
- data/lib/openstax/connect/version.rb +1 -1
- metadata +5 -8
- data/app/handlers/openstax/connect/dev/users_create.rb +0 -30
- data/app/handlers/openstax/connect/dev/users_generate.rb +0 -38
- data/app/routines/openstax/connect/dev/create_user.rb +0 -33
- data/app/views/openstax/connect/dev/users/index.html.erb +0 -30
@@ -2,20 +2,8 @@ module OpenStax
|
|
2
2
|
module Connect
|
3
3
|
module Dev
|
4
4
|
class UsersController < DevController
|
5
|
-
|
6
|
-
def index; end
|
7
5
|
|
8
|
-
def
|
9
|
-
handle_with(Dev::UsersCreate,
|
10
|
-
success: lambda { redirect_to dev_users_path },
|
11
|
-
failure: lambda { render 'index' })
|
12
|
-
end
|
13
|
-
|
14
|
-
def generate
|
15
|
-
handle_with(Dev::UsersGenerate,
|
16
|
-
success: lambda { redirect_to dev_users_path, notice: 'Success!'},
|
17
|
-
failure: lambda { render 'index', alert: 'Error' })
|
18
|
-
end
|
6
|
+
def login; end
|
19
7
|
|
20
8
|
def search
|
21
9
|
handle_with(Dev::UsersSearch,
|
@@ -7,7 +7,6 @@ module OpenStax
|
|
7
7
|
skip_before_filter :authenticate_user!
|
8
8
|
|
9
9
|
def new
|
10
|
-
session[:return_to] = request.referrer
|
11
10
|
redirect_to RouteHelper.get_path(:login)
|
12
11
|
end
|
13
12
|
|
@@ -21,11 +20,15 @@ module OpenStax
|
|
21
20
|
|
22
21
|
def destroy
|
23
22
|
sign_out!
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
|
24
|
+
# If we're using the Services server, need to sign out of it so can't
|
25
|
+
# log back in automagically
|
26
|
+
redirect_to OpenStax::Connect.configuration.enable_stubbing? ?
|
27
|
+
return_url :
|
28
|
+
OpenStax::Utilities.generate_url(
|
29
|
+
OpenStax::Connect.configuration.openstax_services_url + "/logout",
|
30
|
+
return_to: return_url
|
31
|
+
)
|
29
32
|
end
|
30
33
|
|
31
34
|
def failure
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
<div class="openstax-connect development-login">
|
3
|
+
|
4
|
+
<% handler_errors.each do |error| %>
|
5
|
+
<%= error.translate %>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<%= osu.section_block "Development Login" do %>
|
9
|
+
|
10
|
+
<p>You need to login, but we're not connected to the Services server. Search for a user below
|
11
|
+
and click the sign in link next to him or her.</p>
|
12
|
+
|
13
|
+
<%= render 'openstax/connect/users/action_search', action_search_path: dev_users_search_path %>
|
14
|
+
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
</div>
|
@@ -29,7 +29,9 @@ class ActionController::Base
|
|
29
29
|
|
30
30
|
# Useful in before_filters
|
31
31
|
def authenticate_user!
|
32
|
-
|
32
|
+
return if signed_in?
|
33
|
+
session[:return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
|
34
|
+
redirect_to openstax_connect.login_path
|
33
35
|
end
|
34
36
|
|
35
37
|
protected
|
data/config/routes.rb
CHANGED
@@ -9,12 +9,7 @@ OpenStax::Connect::Engine.routes.draw do
|
|
9
9
|
|
10
10
|
if OpenStax::Connect.configuration.enable_stubbing?
|
11
11
|
namespace :dev do
|
12
|
-
|
13
|
-
# post 'sessions/create'
|
14
|
-
# post 'sessions/search'
|
15
|
-
get 'users', to: 'users#index'
|
16
|
-
post 'users/create'
|
17
|
-
post 'users/generate'
|
12
|
+
get 'users/login'
|
18
13
|
post 'users/search'
|
19
14
|
end
|
20
15
|
end
|
@@ -25,7 +20,7 @@ module OpenStax
|
|
25
20
|
module Connect
|
26
21
|
hh = Engine.routes.url_helpers
|
27
22
|
|
28
|
-
RouteHelper.register_path(:login, hh.openstax_login_path) { hh.
|
23
|
+
RouteHelper.register_path(:login, hh.openstax_login_path) { hh.dev_users_login_path }
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -139,17 +139,14 @@ files:
|
|
139
139
|
- app/controllers/openstax/connect/dev/dev_controller.rb
|
140
140
|
- app/controllers/openstax/connect/dev/users_controller.rb
|
141
141
|
- app/controllers/openstax/connect/sessions_controller.rb
|
142
|
-
- app/handlers/openstax/connect/dev/users_create.rb
|
143
|
-
- app/handlers/openstax/connect/dev/users_generate.rb
|
144
142
|
- app/handlers/openstax/connect/dev/users_search.rb
|
145
143
|
- app/handlers/openstax/connect/sessions_omniauth_authenticated.rb
|
146
144
|
- app/helpers/openstax/connect/application_helper.rb
|
147
145
|
- app/helpers/openstax/connect/sessions_helper.rb
|
148
146
|
- app/models/openstax/connect/user.rb
|
149
|
-
- app/routines/openstax/connect/dev/create_user.rb
|
150
147
|
- app/routines/openstax/connect/search_users.rb
|
151
148
|
- app/views/layouts/openstax/connect/application.html.erb
|
152
|
-
- app/views/openstax/connect/dev/users/
|
149
|
+
- app/views/openstax/connect/dev/users/login.html.erb
|
153
150
|
- app/views/openstax/connect/dev/users/search.js.erb
|
154
151
|
- app/views/openstax/connect/shared/_attention.html.erb
|
155
152
|
- app/views/openstax/connect/users/_action_create_form.html.erb
|
@@ -189,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
186
|
version: '0'
|
190
187
|
segments:
|
191
188
|
- 0
|
192
|
-
hash:
|
189
|
+
hash: 4441139255658210770
|
193
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
191
|
none: false
|
195
192
|
requirements:
|
@@ -198,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
195
|
version: '0'
|
199
196
|
segments:
|
200
197
|
- 0
|
201
|
-
hash:
|
198
|
+
hash: 4441139255658210770
|
202
199
|
requirements: []
|
203
200
|
rubyforge_project:
|
204
201
|
rubygems_version: 1.8.25
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module OpenStax::Connect::Dev
|
2
|
-
class UsersCreate
|
3
|
-
lev_handler
|
4
|
-
|
5
|
-
# this code might be OBE
|
6
|
-
|
7
|
-
protected
|
8
|
-
|
9
|
-
def authorized?
|
10
|
-
!Rails.env.production?
|
11
|
-
end
|
12
|
-
|
13
|
-
def handle
|
14
|
-
outputs[:user] = User.create do |user|
|
15
|
-
user.first_name = params[:register][:first_name]
|
16
|
-
user.last_name = params[:register][:last_name]
|
17
|
-
user.username = params[:register][:username]
|
18
|
-
# user.is_administrator = params[:register][:is_administrator]
|
19
|
-
user.openstax_uid = available_openstax_uid
|
20
|
-
end
|
21
|
-
|
22
|
-
transfer_errors_from(outputs[:user], {scope: :register})
|
23
|
-
end
|
24
|
-
|
25
|
-
def available_openstax_uid
|
26
|
-
(User.order("openstax_uid DESC").first.try(:openstax_uid) || 0) + 1
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module OpenStax::Connect::Dev
|
2
|
-
class UsersGenerate
|
3
|
-
lev_handler
|
4
|
-
|
5
|
-
protected
|
6
|
-
|
7
|
-
paramify :generate do
|
8
|
-
attribute :count, type: Integer
|
9
|
-
validates :count, numericality: { only_integer: true,
|
10
|
-
greater_than_or_equal_to: 0 }
|
11
|
-
end
|
12
|
-
|
13
|
-
def authorized?
|
14
|
-
!Rails.env.production?
|
15
|
-
end
|
16
|
-
|
17
|
-
def handle
|
18
|
-
generate_params.count.times do
|
19
|
-
while !(User.where(:username => (username = SecureRandom.hex(4))).empty?) do; end
|
20
|
-
|
21
|
-
u = User.create do |user|
|
22
|
-
user.first_name = "Jane#{username}"
|
23
|
-
user.last_name = "Doe#{username}"
|
24
|
-
user.username = username
|
25
|
-
user.is_administrator = false
|
26
|
-
user.openstax_uid = available_openstax_uid
|
27
|
-
end
|
28
|
-
|
29
|
-
result.outputs.add(:users, u)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def available_openstax_uid
|
34
|
-
(User.order("openstax_uid DESC").first.try(:openstax_uid) || 0) + 1
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module OpenStax::Connect::Dev
|
2
|
-
class CreateUser
|
3
|
-
lev_routine
|
4
|
-
|
5
|
-
protected
|
6
|
-
|
7
|
-
def exec(inputs={})
|
8
|
-
|
9
|
-
username = inputs[:username]
|
10
|
-
|
11
|
-
if username.nil? || inputs[:ensure_no_errors]
|
12
|
-
loop do
|
13
|
-
break if !username.nil? && OpenStax::Connect::User.where(username: username).none?
|
14
|
-
username = "#{inputs[:username] || 'user'}#{rand(1000000)}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
outputs[:user] = OpenStax::Connect::User.create do |user|
|
19
|
-
user.first_name = inputs[:first_name]
|
20
|
-
user.last_name = inputs[:last_name]
|
21
|
-
user.username = username
|
22
|
-
user.openstax_uid = available_negative_openstax_uid
|
23
|
-
end
|
24
|
-
|
25
|
-
transfer_errors_from(outputs[:user], {type: :verbatim})
|
26
|
-
end
|
27
|
-
|
28
|
-
def available_negative_openstax_uid
|
29
|
-
(OpenStax::Connect::User.order("openstax_uid DESC").last.try(:openstax_uid) || 0) - 1
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
|
2
|
-
<% handler_errors.each do |error| %>
|
3
|
-
<%= error.translate %>
|
4
|
-
<% end %>
|
5
|
-
|
6
|
-
<%= osu.section_block "Register a new user" do %>
|
7
|
-
|
8
|
-
<%= lev_form_for :register, url: dev_users_create_path do |f| %>
|
9
|
-
|
10
|
-
First name <%= f.text_field :first_name %><br/>
|
11
|
-
Last name <%= f.text_field :last_name %><br/>
|
12
|
-
Username <%= f.text_field :username %><br/>
|
13
|
-
Admin? <%= f.check_box :is_administrator %><br/>
|
14
|
-
|
15
|
-
<%= submit_tag 'Register' %>
|
16
|
-
<% end %>
|
17
|
-
|
18
|
-
<% end %>
|
19
|
-
|
20
|
-
<%= osu.section_block "Generate new users" do %>
|
21
|
-
<%= lev_form_for :generate, url: dev_users_generate_path do |f| %>
|
22
|
-
Generate <%= f.text_field :count, style: 'width:30px' %> user(s) <%= submit_tag 'Do it now!' %>
|
23
|
-
<% end %>
|
24
|
-
<% end %>
|
25
|
-
|
26
|
-
<%= osu.section_block "Login as an existing user" do %>
|
27
|
-
|
28
|
-
<%= render 'openstax/connect/users/action_search', action_search_path: dev_users_search_path %>
|
29
|
-
|
30
|
-
<% end %>
|