lwqzx_auth 0.1.6 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64272f39bbb1397e25389d8b596f1d66cb940dd350e4d32cddc3334567dda01a
4
- data.tar.gz: c14332035bf008e1ed5c8a812e27590677bcff97887b0df36a24f820d8956103
3
+ metadata.gz: b8c9ac0050837dc3ba05208b6cf877256463594c799cf4b137670145dedc574f
4
+ data.tar.gz: ec8eddbbdddf5b3e47c56ae84dfa96631775be444fafbdb0188b0ce764e61d80
5
5
  SHA512:
6
- metadata.gz: a842d49963961e790f055fe069db1805606e56d5b281193cbd5e1267b675163dc07871981c20f5a77064864ab72a450ee5e6a8ce654b7213c192265ef6181832
7
- data.tar.gz: f0510454c1f24fcf8c0576aad604673d78de886ced7b4cbece782c09ee8be93f4fa63b877095909be0c276fb04a76249d93ff7a34609edcb20dc64b20de5b24b
6
+ metadata.gz: 3518aff0e40db0abf15db0eb3118eb732ad0649c984adcb8bdbc3157c4070db343a1ac76869612e7a1d21ca336e379ad03e6d63c819fa1656768b38f4673a087
7
+ data.tar.gz: '08cbd3dc914637acf9d81e091f1154596ab2323fe4a4a346c8d07c88f6cb225341cc5714936fc36db17e815224ba1d2107370694c20420910c86b4aa50d91090'
@@ -1,6 +1,22 @@
1
1
  module LwqzxAuth
2
2
  class ApplicationController < ::ApplicationController
3
3
  protect_from_forgery with: :exception
4
-
4
+ before_action :check_me
5
+ def check_me
6
+ auth_token = cookies.signed[:auth_token]
7
+ unless auth_token.blank?
8
+ one = Remember.where(token: auth_token).first
9
+ if one
10
+ if one.expired > Time.now.to_i
11
+ session[:login] = one.login
12
+ session[:realname] = one.name
13
+ session[:groups] = one.groups
14
+ else
15
+ cookies.delete(:auth_token)
16
+ one.delete
17
+ end
18
+ end
19
+ end
20
+ end
5
21
  end
6
22
  end
@@ -1,4 +1,5 @@
1
1
  require_dependency "lwqzx_auth/application_controller"
2
+ require "rest-client"
2
3
 
3
4
  module LwqzxAuth
4
5
  class AuthController < ApplicationController
@@ -7,6 +8,13 @@ module LwqzxAuth
7
8
 
8
9
  def logout
9
10
  flash[:notice]="你已经登出"
11
+
12
+ auth_token = cookies[:auth_token]
13
+ unless auth_token.blank?
14
+ one = Remember.where(token: auth_token).first
15
+ cookies.delete(:auth_token)
16
+ one.delete if one
17
+ end
10
18
  reset_session
11
19
  redirect_to main_app.root_path
12
20
  end
@@ -19,12 +27,26 @@ module LwqzxAuth
19
27
 
20
28
  login = params[:login]
21
29
  psd = params[:password]
30
+
22
31
  hsh = lauth(login,psd)
23
- if hsh.blank?
32
+ if hsh["name"].blank?
24
33
  redirect_to login_path , alert: "用户信息有误"
25
34
  else
26
- name = hsh[:name]
27
- groups = hsh[:groups]
35
+ login = hsh["login"]
36
+ name = hsh["name"]
37
+ groups = hsh["user_group"]
38
+
39
+ #rememberme = params[:rememberme]
40
+ #if rememberme == "yes"
41
+ # token = SecureRandom.urlsafe_base64
42
+ # cookies.signed[:auth_token] = token
43
+ # Remember.create(token: token, login: login, name: name, groups: groups,expired: 7.days.from_now.to_i)
44
+ #else
45
+ # auth_token = cookies[:auth_token]
46
+ # cookies.delete(:auth_token)
47
+ # Remember.where(token: auth_token).delete
48
+ #end
49
+
28
50
  session[:login] = login
29
51
  session[:realname] = name
30
52
  session[:groups] = groups
@@ -33,17 +55,11 @@ module LwqzxAuth
33
55
  end
34
56
 
35
57
  private
58
+
36
59
  def lauth(login,passwd)
37
- lurl = "http://www.lwqzx.sdedu.net/kernel/net_school/active_app/login1.php"
38
- res1 = RestClient.post lurl,{login_user_m_: login, login_password: passwd}
39
- res2 = RestClient.get lurl,{cookies: res1.cookies}
40
- content=res2.body.encode("UTF-8","GB2312")
41
- doc = Nokogiri::HTML(content)
42
- return {} if doc.include?("login_submit")
43
- uname = doc.css("span.tt1 a:nth-child(1)").text
44
- groups = doc.css("span.tt1 a:nth-child(5)")[0]["title"]
45
- groups=groups.gsub("[","").gsub("]","").split("@").compact.reject(&:empty?)
46
- return {login: login, name: uname, groups: groups}
60
+ lurl = "http://www.lwqzx.sdedu.net/kernel/net_school/core/jslogin.php"
61
+ res = ::RestClient.post lurl,{login: login, password: passwd}
62
+ return JSON.parse(res.body)
47
63
  end
48
64
 
49
65
  end
@@ -0,0 +1,10 @@
1
+ module LwqzxAuth
2
+ class Remember
3
+ include Mongoid::Document
4
+ field :token, type: String
5
+ field :login, type: String
6
+ field :name, type: String
7
+ field :groups, type: String
8
+ field :expired, type: Integer
9
+ end
10
+ end
@@ -1,39 +1,20 @@
1
1
  h2.text-center =<> icon("fas","user") + ' 登 录'
2
2
  br
3
3
  .row
4
- .col-sm-4
5
- .col-sm-4
4
+ .col-12.col-md-4.offset-md-4.align-self-center
6
5
  = form_tag auth_path, role: "form", class: "loginForm card form-horizontal" do
7
6
  .card-body
8
- strong 登录名
7
+ p: strong 登录名
8
+ div = text_field_tag :login,nil,class: "form-control login"
9
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"
10
+ p: strong 密码
11
+ div = password_field_tag :password,nil, class: "form-control password"
15
12
  p.text-center
16
13
  a.rucaptcha-image-box href="#" = rucaptcha_image_tag
17
14
  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
- });
15
+ /p.text-center
16
+ =<> check_box_tag :rememberme, "yes", false
17
+ | 记住7天
18
+ div.mt-3
19
+ = submit_tag '登录', class: "btn-block btn-primary btn btn-lg"
20
+ /.card-footer
@@ -1,3 +1,3 @@
1
1
  module LwqzxAuth
2
- VERSION = '0.1.6'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lwqzx_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zxy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
13
27
  description: auth function into host app.
14
28
  email:
15
29
  - zxy@qq.com
@@ -26,9 +40,7 @@ files:
26
40
  - app/controllers/lwqzx_auth/application_controller.rb
27
41
  - app/controllers/lwqzx_auth/auth_controller.rb
28
42
  - app/helpers/lwqzx_auth/application_helper.rb
29
- - app/jobs/lwqzx_auth/application_job.rb
30
- - app/mailers/lwqzx_auth/application_mailer.rb
31
- - app/models/lwqzx_auth/application_record.rb
43
+ - app/models/lwqzx_auth/remember.rb
32
44
  - app/views/lwqzx_auth/auth/login.html.slim
33
45
  - config/initializers/rucaptcha.rb
34
46
  - config/routes.rb
@@ -55,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
67
  - !ruby/object:Gem::Version
56
68
  version: '0'
57
69
  requirements: []
58
- rubyforge_project:
59
- rubygems_version: 2.7.7
70
+ rubygems_version: 3.1.4
60
71
  signing_key:
61
72
  specification_version: 4
62
73
  summary: add auth function to host application.
@@ -1,4 +0,0 @@
1
- module LwqzxAuth
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end