grpc_auth 0.0.1

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
+ SHA256:
3
+ metadata.gz: c61d18eff793204e543326a7fed3fbd6df32f3e5c9b8fe70a1d2b350bebd9242
4
+ data.tar.gz: ceac7953db4ffc57b1bb0abe5c2c2ed86c827a71a7b2c531c7b2702be8759de6
5
+ SHA512:
6
+ metadata.gz: 1f6f69745939b58dadb9dad85644a50c690a7b42b8ed235770a26d9e8a3397ab7b1ccf79269127f1abfb7d484a1e3c3fa094a114e6565f72f574d4e79181b395
7
+ data.tar.gz: d62b06b269d7ad12cf580ad14107cae57a66c5a478c551f2f6aff439f4c3ce6e8a7753e3793c37891f460c400f980b0926595f635e9a013c3762ee62e7b67c5a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 zxy
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,38 @@
1
+ # LwqzxAuth
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 'lwqzx_auth'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install lwqzx_auth
22
+ ```
23
+
24
+ ## method added
25
+
26
+ attachit : can be used in controller to add tempfile to mongodb
27
+
28
+ ```ruby
29
+ group[:logo] = attachit("group",:logo)
30
+ ```
31
+ pageit: can be used in controller for page model
32
+
33
+ is_login? : can be used in controller or views to test login status
34
+
35
+ need_login: can be used in controller
36
+
37
+ ## License
38
+ 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 = 'LwqzxAuth'
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/lwqzx_auth .js
2
+ //= link_directory ../stylesheets/lwqzx_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,4 @@
1
+ /*
2
+ *= require_tree .
3
+ *= require_self
4
+ */
@@ -0,0 +1,13 @@
1
+ require 'grpc'
2
+ require 'grpcd_services_pb'
3
+
4
+ module GrpcAuth
5
+ class ApplicationController < ::ApplicationController
6
+ protect_from_forgery with: :exception
7
+
8
+ def stub
9
+ Grpcd::Grpcd::Stub.new(ENV['GRPCD_ADDRESS'], :this_channel_is_insecure)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,48 @@
1
+ require_dependency "grpc_auth/application_controller"
2
+
3
+ module GrpcAuth
4
+ class AuthController < ApplicationController
5
+ def login
6
+ end
7
+
8
+ def logout
9
+ flash[:notice]="你已经登出"
10
+ reset_session
11
+ redirect_to main_app.root_path
12
+ end
13
+
14
+ def auth
15
+ unless verify_rucaptcha?
16
+ flash[:alert] = "验证码出错"
17
+ redirect_to main_app.root_path and return
18
+ end
19
+
20
+ login = params[:login]
21
+ psd = params[:password]
22
+ hsh = gauth(login,psd)
23
+ if hsh == false
24
+ redirect_to login_path , alert: "用户信息有误" and return
25
+ else
26
+ name = hsh.RealName
27
+ groups = hsh.Tags
28
+ session[:login] = login
29
+ session[:realname] = name
30
+ session[:groups] = groups
31
+ redirect_to main_app.root_path and return
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def gauth(login,passwd)
38
+ request = Grpcd::AuthRequest.new(Login: login,Password: passwd)
39
+ begin
40
+ reply = stub.auth(request)
41
+ rescue
42
+ return false
43
+ else
44
+ return reply
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ module GrpcAuth
2
+ module ApplicationHelper
3
+ def is_login?
4
+ !!session[:login]
5
+ end
6
+
7
+ end
8
+
9
+ module ApplicationOnly
10
+
11
+ def need_login
12
+ unless is_login?
13
+ flash[:alert] = "你还没有登录"
14
+ redirect_to grpc_auth.login_path and return
15
+ end
16
+ end
17
+
18
+ def pageit
19
+ params[:page] ||= 1
20
+ per_page = 10
21
+ @num=per_page*(params[:page].to_i-1)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ module GrpcAuth
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
File without changes
File without changes
@@ -0,0 +1,39 @@
1
+ h2.text-center =<> icon("fas","user") + ' 登 录'
2
+ br
3
+ .row
4
+ .col-sm-4
5
+ .col-sm-4
6
+ = form_tag auth_path, role: "form", class: "loginForm card form-horizontal" do
7
+ .card-body
8
+ strong 登录名
9
+ br
10
+ = text_field_tag :login,nil,class: "form-control"
11
+ br
12
+ strong 密码:
13
+ br
14
+ = password_field_tag :password,nil, class: "form-control"
15
+ p.text-center
16
+ a.rucaptcha-image-box href="#" = rucaptcha_image_tag
17
+ p.text-center = rucaptcha_input_tag(class: 'form-control code',placeholder: "输入验证码")
18
+
19
+ .card-footer
20
+ = submit_tag '登录', class: "btn-block btn-primary btn"
21
+
22
+ .col-sm-4
23
+
24
+ javascript:
25
+ javascript:
26
+ $(".loginForm").submit(function(event){
27
+ if($("input.code").val()==""){alert("请填写验证码");return false;};
28
+ if($("input.login").val()==""){alert("登录名不能为空");return false;};
29
+ if($("input.password").val()==""){alert("密码不能为空");return false;};
30
+ });
31
+
32
+ $("a.rucaptcha-image-box").click(function(e){
33
+ e.preventDefault();
34
+ btn = $(e.currentTarget);
35
+ img = btn.find('img:first');
36
+ currentSrc = img.attr('src');
37
+ img.attr('src', currentSrc.split('?')[0] + '?' + (new Date()).getTime());
38
+ return false;
39
+ });
@@ -0,0 +1,3 @@
1
+ RuCaptcha.configure do
2
+ self.cache_store = :mem_cache_store
3
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ GrpcAuth::Engine.routes.draw do
2
+ get 'login' => "auth#login", as: :login
3
+ get 'logout' => "auth#logout", as: :logout
4
+ post 'auth' => "auth#auth", as: :auth
5
+ end
@@ -0,0 +1,22 @@
1
+ module GrpcAuth
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace GrpcAuth
4
+
5
+ config.before_initialize do
6
+ ActiveSupport.on_load :action_controller do
7
+ include GrpcAuth::ApplicationHelper
8
+ include GrpcAuth::ApplicationOnly
9
+ end
10
+
11
+ ActiveSupport.on_load :action_view do
12
+ include GrpcAuth::ApplicationHelper
13
+ end
14
+ end
15
+
16
+ initializer "grpc_auth.mount" do |app|
17
+ app.routes.prepend do
18
+ mount GrpcAuth::Engine => ENV["LWQZX_AUTH_MOUNT_PATH"]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module GrpcAuth
2
+ VERSION = '0.0.1'
3
+ end
data/lib/grpc_auth.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "grpc_auth/engine"
2
+ require "grpc"
3
+ require 'grpcd_services_pb'
4
+
5
+ module GrpcAuth
6
+ end
data/lib/grpcd.proto ADDED
@@ -0,0 +1,80 @@
1
+ syntax = "proto3";
2
+
3
+ package grpcd;
4
+
5
+ service Grpcd {
6
+ rpc CourseNames(CourseNamesRequest) returns (CourseNamesReply) {};
7
+ rpc GroupNames(GroupNamesRequest) returns (GroupNamesReply) {};
8
+ rpc Group(GroupRequest) returns (GroupReply) {};
9
+ rpc Semesters(SemestersRequest) returns (SemestersReply) {};
10
+ rpc CurrentSemester(CurrentSemesterRequest) returns (SemesterReply) {};
11
+ rpc CurrentWeek(CurrentWeekRequest) returns (CurrentWeekReply) {};
12
+ rpc Auth(AuthRequest) returns (AuthReply) {};
13
+ }
14
+
15
+ message CurrentWeekRequest {
16
+
17
+ }
18
+
19
+ message CurrentWeekReply {
20
+ int32 WeekNum = 1;
21
+ }
22
+
23
+ message CourseNamesRequest{
24
+
25
+ }
26
+
27
+ message CourseNamesReply{
28
+ repeated string Names = 1;
29
+ }
30
+
31
+ message GroupNamesRequest{
32
+
33
+ }
34
+
35
+ message GroupNamesReply{
36
+ repeated string Names = 1;
37
+ }
38
+
39
+ message GroupRequest {
40
+ string Name = 1;
41
+ }
42
+
43
+ message GroupReply {
44
+ string Name = 1;
45
+ string Master = 2;
46
+ string Members = 3;
47
+ }
48
+
49
+ message SemestersRequest{
50
+
51
+ }
52
+
53
+ message SemesterReply{
54
+ string ID = 1;
55
+ string Name = 2;
56
+ string ShortName = 3;
57
+ string BeginOn = 4;
58
+ string EndOn = 5;
59
+ string Current = 6;
60
+ }
61
+
62
+ message SemestersReply{
63
+ repeated SemesterReply Semes = 1;
64
+ }
65
+
66
+ message CurrentSemesterRequest {
67
+
68
+ }
69
+
70
+ message AuthRequest{
71
+ string Login = 1;
72
+ string Password = 2;
73
+ }
74
+
75
+ message AuthReply{
76
+ bool Logined = 1;
77
+ string Login = 2;
78
+ string RealName = 3;
79
+ string Tags = 4;
80
+ }
data/lib/grpcd_pb.rb ADDED
@@ -0,0 +1,74 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: grpcd.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("grpcd.proto", :syntax => :proto3) do
8
+ add_message "grpcd.CurrentWeekRequest" do
9
+ end
10
+ add_message "grpcd.CurrentWeekReply" do
11
+ optional :WeekNum, :int32, 1
12
+ end
13
+ add_message "grpcd.CourseNamesRequest" do
14
+ end
15
+ add_message "grpcd.CourseNamesReply" do
16
+ repeated :Names, :string, 1
17
+ end
18
+ add_message "grpcd.GroupNamesRequest" do
19
+ end
20
+ add_message "grpcd.GroupNamesReply" do
21
+ repeated :Names, :string, 1
22
+ end
23
+ add_message "grpcd.GroupRequest" do
24
+ optional :Name, :string, 1
25
+ end
26
+ add_message "grpcd.GroupReply" do
27
+ optional :Name, :string, 1
28
+ optional :Master, :string, 2
29
+ optional :Members, :string, 3
30
+ end
31
+ add_message "grpcd.SemestersRequest" do
32
+ end
33
+ add_message "grpcd.SemesterReply" do
34
+ optional :ID, :string, 1
35
+ optional :Name, :string, 2
36
+ optional :ShortName, :string, 3
37
+ optional :BeginOn, :string, 4
38
+ optional :EndOn, :string, 5
39
+ optional :Current, :string, 6
40
+ end
41
+ add_message "grpcd.SemestersReply" do
42
+ repeated :Semes, :message, 1, "grpcd.SemesterReply"
43
+ end
44
+ add_message "grpcd.CurrentSemesterRequest" do
45
+ end
46
+ add_message "grpcd.AuthRequest" do
47
+ optional :Login, :string, 1
48
+ optional :Password, :string, 2
49
+ end
50
+ add_message "grpcd.AuthReply" do
51
+ optional :Logined, :bool, 1
52
+ optional :Login, :string, 2
53
+ optional :RealName, :string, 3
54
+ optional :Tags, :string, 4
55
+ end
56
+ end
57
+ end
58
+
59
+ module Grpcd
60
+ CurrentWeekRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.CurrentWeekRequest").msgclass
61
+ CurrentWeekReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.CurrentWeekReply").msgclass
62
+ CourseNamesRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.CourseNamesRequest").msgclass
63
+ CourseNamesReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.CourseNamesReply").msgclass
64
+ GroupNamesRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.GroupNamesRequest").msgclass
65
+ GroupNamesReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.GroupNamesReply").msgclass
66
+ GroupRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.GroupRequest").msgclass
67
+ GroupReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.GroupReply").msgclass
68
+ SemestersRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.SemestersRequest").msgclass
69
+ SemesterReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.SemesterReply").msgclass
70
+ SemestersReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.SemestersReply").msgclass
71
+ CurrentSemesterRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.CurrentSemesterRequest").msgclass
72
+ AuthRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.AuthRequest").msgclass
73
+ AuthReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpcd.AuthReply").msgclass
74
+ end
@@ -0,0 +1,28 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: grpcd.proto for package 'grpcd'
3
+
4
+ require 'grpc'
5
+ require 'grpcd_pb'
6
+
7
+ module Grpcd
8
+ module Grpcd
9
+ class Service
10
+
11
+ include GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'grpcd.Grpcd'
16
+
17
+ rpc :CourseNames, CourseNamesRequest, CourseNamesReply
18
+ rpc :GroupNames, GroupNamesRequest, GroupNamesReply
19
+ rpc :Group, GroupRequest, GroupReply
20
+ rpc :Semesters, SemestersRequest, SemestersReply
21
+ rpc :CurrentSemester, CurrentSemesterRequest, SemesterReply
22
+ rpc :CurrentWeek, CurrentWeekRequest, CurrentWeekReply
23
+ rpc :Auth, AuthRequest, AuthReply
24
+ end
25
+
26
+ Stub = Service.rpc_stub_class
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grpc_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - zxy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: auth function into host app.
28
+ email:
29
+ - zxy@qq.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/lwqzx_auth_manifest.js
38
+ - app/assets/javascripts/lwqzx_auth/application.js
39
+ - app/assets/stylesheets/lwqzx_auth/application.scss
40
+ - app/controllers/grpc_auth/application_controller.rb
41
+ - app/controllers/grpc_auth/auth_controller.rb
42
+ - app/helpers/grpc_auth/application_helper.rb
43
+ - app/jobs/grpc_auth/application_job.rb
44
+ - app/mailers/grpc_auth/application_mailer.rb
45
+ - app/models/grpc_auth/application_record.rb
46
+ - app/views/grpc_auth/auth/login.html.slim
47
+ - config/initializers/rucaptcha.rb
48
+ - config/routes.rb
49
+ - lib/grpc_auth.rb
50
+ - lib/grpc_auth/engine.rb
51
+ - lib/grpc_auth/version.rb
52
+ - lib/grpcd.proto
53
+ - lib/grpcd_pb.rb
54
+ - lib/grpcd_services_pb.rb
55
+ homepage: https://www.zapps.online
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.0.3
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: add grpc auth function and auth engine to host application.
78
+ test_files: []