simply_auth 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3eee7f12215a55da586805281fcef95295c81f71
4
+ data.tar.gz: 0f116bbfa9e6b7e473b4f07c81619d7ecf668f2d
5
+ SHA512:
6
+ metadata.gz: bf9a8642239c96b488d94a83654682580584f615ec6a0dafb7f0192b9d95176e2a3041a62fdeeb92e2c03a9ef0cd0c1d69b4a79cbdc9948fddb218f2e2818b75
7
+ data.tar.gz: a1fcdd2107a340214154e9faca3e59e3dc22fcc7966dd64949896772a4508e1b91af32172a098f1414f3e37cebf6dc05726a270f9ad3461639b0535d3208b2b2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Ryan Fogle
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.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # SimplyAuth
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'simply_auth'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install simply_auth
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SimplyAuth'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/simply_auth .js
2
+ //= link_directory ../stylesheets/simply_auth .css
@@ -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 any plugin's vendor/assets/javascripts directory 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. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/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 any plugin's vendor/assets/stylesheets directory 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 other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module SimplyAuth
2
+ class ApplicationController < ::ApplicationController
3
+ layout "application"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ module SimplyAuth
2
+ class RegistrationsController < ApplicationController
3
+ def new
4
+ @user = SimplyAuth::User.new
5
+ end
6
+
7
+ def create
8
+ @user = SimplyAuth::User.new(user_params)
9
+ if @user.save
10
+ # account_name = @user.data.company_name
11
+ # account_name = @user.name if account_name.blank?
12
+ # account = Account.create(name: account_name)
13
+ # @user.data.account_id = account.id
14
+ # @user.save
15
+
16
+ @session = SimplyAuth::Session.new(email: user_params[:email], password: user_params[:password])
17
+ @session.save
18
+ session[:simply_auth_session_id] = @session.id
19
+ redirect_to :root
20
+ else
21
+ render :new
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def user_params
28
+ params.require(:simply_auth_user).permit(:name, :email, :password, data: params[:simply_auth_user][:data].keys)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ module SimplyAuth
2
+ class SessionsController < ApplicationController
3
+ def new
4
+ @session = SimplyAuth::Session.new
5
+ end
6
+
7
+ def create
8
+ @session = SimplyAuth::Session.new(session_params)
9
+ if @session.save
10
+ session[:simply_auth_session_id] = @session.id
11
+ redirect_to :root
12
+ else
13
+ render :new
14
+ end
15
+ end
16
+
17
+ def destroy
18
+ current_session.destroy
19
+ session.destroy
20
+ redirect_to :root
21
+ end
22
+
23
+ private
24
+
25
+ def session_params
26
+ params.require(:simply_auth_session).permit(:email, :password)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module SimplyAuth
2
+ module ApplicationHelper
3
+ def method_missing(method, *args, &block)
4
+ if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && main_app.respond_to?(method)
5
+ main_app.send(method, *args)
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module SimplyAuth
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module SimplyAuth
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ module SimplyAuth::Config
2
+ def self.api_key_id
3
+ ENV["SIMPLY_AUTH_KEY_ID"] || yaml_contents["api_key_id"]
4
+ end
5
+
6
+ def self.api_key_secret
7
+ ENV["SIMPLY_AUTH_KEY_SECRET"] || yaml_contents["api_key_secret"]
8
+ end
9
+
10
+ def self.user_pool_id
11
+ ENV["SIMPLY_AUTH_USER_POOL_ID"] || yaml_contents["user_pool_id"]
12
+ end
13
+
14
+ private
15
+
16
+ def self.yaml_contents
17
+ @contents ||= read_contents
18
+ end
19
+
20
+ def self.read_contents
21
+ yaml = YAML.load(File.read(File.join(Rails.root, "config", "simply_auth.yml")))
22
+ yaml[Rails.env] || {}
23
+ end
24
+ end
@@ -0,0 +1,92 @@
1
+ module SimplyAuth
2
+ class Model
3
+ include ActiveModel::Model
4
+ include ActiveModel::Dirty
5
+ include ActiveModel::Conversion
6
+ attr_accessor :id
7
+
8
+ def data
9
+ @data ||= OpenStruct.new
10
+ end
11
+
12
+ def data=(val)
13
+ @data = OpenStruct.new(val)
14
+ end
15
+
16
+ def attributes=(hash)
17
+ hash.each do |key, value|
18
+ send("#{key}=", value)
19
+ end
20
+ end
21
+
22
+ def attributes
23
+ {id: id, data: data}
24
+ end
25
+
26
+ def save
27
+ if valid?
28
+ response = RestClient.send(
29
+ persisted? ? :patch : :post,
30
+ "https://api.simplyauth.com#{instance_path}",
31
+ attributes.to_json,
32
+ accept: :json,
33
+ content_type: :json
34
+ )
35
+ body = JSON.parse(response.body)
36
+ body = body.deep_transform_keys { |key| key.to_s.underscore }
37
+ self.attributes = body
38
+ changes_applied
39
+ true
40
+ else
41
+ false
42
+ end
43
+ end
44
+
45
+ def self.owner_class
46
+ return @owner_class if @owner_class_set
47
+ @owner_class = "SimplyAuth::#{self.owner_class_name}".constantize if self.owner_class_name
48
+ @owner_class_set = true
49
+ @owner_class
50
+ end
51
+
52
+ def self.path_component
53
+ model_name.element.pluralize.dasherize
54
+ end
55
+
56
+ def self.owner_class_name
57
+ nil
58
+ end
59
+
60
+ def self.collection_path(owner_ids = [])
61
+ ids = [ids].flatten
62
+ if self.owner_class
63
+ "#{self.owner_class.instance_path(owner_ids)}/#{path_component}"
64
+ else
65
+ "/#{path_component}"
66
+ end
67
+ end
68
+
69
+ def instance_path
70
+ self.class.instance_path(id)
71
+ end
72
+
73
+ def self.instance_path(ids = [])
74
+ ids = [ids].flatten
75
+ if self.owner_class
76
+ "#{self.owner_class.instance_path(ids.first(ids.length - 1))}/#{path_component}/#{ids.last}"
77
+ else
78
+ "/#{path_component}/#{ids.last}"
79
+ end
80
+ end
81
+
82
+ def self.find(ids)
83
+ response = RestClient.get(
84
+ "https://api.simplyauth.com#{instance_path(ids)}",
85
+ accept: :json
86
+ )
87
+ body = JSON.parse(response.body)
88
+ body = body.deep_transform_keys { |key| key.to_s.underscore }
89
+ new(body)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,22 @@
1
+ module SimplyAuth
2
+ class Session < Model
3
+ attr_accessor :email, :password, :user
4
+ validates :email, format: /[^@]+@[^@]+/
5
+ validates :password, length: 6..72
6
+ def attributes
7
+ super.merge(email: email, password: password, id: id)
8
+ end
9
+ def user
10
+ User.new(@user)
11
+ end
12
+ def self.owner_class_name
13
+ "UserPool"
14
+ end
15
+ def destroy
16
+ response = RestClient.delete(
17
+ "https://api.simplyauth.com#{instance_path}",
18
+ accept: :json
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module SimplyAuth
2
+ class User < Model
3
+ attr_accessor :name, :email, :password, :user_pool_id
4
+ validates :name, presence: true
5
+ validates :email, format: /[^@]+@[^@]+/
6
+ validates :password, length: 6..72
7
+ def attributes
8
+ super.merge(name: name, email: email, password: password)
9
+ end
10
+
11
+ def self.owner_class_name
12
+ "UserPool"
13
+ end
14
+
15
+ def self.all(ids)
16
+ response = RestClient.get(
17
+ "https://api.simplyauth.com#{collection_path(ids)}",
18
+ accept: :json
19
+ )
20
+ body = JSON.parse(response.body)
21
+ body.map do |data|
22
+ data = data.deep_transform_keys { |key| key.to_s.underscore }
23
+ new(data)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module SimplyAuth
2
+ class UserPool < Model
3
+ attr_accessor :name
4
+ def attributes
5
+ super.merge(name: name)
6
+ end
7
+
8
+ def self.instance_path(ids = [])
9
+ if ids.empty?
10
+ super([SimplyAuth::Config.user_pool_id])
11
+ else
12
+ super(ids)
13
+ end
14
+ end
15
+
16
+ def self.all
17
+ response = RestClient.get(
18
+ "https://api.simplyauth.com#{collection_path}",
19
+ accept: :json
20
+ )
21
+ body = JSON.parse(response.body)
22
+ body.map do |data|
23
+ data = data.deep_transform_keys { |key| key.to_s.underscore }
24
+ new(data)
25
+ end
26
+ end
27
+
28
+ def users
29
+ User.all(id)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Simply auth</title>
5
+ <%= stylesheet_link_tag "simply_auth/application", media: "all" %>
6
+ <%= javascript_include_tag "simply_auth/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,15 @@
1
+ <%= form_for @user, url: [:registrations] do |f| %>
2
+ <div class='form-group'>
3
+ <%= f.label :name, "Name *" %>
4
+ <%= f.text_field :name, class: "form-control" %>
5
+ </div>
6
+ <div class='form-group'>
7
+ <%= f.label :email, "Email *" %>
8
+ <%= f.text_field :email, class: "form-control" %>
9
+ </div>
10
+ <div class='form-group'>
11
+ <%= f.label :password, "Password *" %>
12
+ <%= f.password_field :password, class: "form-control" %>
13
+ </div>
14
+ <%= f.submit "Sign Up", class: "btn btn-primary" %>
15
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <%= form_for @session, url: :session do |f| %>
2
+ <div class='form-group'>
3
+ <%= f.label :email, "Email *" %>
4
+ <%= f.text_field :email, class: "form-control" %>
5
+ </div>
6
+ <div class='form-group'>
7
+ <%= f.label :password, "Password *" %>
8
+ <%= f.password_field :password, class: "form-control"%>
9
+ </div>
10
+ <%= f.submit "Log In", class: "btn btn-primary"%>
11
+ <% end %>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ SimplyAuth::Engine.routes.draw do
2
+ resources :registrations
3
+ resource :session
4
+ end
@@ -0,0 +1,6 @@
1
+ require "simply_auth/engine"
2
+ require "simply_auth/version"
3
+ require "simply_auth/controller_helpers"
4
+
5
+ module SimplyAuth
6
+ end
@@ -0,0 +1,24 @@
1
+ module SimplyAuth
2
+ module ControllerHelpers
3
+ def current_session
4
+ SimplyAuth::Session.find(session[:simply_auth_session_id]) if session[:simply_auth_session_id]
5
+ end
6
+
7
+ def user_logged_in?
8
+ current_session.present?
9
+ end
10
+
11
+ def current_user
12
+ current_session.try(:user)
13
+ end
14
+
15
+ def authenticate_user!
16
+ if user_logged_in?
17
+ true
18
+ else
19
+ redirect_to new_session_path
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module SimplyAuth
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SimplyAuth
4
+
5
+ initializer "controller_helpers" do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ include SimplyAuth::ControllerHelpers
8
+ helper_method :user_logged_in?, :current_user
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module SimplyAuth
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :simply_auth do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simply_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Fogle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - ryan@simplyauth.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/assets/config/simply_auth_manifest.js
52
+ - app/assets/javascripts/simply_auth/application.js
53
+ - app/assets/stylesheets/simply_auth/application.css
54
+ - app/controllers/simply_auth/application_controller.rb
55
+ - app/controllers/simply_auth/registrations_controller.rb
56
+ - app/controllers/simply_auth/sessions_controller.rb
57
+ - app/helpers/simply_auth/application_helper.rb
58
+ - app/jobs/simply_auth/application_job.rb
59
+ - app/mailers/simply_auth/application_mailer.rb
60
+ - app/models/simply_auth/config.rb
61
+ - app/models/simply_auth/model.rb
62
+ - app/models/simply_auth/session.rb
63
+ - app/models/simply_auth/user.rb
64
+ - app/models/simply_auth/user_pool.rb
65
+ - app/views/layouts/simply_auth/application.html.erb
66
+ - app/views/simply_auth/registrations/new.html.erb
67
+ - app/views/simply_auth/sessions/new.html.erb
68
+ - config/routes.rb
69
+ - lib/simply_auth.rb
70
+ - lib/simply_auth/controller_helpers.rb
71
+ - lib/simply_auth/engine.rb
72
+ - lib/simply_auth/version.rb
73
+ - lib/tasks/simply_auth_tasks.rake
74
+ homepage: https://www.simplyauth.com
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.12
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: The simple managed user service
98
+ test_files: []