Description:
fix wrong merge on user
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r845:daf5f8de8a3f - - 1 file changed: 4 inserted, 0 deleted
@@ -43,96 +43,100 | |||||
|
43 |
|
43 | ||
|
44 | validates_presence_of :password, :if => :password_required? |
|
44 | validates_presence_of :password, :if => :password_required? |
|
45 | validates_length_of :password, :within => 4..50, :if => :password_required? |
|
45 | validates_length_of :password, :within => 4..50, :if => :password_required? |
|
46 | validates_confirmation_of :password, :if => :password_required? |
|
46 | validates_confirmation_of :password, :if => :password_required? |
|
47 |
|
47 | ||
|
48 | validates_format_of :email, |
|
48 | validates_format_of :email, |
|
49 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
49 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
50 | :if => :email_validation? |
|
50 | :if => :email_validation? |
|
51 | validate :uniqueness_of_email_from_activated_users, |
|
51 | validate :uniqueness_of_email_from_activated_users, |
|
52 | :if => :email_validation? |
|
52 | :if => :email_validation? |
|
53 | validate :enough_time_interval_between_same_email_registrations, |
|
53 | validate :enough_time_interval_between_same_email_registrations, |
|
54 | :if => :email_validation? |
|
54 | :if => :email_validation? |
|
55 |
|
55 | ||
|
56 | # these are for ytopc |
|
56 | # these are for ytopc |
|
57 | # disable for now |
|
57 | # disable for now |
|
58 | #validates_presence_of :province |
|
58 | #validates_presence_of :province |
|
59 |
|
59 | ||
|
60 | attr_accessor :password |
|
60 | attr_accessor :password |
|
61 |
|
61 | ||
|
62 | before_save :encrypt_new_password |
|
62 | before_save :encrypt_new_password |
|
63 | before_save :assign_default_site |
|
63 | before_save :assign_default_site |
|
64 | before_save :assign_default_contest |
|
64 | before_save :assign_default_contest |
|
65 |
|
65 | ||
|
66 | # this is for will_paginate |
|
66 | # this is for will_paginate |
|
67 | cattr_reader :per_page |
|
67 | cattr_reader :per_page |
|
68 | @@per_page = 50 |
|
68 | @@per_page = 50 |
|
69 |
|
69 | ||
|
70 | def self.authenticate(login, password) |
|
70 | def self.authenticate(login, password) |
|
71 | user = find_by_login(login) |
|
71 | user = find_by_login(login) |
|
72 | if user |
|
72 | if user |
|
73 | return user if user.authenticated?(password) |
|
73 | return user if user.authenticated?(password) |
|
74 | if user.authenticated_by_cucas?(password) |
|
74 | if user.authenticated_by_cucas?(password) |
|
75 | user.password = password |
|
75 | user.password = password |
|
76 | user.save |
|
76 | user.save |
|
77 | return user |
|
77 | return user |
|
78 | end |
|
78 | end |
|
79 | end |
|
79 | end |
|
80 | end |
|
80 | end |
|
81 |
|
81 | ||
|
82 |
|
82 | ||
|
83 | def authenticated?(password) |
|
83 | def authenticated?(password) |
|
84 | if self.activated |
|
84 | if self.activated |
|
85 | hashed_password == User.encrypt(password,self.salt) |
|
85 | hashed_password == User.encrypt(password,self.salt) |
|
86 | else |
|
86 | else |
|
87 | false |
|
87 | false |
|
88 | end |
|
88 | end |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
|
91 | + def login_with_name | ||
|
|
92 | + "[#{login}] #{full_name}" | ||
|
|
93 | + end | ||
|
|
94 | + | ||
|
91 | def authenticated_by_cucas?(password) |
|
95 | def authenticated_by_cucas?(password) |
|
92 | url = URI.parse('https://www.cas.chula.ac.th/cas/api/?q=studentAuthenticate') |
|
96 | url = URI.parse('https://www.cas.chula.ac.th/cas/api/?q=studentAuthenticate') |
|
93 | appid = '41508763e340d5858c00f8c1a0f5a2bb' |
|
97 | appid = '41508763e340d5858c00f8c1a0f5a2bb' |
|
94 | appsecret ='d9cbb5863091dbe186fded85722a1e31' |
|
98 | appsecret ='d9cbb5863091dbe186fded85722a1e31' |
|
95 | post_args = { |
|
99 | post_args = { |
|
96 | 'appid' => appid, |
|
100 | 'appid' => appid, |
|
97 | 'appsecret' => appsecret, |
|
101 | 'appsecret' => appsecret, |
|
98 | 'username' => login, |
|
102 | 'username' => login, |
|
99 | 'password' => password |
|
103 | 'password' => password |
|
100 | } |
|
104 | } |
|
101 |
|
105 | ||
|
102 | #simple call |
|
106 | #simple call |
|
103 | begin |
|
107 | begin |
|
104 | http = Net::HTTP.new('www.cas.chula.ac.th', 443) |
|
108 | http = Net::HTTP.new('www.cas.chula.ac.th', 443) |
|
105 | http.use_ssl = true |
|
109 | http.use_ssl = true |
|
106 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE |
|
110 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE |
|
107 | result = [ ] |
|
111 | result = [ ] |
|
108 | http.start do |http| |
|
112 | http.start do |http| |
|
109 | req = Net::HTTP::Post.new('/cas/api/?q=studentAuthenticate') |
|
113 | req = Net::HTTP::Post.new('/cas/api/?q=studentAuthenticate') |
|
110 | #req = Net::HTTP::Post.new('/appX/prod/?q=studentAuthenticate') |
|
114 | #req = Net::HTTP::Post.new('/appX/prod/?q=studentAuthenticate') |
|
111 | #req = Net::HTTP::Post.new('/app2/prod/api/?q=studentAuthenticate') |
|
115 | #req = Net::HTTP::Post.new('/app2/prod/api/?q=studentAuthenticate') |
|
112 | param = "appid=#{appid}&appsecret=#{appsecret}&username=#{login}&password=#{password}" |
|
116 | param = "appid=#{appid}&appsecret=#{appsecret}&username=#{login}&password=#{password}" |
|
113 | resp = http.request(req,param) |
|
117 | resp = http.request(req,param) |
|
114 | result = JSON.parse resp.body |
|
118 | result = JSON.parse resp.body |
|
115 | puts result |
|
119 | puts result |
|
116 | end |
|
120 | end |
|
117 | return true if result["type"] == "beanStudent" |
|
121 | return true if result["type"] == "beanStudent" |
|
118 | rescue => e |
|
122 | rescue => e |
|
119 | puts e |
|
123 | puts e |
|
120 | puts e.message |
|
124 | puts e.message |
|
121 | return false |
|
125 | return false |
|
122 | end |
|
126 | end |
|
123 | return false |
|
127 | return false |
|
124 | end |
|
128 | end |
|
125 |
|
129 | ||
|
126 | def admin? |
|
130 | def admin? |
|
127 | has_role?('admin') |
|
131 | has_role?('admin') |
|
128 | end |
|
132 | end |
|
129 |
|
133 | ||
|
130 | def has_role?(role) |
|
134 | def has_role?(role) |
|
131 | self.roles.where(name: role).count > 0 |
|
135 | self.roles.where(name: role).count > 0 |
|
132 | end |
|
136 | end |
|
133 |
|
137 | ||
|
134 | def email_for_editing |
|
138 | def email_for_editing |
|
135 | if self.email==nil |
|
139 | if self.email==nil |
|
136 | "(unknown)" |
|
140 | "(unknown)" |
|
137 | elsif self.email=='' |
|
141 | elsif self.email=='' |
|
138 | "(blank)" |
|
142 | "(blank)" |
You need to be logged in to leave comments.
Login now