ucenter 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39fb7334c69206eda4dc53352bc1761faa573f8d
4
- data.tar.gz: 59c136c1cd60937283cd40c59ad738be9976ed33
3
+ metadata.gz: b5edfc93a65098a7c44d33b99473a523d2188f33
4
+ data.tar.gz: b44bf15c3d41881d85fa24c54176fc2536ad41ae
5
5
  SHA512:
6
- metadata.gz: 5ab39a314f899cdaf779ba25b52dda6b9ad7b71b5e56aacbc95179c60c6cda71774b20c12325cb6a31e7329a1d673a4f200f34e6924eb741b64581cc21da16b7
7
- data.tar.gz: 35d08c5f26b5c8b27b25fdcbd4cfe2f074a1a198a045a1de15a3ae6cf0427275a1ba7d694b0e25d66d256b9b6bfa699f821841e03f04e8abef21480029cba900
6
+ metadata.gz: 6c7b93cdad2cec9c19ec572d7eefa05e95553b82907714cfd5a5031019a52f58d6d3fc713f0d484a35c414989a6c3968ce47029e74992a9b828ac9d06c5cb22b
7
+ data.tar.gz: 865d3f7b7740bc1b30172f99d940e90fcd87c0a995254b0f9754807259023d661ecd71eeb6e963c27869bd356d218b7b49b0ef35e144f223f22323ddd37a2376
@@ -6,9 +6,12 @@ module Ucenter
6
6
  where = db_client.escape(where)
7
7
  data = db_client.query("SELECT #{col} FROM #{Ucenter::Config.uc_dbtablepre}applications #{where!="" ? " WHERE #{where} " : ""}").to_a
8
8
  data.each_with_index do |item,index|
9
- item['extra'] = Ucenter::Tools::PHP.unserialize(item['extra'])
10
- data[index] = item
9
+ if item['extra'] and item['extra'].strip!=""
10
+ item['extra'] = Ucenter::Tools::PHP.unserialize(item['extra'])
11
+ data[index] = item
12
+ end
11
13
  end
14
+ data
12
15
  end
13
16
  end
14
17
  end
@@ -4,6 +4,13 @@ module Ucenter
4
4
  class Base
5
5
  def initialize(client)
6
6
  @client = client
7
+ config = Hash.new
8
+ config[:host] = Ucenter::Config.uc_dbhost unless Ucenter::Config.uc_dbhost.nil?
9
+ config[:username] = Ucenter::Config.uc_dbuser unless Ucenter::Config.uc_dbuser.nil?
10
+ config[:password] = Ucenter::Config.uc_dbpw unless Ucenter::Config.uc_dbpw.nil?
11
+ config[:database] = Ucenter::Config.uc_dbname unless Ucenter::Config.uc_dbname.nil?
12
+ config[:encoding] = Ucenter::Config.uc_dbcharset unless Ucenter::Config.uc_dbcharset.nil?
13
+ @db_client = Mysql2::Client.new(config)
7
14
  end
8
15
 
9
16
  def get(path, opts={}, &block)
@@ -15,13 +22,7 @@ module Ucenter
15
22
  end
16
23
 
17
24
  def db_client
18
- config = Hash.new
19
- config[:host] = Ucenter::Config.uc_dbhost unless Ucenter::Config.uc_dbhost.nil?
20
- config[:username] = Ucenter::Config.uc_dbuser unless Ucenter::Config.uc_dbuser.nil?
21
- config[:password] = Ucenter::Config.uc_dbpw unless Ucenter::Config.uc_dbpw.nil?
22
- config[:database] = Ucenter::Config.uc_dbname unless Ucenter::Config.uc_dbname.nil?
23
- config[:encoding] = Ucenter::Config.uc_dbcharset unless Ucenter::Config.uc_dbcharset.nil?
24
- Mysql2::Client.new(config)
25
+ @db_client
25
26
  end
26
27
 
27
28
  end
@@ -53,8 +53,20 @@ module Ucenter
53
53
  db_client.query("SELECT count(*) FROM #{Ucenter::Config.uc_dbtablepre}mergemembers WHERE appid='#{Ucenter::Config.app_id}' AND username='#{username}'").to_a[0]
54
54
  end
55
55
 
56
- def add_user
56
+ def add_user (username, password, email, uid = 0, questionid = '', answer = '', regip = '', phone = '')
57
57
  # TODO: 注册
58
+ # Aaron 2014-08-28
59
+ salt = UUID.new.generate[1,6]
60
+ password = md5(md5(password)+salt)
61
+ sqladd = uid.to_i==0 ? "" : ("uid='" + uid.to_i.to_s + "', " )
62
+ sqladd += questionid.to_i > 0 ? (" secques='" + quescrypt(questionid,answer) + "', ") : " secques='', "
63
+ sqladd += phone.empty? ? " " : " phone='#{phone}', "
64
+ sql= "insert into #{Ucenter::Config.uc_dbtablepre}members set #{sqladd} username='#{username}', password='#{password}', email='#{email}', regip='#{regip}', regdate='#{Time.now.to_i}', salt='#{salt}'"
65
+ client = db_client
66
+ client.query(sql)
67
+ inserted_id = client.last_id
68
+ client.query("insert into #{Ucenter::Config.uc_dbtablepre}memberfields set uid='#{inserted_id}'")
69
+ inserted_id
58
70
  end
59
71
 
60
72
  def edit_user
@@ -82,6 +94,10 @@ module Ucenter
82
94
  db_client.query("SELECT * FROM #{Ucenter::Config.uc_dbtablepre}members WHERE phone='#{username}'").to_a[0]
83
95
  end
84
96
 
97
+ def quescrypt(questionid, answer)
98
+ return questionid > 0 && answer != '' ? md5(answer.md5(questionid))[16,8] : '';
99
+ end
100
+
85
101
  private
86
102
  def md5 str; Digest::MD5.hexdigest str.to_s end
87
103
  end
@@ -1,3 +1,3 @@
1
1
  module Ucenter
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake", "~>0"
23
23
  spec.add_development_dependency "mysql2", "~>0"
24
24
  spec.add_development_dependency "nokogiri", "~>0"
25
+ spec.add_development_dependency "uuid", "~>0"
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ucenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willin Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-28 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: uuid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: http://willin.wang visit for more info.
70
84
  email: willin@willin.org
71
85
  executables: []