json_voorhees 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -4
- data/lib/generators/json_voorhees/app_make_authorizations/USAGE +1 -1
- data/lib/generators/json_voorhees/app_make_authorizations/app_make_authorizations_generator.rb +1 -0
- data/lib/generators/json_voorhees/app_make_authorizations/templates/auth_file.rb.erb +8 -1
- data/lib/generators/json_voorhees/app_make_tests/USAGE +1 -1
- data/lib/generators/json_voorhees/app_make_tests/app_make_tests_generator.rb +26 -0
- data/lib/generators/json_voorhees/app_make_tests/templates/factory.rb.erb +3 -1
- data/lib/generators/json_voorhees/app_make_tests/templates/model.rb.erb +5 -0
- data/lib/generators/json_voorhees/app_make_tests/templates/no_auth_request.rb.erb +90 -0
- data/lib/generators/json_voorhees/app_scaffold/USAGE +9 -0
- data/lib/generators/json_voorhees/app_scaffold/app_scaffold_generator.rb +22 -0
- data/lib/generators/json_voorhees/engine_create_controller/USAGE +1 -1
- data/lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb +11 -0
- data/lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb +1 -1
- data/lib/generators/json_voorhees/engine_create_controller/templates/no_auth_controller_template.rb.erb +1 -1
- data/lib/generators/json_voorhees/engine_create_serializer/USAGE +1 -1
- data/lib/generators/json_voorhees/engine_create_serializer/engine_create_serializer_generator.rb +1 -0
- data/lib/generators/json_voorhees/engine_create_serializer/templates/serializer.rb.erb +13 -0
- data/lib/generators/json_voorhees/engine_scaffold/USAGE +9 -0
- data/lib/generators/json_voorhees/engine_scaffold/engine_scaffold_generator.rb +18 -0
- data/lib/generators/json_voorhees/massive_scaffold/USAGE +10 -0
- data/lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb +23 -0
- data/lib/generators/json_voorhees/setup_app/setup_app_generator.rb +10 -0
- data/lib/json_voorhees/version.rb +1 -1
- data/test/lib/generators/json_voorhees/app_scaffold_generator_test.rb +16 -0
- data/test/lib/generators/json_voorhees/engine_scaffold_generator_test.rb +16 -0
- data/test/lib/generators/json_voorhees/massive_scaffold_generator_test.rb +16 -0
- data/test/test_app/Gemfile +23 -0
- data/test/test_app/Gemfile.lock +99 -1
- data/test/test_app/README.md +1 -0
- data/test/test_app/app/controllers/api/v1/api_controller.rb +26 -0
- data/test/test_app/app/controllers/app_index_controller.rb +4 -0
- data/test/test_app/app/controllers/application_controller.rb +5 -0
- data/test/test_app/app/controllers/main_controller.rb +4 -0
- data/test/test_app/app/views/app_index/app.html.erb +0 -0
- data/test/test_app/app/views/layouts/app_index.html.erb +9 -0
- data/test/test_app/app/views/layouts/application.html.erb +8 -3
- data/test/test_app/app/views/main/admin.html.erb +9 -0
- data/test/test_app/config/application.rb +4 -0
- data/test/test_app/config/routes.rb +8 -0
- data/test/test_app/db/development.sqlite3 +0 -0
- data/test/test_app/db/migrate/20140905145354_create_people_users.people.rb +12 -0
- data/test/test_app/db/migrate/20140905145355_create_arcadex_tokens.arcadex.rb +12 -0
- data/test/test_app/db/migrate/20140905145356_add_index_to_token.arcadex.rb +6 -0
- data/test/test_app/db/production.sqlite3 +0 -0
- data/test/test_app/db/schema.rb +19 -1
- data/test/test_app/db/test.sqlite3 +0 -0
- data/test/test_app/engines/people/Gemfile +14 -0
- data/test/test_app/engines/people/Gemfile.lock +92 -0
- data/test/test_app/engines/people/MIT-LICENSE +20 -0
- data/test/test_app/engines/people/README.md +1 -0
- data/test/test_app/engines/people/Rakefile +34 -0
- data/test/test_app/engines/people/app/assets/javascripts/people/application.js +13 -0
- data/test/test_app/engines/people/app/assets/javascripts/people/users.js +2 -0
- data/test/test_app/engines/people/app/assets/stylesheets/people/application.css +15 -0
- data/test/test_app/engines/people/app/assets/stylesheets/people/users.css +4 -0
- data/test/test_app/engines/people/app/assets/stylesheets/scaffold.css +56 -0
- data/test/test_app/engines/people/app/controllers/people/api/v1/application_controller.rb +5 -0
- data/test/test_app/engines/people/app/controllers/people/api/v1/users_controller.rb +124 -0
- data/test/test_app/engines/people/app/controllers/people/application_controller.rb +4 -0
- data/test/test_app/engines/people/app/controllers/people/users_controller.rb +62 -0
- data/test/test_app/engines/people/app/helpers/people/application_helper.rb +4 -0
- data/test/test_app/engines/people/app/helpers/people/users_helper.rb +4 -0
- data/test/test_app/engines/people/app/models/people/user.rb +26 -0
- data/test/test_app/engines/people/app/serializers/people/user_serializer.rb +39 -0
- data/test/test_app/engines/people/app/views/layouts/people/default/application.html.erb +14 -0
- data/test/test_app/engines/people/app/views/people/users/_form.html.erb +29 -0
- data/test/test_app/engines/people/app/views/people/users/edit.html.erb +6 -0
- data/test/test_app/engines/people/app/views/people/users/index.html.erb +29 -0
- data/test/test_app/engines/people/app/views/people/users/new.html.erb +5 -0
- data/test/test_app/engines/people/app/views/people/users/show.html.erb +19 -0
- data/test/test_app/engines/people/bin/rails +12 -0
- data/test/test_app/engines/people/config/routes.rb +24 -0
- data/test/test_app/engines/people/db/migrate/20140905145341_create_people_users.rb +11 -0
- data/test/test_app/engines/people/lib/people/engine.rb +5 -0
- data/test/test_app/engines/people/lib/people/version.rb +3 -0
- data/test/test_app/engines/people/lib/people.rb +4 -0
- data/test/test_app/engines/people/lib/tasks/people_tasks.rake +4 -0
- data/test/test_app/engines/people/people.gemspec +31 -0
- data/test/test_app/engines/people/test/controllers/people/users_controller_test.rb +51 -0
- data/test/test_app/{README.rdoc → engines/people/test/dummy/README.rdoc} +0 -0
- data/test/test_app/engines/people/test/dummy/Rakefile +6 -0
- data/test/test_app/engines/people/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/test_app/engines/people/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/test_app/engines/people/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/test_app/engines/people/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/test_app/engines/people/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/test_app/engines/people/test/dummy/bin/bundle +3 -0
- data/test/test_app/engines/people/test/dummy/bin/rails +4 -0
- data/test/test_app/engines/people/test/dummy/bin/rake +4 -0
- data/test/test_app/engines/people/test/dummy/config/application.rb +23 -0
- data/test/test_app/engines/people/test/dummy/config/boot.rb +5 -0
- data/test/test_app/engines/people/test/dummy/config/database.yml +25 -0
- data/test/test_app/engines/people/test/dummy/config/environment.rb +5 -0
- data/test/test_app/engines/people/test/dummy/config/environments/development.rb +37 -0
- data/test/test_app/engines/people/test/dummy/config/environments/production.rb +82 -0
- data/test/test_app/engines/people/test/dummy/config/environments/test.rb +39 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/assets.rb +8 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/test_app/engines/people/test/dummy/config/locales/en.yml +23 -0
- data/test/test_app/engines/people/test/dummy/config/routes.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/secrets.yml +22 -0
- data/test/test_app/engines/people/test/dummy/config.ru +4 -0
- data/test/test_app/engines/people/test/dummy/db/schema.rb +24 -0
- data/test/test_app/engines/people/test/dummy/public/404.html +67 -0
- data/test/test_app/engines/people/test/dummy/public/422.html +67 -0
- data/test/test_app/engines/people/test/dummy/public/500.html +66 -0
- data/test/test_app/engines/people/test/dummy/public/favicon.ico +0 -0
- data/test/test_app/engines/people/test/fixtures/people/users.yml +11 -0
- data/test/test_app/engines/people/test/helpers/people/users_helper_test.rb +6 -0
- data/test/test_app/engines/people/test/integration/navigation_test.rb +10 -0
- data/test/test_app/engines/people/test/models/people/user_test.rb +9 -0
- data/test/test_app/engines/people/test/people_test.rb +7 -0
- data/test/test_app/engines/people/test/test_helper.rb +15 -0
- data/test/test_app/gems/authorization/Gemfile +14 -0
- data/test/test_app/gems/authorization/Gemfile.lock +92 -0
- data/test/test_app/gems/authorization/MIT-LICENSE +20 -0
- data/test/test_app/gems/authorization/README.rdoc +3 -0
- data/test/test_app/gems/authorization/Rakefile +32 -0
- data/test/test_app/gems/authorization/authorization.gemspec +23 -0
- data/test/test_app/gems/authorization/lib/authorization/people/user.rb +82 -0
- data/test/test_app/gems/authorization/lib/authorization/version.rb +3 -0
- data/test/test_app/gems/authorization/lib/authorization.rb +3 -0
- data/test/test_app/gems/authorization/lib/tasks/authorization_tasks.rake +4 -0
- data/test/test_app/gems/authorization/test/authorization_test.rb +7 -0
- data/test/test_app/gems/authorization/test/dummy/README.rdoc +28 -0
- data/test/test_app/gems/authorization/test/dummy/Rakefile +6 -0
- data/test/test_app/gems/authorization/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/test_app/gems/authorization/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/test_app/gems/authorization/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/test_app/gems/authorization/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/test_app/gems/authorization/test/dummy/bin/bundle +3 -0
- data/test/test_app/gems/authorization/test/dummy/bin/rails +4 -0
- data/test/test_app/gems/authorization/test/dummy/bin/rake +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/application.rb +23 -0
- data/test/test_app/gems/authorization/test/dummy/config/boot.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/config/database.yml +25 -0
- data/test/test_app/gems/authorization/test/dummy/config/environment.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/development.rb +37 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/production.rb +82 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/test.rb +39 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/assets.rb +8 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/test_app/gems/authorization/test/dummy/config/locales/en.yml +23 -0
- data/test/test_app/gems/authorization/test/dummy/config/routes.rb +56 -0
- data/test/test_app/gems/authorization/test/dummy/config/secrets.yml +22 -0
- data/test/test_app/gems/authorization/test/dummy/config.ru +4 -0
- data/test/test_app/gems/authorization/test/dummy/public/404.html +67 -0
- data/test/test_app/gems/authorization/test/dummy/public/422.html +67 -0
- data/test/test_app/gems/authorization/test/dummy/public/500.html +66 -0
- data/test/test_app/gems/authorization/test/dummy/public/favicon.ico +0 -0
- data/test/test_app/gems/authorization/test/test_helper.rb +15 -0
- data/test/test_app/log/development.log +195 -0
- data/test/test_app/log/production.log +20 -0
- data/test/test_app/log/test.log +8427 -0
- data/test/test_app/spec/controllers/app_index_controller_spec.rb +12 -0
- data/test/test_app/spec/engines/people/api/v1/models/user_spec.rb +59 -0
- data/test/test_app/spec/engines/people/api/v1/requests/user_spec.rb +154 -0
- data/test/test_app/spec/engines/people/api/v1/routing/user_spec.rb +77 -0
- data/test/test_app/spec/factories/people_user_factory.rb +14 -0
- data/test/test_app/spec/rails_helper.rb +47 -0
- data/test/test_app/spec/spec_helper.rb +78 -0
- data/test/test_app/spec/support/factory_girl.rb +16 -0
- data/test/test_app/spec/support/request_helpers.rb +7 -0
- metadata +293 -6
- data/test/test_app/test/test_helper.rb +0 -10
@@ -0,0 +1,124 @@
|
|
1
|
+
require_dependency "people/api/v1/application_controller"
|
2
|
+
require 'authorization'
|
3
|
+
|
4
|
+
module People
|
5
|
+
class Api::V1::UsersController < Api::V1::ApplicationController
|
6
|
+
skip_before_filter :authenticate_user, :only => [:register, :login]
|
7
|
+
before_action :set_user, only: [:show, :edit, :update]
|
8
|
+
before_action :register_authorize, only: [:register]
|
9
|
+
before_action :login_authorize, only: [:login]
|
10
|
+
before_action :logout_authorize, only: [:logout]
|
11
|
+
before_action :index_authorize, only: [:index]
|
12
|
+
before_action :show_authorize, only: [:show]
|
13
|
+
before_action :update_authorize, only: [:update]
|
14
|
+
|
15
|
+
# POST /api/1/users/register
|
16
|
+
def register
|
17
|
+
#Create a new user
|
18
|
+
user = ::People::User.new(user_params)
|
19
|
+
if user.save
|
20
|
+
#If the user is saved, return a token
|
21
|
+
token = user.tokens[0]
|
22
|
+
render :json => {user: user, token: token}
|
23
|
+
else
|
24
|
+
#Return an error if not saved
|
25
|
+
render :json => {errors: user.errors}, status: :unprocessable_entity
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# POST /api/1/users/login
|
30
|
+
def login
|
31
|
+
#Should I delete the current token or ignore it?
|
32
|
+
#Find user from email and password. Create and return a new token
|
33
|
+
user = ::People::User.find_by(email: params[:email])
|
34
|
+
if user && user.authenticate(params[:password])
|
35
|
+
token = user.tokens.create
|
36
|
+
render :json => {user: user, token: token}
|
37
|
+
else
|
38
|
+
render :json => {errors: "Email and/or Password is incorrect"}, status: :unauthorized
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# GET /api/1/users/logout
|
43
|
+
def logout
|
44
|
+
#Destroy the current token
|
45
|
+
token = current_token
|
46
|
+
token.destroy
|
47
|
+
render json: {}
|
48
|
+
end
|
49
|
+
|
50
|
+
# GET /api/1/users
|
51
|
+
def index
|
52
|
+
@users = ::People::User.all
|
53
|
+
render json: @users
|
54
|
+
end
|
55
|
+
|
56
|
+
# GET /api/1/users/1
|
57
|
+
def show
|
58
|
+
render json: @user
|
59
|
+
end
|
60
|
+
|
61
|
+
# PATCH/PUT /api/1/users/1
|
62
|
+
def update
|
63
|
+
if @user.update(user_params)
|
64
|
+
render json: @user
|
65
|
+
else
|
66
|
+
render :json => {errors: @user.errors}, status: :unprocessable_entity
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
# Use callbacks to share common setup or constraints between actions.
|
72
|
+
|
73
|
+
def set_user
|
74
|
+
@user = ::People::User.find_by_id(params[:id])
|
75
|
+
if @user.nil?
|
76
|
+
render :json => {errors: "User was not found"}, status: :not_found
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Only allow a trusted parameter "white list" through.
|
81
|
+
|
82
|
+
def user_params
|
83
|
+
params.require(:user).permit(:username, :email, :password, :password_confirmation)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Authorizations below here
|
87
|
+
|
88
|
+
def register_authorize
|
89
|
+
if !::Authorization::People::User.register?
|
90
|
+
render :json => {errors: "User is not authorized for this action"}, status: :forbidden
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def login_authorize
|
95
|
+
if !::Authorization::People::User.login?
|
96
|
+
render :json => {errors: "User is not authorized for this action"}, status: :forbidden
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def logout_authorize
|
101
|
+
if !::Authorization::People::User.logout?(current_user)
|
102
|
+
render :json => {errors: "User is not authorized for this action"}, status: :forbidden
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def index_authorize
|
107
|
+
if !::Authorization::People::User.index?(current_user)
|
108
|
+
render :json => {errors: "User is not authorized for this action"}, status: :forbidden
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def show_authorize
|
113
|
+
if !::Authorization::People::User.show?(@user,current_user)
|
114
|
+
render :json => {errors: "User is not authorized for this action"}, status: :forbidden
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def update_authorize
|
119
|
+
if !::Authorization::People::User.update?(@user,current_user)
|
120
|
+
render :json => {errors: "User is not authorized for this action"}, status: :forbidden
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_dependency "people/application_controller"
|
2
|
+
|
3
|
+
module People
|
4
|
+
class UsersController < ApplicationController
|
5
|
+
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
6
|
+
|
7
|
+
# GET /users
|
8
|
+
def index
|
9
|
+
@users = User.all
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /users/1
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /users/new
|
17
|
+
def new
|
18
|
+
@user = User.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /users/1/edit
|
22
|
+
def edit
|
23
|
+
end
|
24
|
+
|
25
|
+
# POST /users
|
26
|
+
def create
|
27
|
+
@user = User.new(user_params)
|
28
|
+
|
29
|
+
if @user.save
|
30
|
+
redirect_to @user, notice: 'User was successfully created.'
|
31
|
+
else
|
32
|
+
render :new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# PATCH/PUT /users/1
|
37
|
+
def update
|
38
|
+
if @user.update(user_params)
|
39
|
+
redirect_to @user, notice: 'User was successfully updated.'
|
40
|
+
else
|
41
|
+
render :edit
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# DELETE /users/1
|
46
|
+
def destroy
|
47
|
+
@user.destroy
|
48
|
+
redirect_to users_url, notice: 'User was successfully destroyed.'
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
# Use callbacks to share common setup or constraints between actions.
|
53
|
+
def set_user
|
54
|
+
@user = User.find(params[:id])
|
55
|
+
end
|
56
|
+
|
57
|
+
# Only allow a trusted parameter "white list" through.
|
58
|
+
def user_params
|
59
|
+
params.require(:user).permit(:username, :email, :password_digest)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'type_cartographer'
|
2
|
+
|
3
|
+
module People
|
4
|
+
class User < ActiveRecord::Base
|
5
|
+
|
6
|
+
has_many :tokens, :as => :imageable, :class_name => "::Arcadex::Token"
|
7
|
+
|
8
|
+
has_secure_password
|
9
|
+
|
10
|
+
after_create :setup_user
|
11
|
+
|
12
|
+
validates :username, presence: true
|
13
|
+
#validates_format_of :username, :with => /\A[A-Za-z0-9\d]+\Z/i
|
14
|
+
validates :email, presence: true
|
15
|
+
#Might need a regex for emails, or just rather confirm them
|
16
|
+
|
17
|
+
def setup_user
|
18
|
+
create_token
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_token
|
22
|
+
self.tokens.create!
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'authorization'
|
2
|
+
|
3
|
+
module People
|
4
|
+
class UserSerializer < ActiveModel::Serializer
|
5
|
+
embed :ids, include: true
|
6
|
+
|
7
|
+
attributes :id
|
8
|
+
attributes :username
|
9
|
+
attributes :email
|
10
|
+
attributes :created_at
|
11
|
+
attributes :updated_at
|
12
|
+
has_many :tokens
|
13
|
+
|
14
|
+
def include_id?
|
15
|
+
return ::Authorization::People::User.include_id?(current_user,object,@options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def include_email?
|
19
|
+
return ::Authorization::People::User.include_email?(current_user,object,@options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def include_username?
|
23
|
+
return ::Authorization::People::User.include_username?(current_user,object,@options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def include_created_at?
|
27
|
+
return ::Authorization::People::User.include_created_at?(current_user,object,@options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def include_updated_at?
|
31
|
+
return ::Authorization::People::User.include_updated_at?(current_user,object,@options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def include_associations!
|
35
|
+
include! :tokens if ::Authorization::People::User.include_tokens?(current_user,object,@options)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>People</title>
|
5
|
+
<%= stylesheet_link_tag "people/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "people/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%= form_for(@user) do |f| %>
|
2
|
+
<% if @user.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @user.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :username %><br>
|
16
|
+
<%= f.text_field :username %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :email %><br>
|
20
|
+
<%= f.text_field :email %>
|
21
|
+
</div>
|
22
|
+
<div class="field">
|
23
|
+
<%= f.label :password_digest %><br>
|
24
|
+
<%= f.text_field :password_digest %>
|
25
|
+
</div>
|
26
|
+
<div class="actions">
|
27
|
+
<%= f.submit %>
|
28
|
+
</div>
|
29
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<h1>Listing users</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Username</th>
|
7
|
+
<th>Email</th>
|
8
|
+
<th>Password digest</th>
|
9
|
+
<th colspan="3"></th>
|
10
|
+
</tr>
|
11
|
+
</thead>
|
12
|
+
|
13
|
+
<tbody>
|
14
|
+
<% @users.each do |user| %>
|
15
|
+
<tr>
|
16
|
+
<td><%= user.username %></td>
|
17
|
+
<td><%= user.email %></td>
|
18
|
+
<td><%= user.password_digest %></td>
|
19
|
+
<td><%= link_to 'Show', user %></td>
|
20
|
+
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
21
|
+
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
22
|
+
</tr>
|
23
|
+
<% end %>
|
24
|
+
</tbody>
|
25
|
+
</table>
|
26
|
+
|
27
|
+
<br>
|
28
|
+
|
29
|
+
<%= link_to 'New User', new_user_path %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Username:</strong>
|
5
|
+
<%= @user.username %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>Email:</strong>
|
10
|
+
<%= @user.email %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<strong>Password digest:</strong>
|
15
|
+
<%= @user.password_digest %>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<%= link_to 'Edit', edit_user_path(@user) %> |
|
19
|
+
<%= link_to 'Back', users_path %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/people/engine', __FILE__)
|
6
|
+
|
7
|
+
# Set up gems listed in the Gemfile.
|
8
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
9
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
10
|
+
|
11
|
+
require 'rails/all'
|
12
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
People::Engine.routes.draw do
|
2
|
+
|
3
|
+
root to: "users#index"
|
4
|
+
|
5
|
+
scope 'admin' do
|
6
|
+
resources :users
|
7
|
+
end
|
8
|
+
|
9
|
+
scope 'api' do
|
10
|
+
scope '1' do
|
11
|
+
resources :users, controller: 'api/v1/users' do
|
12
|
+
collection do
|
13
|
+
# /api/1/users/register
|
14
|
+
post 'register', to: "api/v1/users#register"
|
15
|
+
# /api/1/users/login
|
16
|
+
post 'login', to: "api/v1/users#login"
|
17
|
+
# /api/1/users/logout
|
18
|
+
get 'logout', to: "api/v1/users#logout"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "people/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "people"
|
9
|
+
s.version = People::VERSION
|
10
|
+
s.authors = ["TODO: Your name"]
|
11
|
+
s.email = ["TODO: Your email"]
|
12
|
+
s.homepage = "TODO"
|
13
|
+
s.summary = "TODO: Summary of People."
|
14
|
+
s.description = "TODO: Description of People."
|
15
|
+
s.license = "MIT"
|
16
|
+
|
17
|
+
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
|
18
|
+
s.test_files = Dir["test/**/*"]
|
19
|
+
|
20
|
+
s.add_dependency "rails-api"
|
21
|
+
s.add_dependency "type_cartographer"
|
22
|
+
s.add_dependency "arcadex"
|
23
|
+
s.add_dependency "active_model_serializers", "~> 0.8.0"
|
24
|
+
s.add_dependency "bcrypt", "~> 3.1.7"
|
25
|
+
s.add_development_dependency "annotate", ">=2.6.0"
|
26
|
+
|
27
|
+
|
28
|
+
s.add_dependency "rails", "~> 4.1.5"
|
29
|
+
|
30
|
+
s.add_development_dependency "sqlite3"
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module People
|
4
|
+
class UsersControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@user = users(:one)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get index" do
|
10
|
+
get :index
|
11
|
+
assert_response :success
|
12
|
+
assert_not_nil assigns(:users)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should get new" do
|
16
|
+
get :new
|
17
|
+
assert_response :success
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should create user" do
|
21
|
+
assert_difference('User.count') do
|
22
|
+
post :create, user: { email: @user.email, password_digest: @user.password_digest, username: @user.username }
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_redirected_to user_path(assigns(:user))
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should show user" do
|
29
|
+
get :show, id: @user
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should get edit" do
|
34
|
+
get :edit, id: @user
|
35
|
+
assert_response :success
|
36
|
+
end
|
37
|
+
|
38
|
+
test "should update user" do
|
39
|
+
patch :update, id: @user, user: { email: @user.email, password_digest: @user.password_digest, username: @user.username }
|
40
|
+
assert_redirected_to user_path(assigns(:user))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should destroy user" do
|
44
|
+
assert_difference('User.count', -1) do
|
45
|
+
delete :destroy, id: @user
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_redirected_to users_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "people"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
+
# config.i18n.default_locale = :de
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|