tramway-auth 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b893b1a2ffd4f17ca07c63ee4abad90318e723c0764e7cba1a32f258fbd50a3
4
+ data.tar.gz: d13036bd0ffa66db9bd39352a6a148bd99a314d747b29c5ee4c2119f251e155b
5
+ SHA512:
6
+ metadata.gz: bfce2aa7edf2cb42b98874c3e034c632f307aee546835653183495f05894d825bd5a3b7993b1de0466aaba1a79843cfe2b040ddcd68be061fde8c1b631cd8dbc
7
+ data.tar.gz: 0e8158fd812736b983f440ee20e97bdac54d828635336ef3d1773d45a090157f8e9720c5482603441e67d9fdbb7a1c69aa433c3562d391ffa3805660d4968c4b
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Pavel Kalashnikov
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
+ # Tramway::Auth
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 'tramway-auth'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install tramway-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 = 'Tramway::Auth'
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/tramway/auth .js
2
+ //= link_directory ../stylesheets/tramway/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,29 @@
1
+ module AuthManagment
2
+ def sign_in(user)
3
+ session[:user_id] = user.id
4
+ end
5
+
6
+ def sign_out
7
+ session[:user_id] = nil
8
+ end
9
+
10
+ def signed_in?
11
+ current_user
12
+ end
13
+
14
+ def authenticate_user!
15
+ redirect_to new_session_path unless signed_in?
16
+ end
17
+
18
+ def authenticate_admin!
19
+ if signed_in?
20
+ redirect_to ::Tramway::Auth.root_path if !current_user.admin? && request.env['PATH_INFO'] != ::Tramway::Auth.root_path
21
+ else
22
+ redirect_to '/auth/session/new'
23
+ end
24
+ end
25
+
26
+ def current_user
27
+ @_current_user ||= ::Tramway::User::User.find_by id: session[:user_id]
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Tramway
2
+ module Auth
3
+ class ApplicationController < ActionController::Base
4
+ layout ::Tramway::Auth.layout_path
5
+ protect_from_forgery with: :exception
6
+ before_action :application
7
+
8
+ def application
9
+ if ::Tramway::Core.application
10
+ @application = Tramway::Core.application&.model_class&.first || Tramway::Core.application
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ require_dependency "tramway/auth/application_controller"
2
+
3
+ class Tramway::Auth::Web::ApplicationController < ::Tramway::Auth::ApplicationController
4
+ include AuthManagment
5
+ end
@@ -0,0 +1,32 @@
1
+ module Tramway::Auth
2
+ module Web
3
+ class SessionsController < ::Tramway::Auth::Web::ApplicationController
4
+ before_action :redirect_if_signed_in, except: :destroy
5
+
6
+ def new
7
+ @session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.new
8
+ end
9
+
10
+ def create
11
+ @session_form = ::Tramway::Auth::SessionForm.new ::Tramway::User::User.find_or_initialize_by email: params[:user][:email]
12
+ if @session_form.validate params[:user]
13
+ sign_in @session_form.model
14
+ redirect_to ::Tramway::Auth.root_path
15
+ else
16
+ render :new
17
+ end
18
+ end
19
+
20
+ def destroy
21
+ sign_out
22
+ redirect_to root_path
23
+ end
24
+
25
+ private
26
+
27
+ def redirect_if_signed_in
28
+ redirect_to ::Tramway::Auth.root_path if signed_in? && request.env['PATH_INFO'] != ::Tramway::Auth.root_path
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ module Tramway::Auth
2
+ class SessionForm < ::Tramway::Core::ApplicationForm
3
+ properties :email
4
+ attr_accessor :password
5
+
6
+ def model_name
7
+ User
8
+ end
9
+
10
+ def validate(params)
11
+ self.model.authenticate params[:password]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module Tramway
2
+ module Auth
3
+ module ApplicationHelper
4
+ include AuthManagment
5
+ include ::FontAwesome::Rails::IconHelper
6
+ include Tramway::Core::TitleHelper
7
+ include Tramway::Admin::NavbarHelper
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module Tramway
2
+ module Auth
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Tramway
2
+ module Auth
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Tramway
2
+ module Auth
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ - title
2
+ .row
3
+ .col-md-6
4
+ = simple_form_for @session_form.model, url: session_path, method: :post, html: { class: 'form-horizontal' } do |f|
5
+ = f.input :email, as: :string
6
+ = f.input :password
7
+ = f.button :submit, t('helpers.links.enter'), class: 'btn btn-success'
@@ -0,0 +1,4 @@
1
+ ru:
2
+ helpers:
3
+ links:
4
+ enter: Войти
@@ -0,0 +1,7 @@
1
+ ru:
2
+ tramway:
3
+ auth:
4
+ web:
5
+ sessions:
6
+ new:
7
+ title: Авторизация
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Tramway::Auth::Engine.routes.draw do
2
+ scope module: :web do
3
+ resource :session, only: [ :new, :create, :destroy ]
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :tramway_auth do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,27 @@
1
+ require "tramway/auth/engine"
2
+
3
+ module Tramway
4
+ module Auth
5
+ class << self
6
+ def root
7
+ File.dirname __dir__
8
+ end
9
+
10
+ def layout_path=(path)
11
+ @layout_path = path
12
+ end
13
+
14
+ def layout_path
15
+ @layout_path ||= 'tramway/user/application'
16
+ end
17
+
18
+ def root_path=(path)
19
+ @root_path = path
20
+ end
21
+
22
+ def root_path
23
+ @root_path || '/'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module Tramway
2
+ module Auth
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Tramway::Auth
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Tramway
2
+ module Auth
3
+ VERSION = '1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tramway-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Kalashnikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Rails engine for auth
14
+ email:
15
+ - kalashnikovisme@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - MIT-LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - app/assets/config/tramway_auth_manifest.js
24
+ - app/assets/javascripts/tramway/auth/application.js
25
+ - app/assets/stylesheets/tramway/auth/application.css
26
+ - app/controllers/concerns/auth_managment.rb
27
+ - app/controllers/tramway/auth/application_controller.rb
28
+ - app/controllers/tramway/auth/web/application_controller.rb
29
+ - app/controllers/tramway/auth/web/sessions_controller.rb
30
+ - app/forms/tramway/auth/session_form.rb
31
+ - app/helpers/tramway/auth/application_helper.rb
32
+ - app/jobs/tramway/auth/application_job.rb
33
+ - app/mailers/tramway/auth/application_mailer.rb
34
+ - app/models/tramway/auth/application_record.rb
35
+ - app/views/tramway/auth/web/sessions/new.html.haml
36
+ - config/locales/helpers.yml
37
+ - config/locales/ru.yml
38
+ - config/routes.rb
39
+ - lib/tasks/tramway/auth_tasks.rake
40
+ - lib/tramway/auth.rb
41
+ - lib/tramway/auth/engine.rb
42
+ - lib/tramway/auth/version.rb
43
+ homepage: https://github.com/ulmic/tramway-dev
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.7.7
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Rails engine for auth
67
+ test_files: []