Description:
added password recovery through e-mails git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@400 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r189:5c9646c12fab - - 5 files changed: 120 inserted, 4 deleted

@@ -0,0 +1,18
1 + .contest-title
2 + %h1
3 + = "#{Configuration['contest.name']}: #{t 'registration.password_retrieval.header'}"
4 +
5 + - if flash[:notice]
6 + %hr/
7 + %b= flash[:notice]
8 + %hr/
9 +
10 + %br/
11 +
12 + - form_tag :action => 'retrieve_password' do
13 + =t 'registration.password_retrieval.instructions'
14 + = text_field 'email', nil, :size => 20
15 + %br/
16 + = submit_tag(t 'registration.password_retrieval.button_label')
17 +
18 + = link_to "#{t 'go_back_to'}#{t 'home_page'}", :controller => 'main', :action => 'index'
@@ -1,14 +1,21
1 require 'tmail'
1 require 'tmail'
2 require 'net/smtp'
2 require 'net/smtp'
3
3
4 class UsersController < ApplicationController
4 class UsersController < ApplicationController
5
5
6 - before_filter :authenticate, :except => [:new, :register, :confirm]
6 + before_filter :authenticate, :except => [:new,
7 + :register,
8 + :confirm,
9 + :forget,
10 + :retrieve_password]
7
11
8 - before_filter :verify_online_registration, :only => [:new, :register]
12 + before_filter :verify_online_registration, :only => [:new,
13 + :register,
14 + :forget,
15 + :retrieve_password]
9
16
10 verify :method => :post, :only => [:chg_passwd],
17 verify :method => :post, :only => [:chg_passwd],
11 :redirect_to => { :action => :index }
18 :redirect_to => { :action => :index }
12
19
13 #in_place_edit_for :user, :alias_for_editing
20 #in_place_edit_for :user, :alias_for_editing
14 #in_place_edit_for :user, :email_for_editing
21 #in_place_edit_for :user, :email_for_editing
@@ -74,12 +81,34
74 else
81 else
75 @result = :failed
82 @result = :failed
76 end
83 end
77 render :action => 'confirm', :layout => 'empty'
84 render :action => 'confirm', :layout => 'empty'
78 end
85 end
79
86
87 + def forget
88 + render :action => 'forget', :layout => 'empty'
89 + end
90 +
91 + def retrieve_password
92 + email = params[:email]
93 + user = User.find_by_email(email)
94 + if user
95 + last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour)
96 + if last_updated_time > Time.now.gmtime - 5.minutes
97 + flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes'
98 + else
99 + user.password = user.password_confirmation = User.random_password
100 + send_new_password_email(user)
101 + flash[:notice] = 'New password has been mailed to you.'
102 + end
103 + else
104 + flash[:notice] = I18n.t 'registration.password_retrieval.no_email'
105 + end
106 + redirect_to :action => 'forget'
107 + end
108 +
80 protected
109 protected
81
110
82 def verify_online_registration
111 def verify_online_registration
83 if !Configuration['system.online_registration']
112 if !Configuration['system.online_registration']
84 redirect_to :controller => 'main', :action => 'login'
113 redirect_to :controller => 'main', :action => 'login'
85 end
114 end
@@ -118,7 +147,38
118 result = false
147 result = false
119 end
148 end
120
149
121 return result
150 return result
122 end
151 end
123
152
153 + def send_new_password_email(user)
154 + contest_name = Configuration['contest.name']
155 + admin_email = Configuration['system.admin_email']
156 + mail = TMail::Mail.new
157 + mail.to = user.email
158 + mail.from = Configuration['system.online_registration.from']
159 + mail.subject = "[#{contest_name}] Confirmation"
160 + mail.body = t('registration.password_retrieval.email_body', {
161 + :full_name => user.full_name,
162 + :contest_name => contest_name,
163 + :login => user.login,
164 + :password => user.password,
165 + :admin_email => admin_email
166 + })
167 +
168 + logger.info mail.body
169 +
170 + smtp_server = Configuration['system.online_registration.smtp']
171 +
172 + begin
173 + Net::SMTP.start(smtp_server) do |smtp|
174 + smtp.send_message(mail.to_s, mail.from, mail.to)
175 + end
176 + result = true
177 + rescue
178 + result = false
179 + end
180 +
181 + return result
182 + end
183 +
124 end
184 end
@@ -36,7 +36,7
36 - if Configuration['system.online_registration']
36 - if Configuration['system.online_registration']
37 =t 'login.participation'
37 =t 'login.participation'
38 %b
38 %b
39 = "#{t 'login.please'} "
39 = "#{t 'login.please'} "
40 = link_to "#{t 'login.register'}", :controller => :users, :action => :new
40 = link_to "#{t 'login.register'}", :controller => :users, :action => :new
41 %br/
41 %br/
42 -
42 + = link_to "#{t 'login.forget_password'}", :controller => :users, :action => :forget
@@ -32,12 +32,13
32 login:
32 login:
33 message: 'Please login to see the problem list'
33 message: 'Please login to see the problem list'
34 login_submit: 'Login'
34 login_submit: 'Login'
35 participation: 'Want to participate?'
35 participation: 'Want to participate?'
36 please: 'Please'
36 please: 'Please'
37 register: 'register'
37 register: 'register'
38 + forget_password: 'Forget password?'
38
39
39 main:
40 main:
40 start_soon: "The contest at your site will start soon. Please wait."
41 start_soon: "The contest at your site will start soon. Please wait."
41 specified_in_header: "Specified in header"
42 specified_in_header: "Specified in header"
42
43
43 problem_desc: "desc"
44 problem_desc: "desc"
@@ -52,12 +53,15
52 title: "Test Interface"
53 title: "Test Interface"
53 intro: "You can test your submission with your own test data on the grading environment using this test interface."
54 intro: "You can test your submission with your own test data on the grading environment using this test interface."
54 disabled_at_end_announcement: "<b>Note:</b> Test interface will be disabled in the last 30 minutes of the contest time on your site."
55 disabled_at_end_announcement: "<b>Note:</b> Test interface will be disabled in the last 30 minutes of the contest time on your site."
55
56
56 registration:
57 registration:
57 title: "New user registration"
58 title: "New user registration"
59 +
60 + description: "Please enter your information below. Please make sure your e-mail is correct, because you will have to confirm the registration through an e-mail we send to that e-mail address."
61 +
58 successful_title: "Registration successful"
62 successful_title: "Registration successful"
59
63
60 login_guide: "Only a-z, A-Z, 0-9 and _. Can be at most 20 characters long"
64 login_guide: "Only a-z, A-Z, 0-9 and _. Can be at most 20 characters long"
61 email_guide: "Please make sure that your e-mail is correct.<br/>You'll need to verify your account by email."
65 email_guide: "Please make sure that your e-mail is correct.<br/>You'll need to verify your account by email."
62 register: "Register"
66 register: "Register"
63
67
@@ -95,12 +99,29
95 expl: "<h2>Your user account has been created, but the system cannot send you the confirmation e-mail.</h2>
99 expl: "<h2>Your user account has been created, but the system cannot send you the confirmation e-mail.</h2>
96 Maybe there's a problem in the configuration. Please report the admin at {{email}}.<br/>Thank you!"
100 Maybe there's a problem in the configuration. Please report the admin at {{email}}.<br/>Thank you!"
97 activation:
101 activation:
98 email_exists: "A user with this E-mail exists."
102 email_exists: "A user with this E-mail exists."
99 invalid: "Your activation code is invalid. Please check again."
103 invalid: "Your activation code is invalid. Please check again."
100
104
105 + password_retrieval:
106 + header: "Password retrieval"
107 + instructions: "Please enter the e-mail address that you used to register."
108 + button_label: "Request new password"
109 + no_email: "No user with that e-mail address."
110 + email_body: "Hello {{full_name}},
111 +
112 + You have requested for new password for {{contest_name}}. We have generated it for you:
113 +
114 + user name: {{login}}
115 + password: {{password}}
116 +
117 + If you didn't ask for new password or you're not the person who registered,
118 + please ignore this e-mail and inform {{admin_email}} of this mistake.
119 +
120 + Thanks!"
121 +
101 help:
122 help:
102 how_to_submit: "How to submit"
123 how_to_submit: "How to submit"
103 must_specify_language: "You <b>must</b> specify the language you are using in your program header. You can optionally specify the task you are submitting to."
124 must_specify_language: "You <b>must</b> specify the language you are using in your program header. You can optionally specify the task you are submitting to."
104 list_available_language: "The possible language options are <tt>C</tt>, <tt>C++</tt>, and <tt>Pascal</tt>. The follow are examples."
125 list_available_language: "The possible language options are <tt>C</tt>, <tt>C++</tt>, and <tt>Pascal</tt>. The follow are examples."
105 accept_only_language_specified: "The server <b>will not</b> accept your submission, if you do not specify the language."
126 accept_only_language_specified: "The server <b>will not</b> accept your submission, if you do not specify the language."
106 specifying_task: "Optionally, you can also specify the task with <tt>TASK:</tt> <i>taskname</i>. On the first page, the taskname for each task is shown in parentheses."
127 specifying_task: "Optionally, you can also specify the task with <tt>TASK:</tt> <i>taskname</i>. On the first page, the taskname for each task is shown in parentheses."
@@ -32,12 +32,13
32 login:
32 login:
33 message: 'กรุณา login เพื่อเข้าสู่ระบบ'
33 message: 'กรุณา login เพื่อเข้าสู่ระบบ'
34 login_submit: 'เข้าใช้ระบบ'
34 login_submit: 'เข้าใช้ระบบ'
35 participation: 'ต้องการเข้าร่วม?'
35 participation: 'ต้องการเข้าร่วม?'
36 please: 'กรุณา'
36 please: 'กรุณา'
37 register: 'ลงทะเบียน'
37 register: 'ลงทะเบียน'
38 + forget_password: 'ลืมรหัสผ่าน?'
38
39
39 main:
40 main:
40 start_soon: "การแข่งขันกำลังจะเริ่ม กรุณารอก่อน"
41 start_soon: "การแข่งขันกำลังจะเริ่ม กรุณารอก่อน"
41 specified_in_header: "ระบุที่หัวโปรแกรมแล้ว"
42 specified_in_header: "ระบุที่หัวโปรแกรมแล้ว"
42
43
43 problem_desc: "อ่าน"
44 problem_desc: "อ่าน"
@@ -50,13 +51,12
50
51
51 test:
52 test:
52 title: "ทดสอบโปรแกรมบนสภาพแวดล้อมของเครื่องตรวจ"
53 title: "ทดสอบโปรแกรมบนสภาพแวดล้อมของเครื่องตรวจ"
53 intro: "คุณสามารถทดลองการทำงานของโปรแกรมที่เขียนกับข้อมูลชุดทดสอบของคุณเองในสภาพแวดล้อมจริงของการตรวจโปรแกรมได้ โดยเลือกโปรแกรมส่งแล้วที่ด้านล่างพร้อมทั้งส่งแฟ้มข้อมูลชุดทดสอบที่ต้องการให้ทำงานด้วย"
54 intro: "คุณสามารถทดลองการทำงานของโปรแกรมที่เขียนกับข้อมูลชุดทดสอบของคุณเองในสภาพแวดล้อมจริงของการตรวจโปรแกรมได้ โดยเลือกโปรแกรมส่งแล้วที่ด้านล่างพร้อมทั้งส่งแฟ้มข้อมูลชุดทดสอบที่ต้องการให้ทำงานด้วย"
54 disabled_at_end_announcement: "<b>หมายเหตุ:</b> ระบบทดสอบโปรแกรมจะหยุดทำงานในช่วงเวลา 30 นาทีสุดท้ายของการแข่งขัน"
55 disabled_at_end_announcement: "<b>หมายเหตุ:</b> ระบบทดสอบโปรแกรมจะหยุดทำงานในช่วงเวลา 30 นาทีสุดท้ายของการแข่งขัน"
55
56
56 -
57 registration:
57 registration:
58 title: "ลงทะเบียนผู้ใช้ใหม่"
58 title: "ลงทะเบียนผู้ใช้ใหม่"
59 description: "ในการลงทะเบียน ให้ผู้สนใจเข้าร่วมการแข่งขันกรอกข้อมูลด้านล่าง จากนั้นระบบจะส่ง e-mail ไปยัง e-mail ที่ระบุเพื่อให้ยืนยันตัวตนและเปิดใช้บัญชีผู้ใช้<br/>ในกรณีที่ผู้เข้าแข่งขันเป็นนักเรียน รบกวนช่วยให้ข้อมูลเกี่ยวกับโรงเรียนและจังหวัดด้วย"
59 description: "ในการลงทะเบียน ให้ผู้สนใจเข้าร่วมการแข่งขันกรอกข้อมูลด้านล่าง จากนั้นระบบจะส่ง e-mail ไปยัง e-mail ที่ระบุเพื่อให้ยืนยันตัวตนและเปิดใช้บัญชีผู้ใช้<br/>ในกรณีที่ผู้เข้าแข่งขันเป็นนักเรียน รบกวนช่วยให้ข้อมูลเกี่ยวกับโรงเรียนและจังหวัดด้วย"
60
60
61 successful_title: "การลงทะเบียนเสร็จเรียบร้อย"
61 successful_title: "การลงทะเบียนเสร็จเรียบร้อย"
62
62
@@ -98,12 +98,29
98 expl: "<h2>บัญชีผู้ใช้ของคุณถูกสร้างขึ้นแล้ว แต่ระบบไม่สามารถส่ง e-mail เพื่อยืนยันการสมัครได้</h2>
98 expl: "<h2>บัญชีผู้ใช้ของคุณถูกสร้างขึ้นแล้ว แต่ระบบไม่สามารถส่ง e-mail เพื่อยืนยันการสมัครได้</h2>
99 อาจเกิดปัญหาในการตั้งค่าเริ่มต้นของระบบ กรุณาช่วยติดต่อผู้ดูแลระบบด้วยที่ {{email}}<br/>ขอขอบคุณจากทีมงาน"
99 อาจเกิดปัญหาในการตั้งค่าเริ่มต้นของระบบ กรุณาช่วยติดต่อผู้ดูแลระบบด้วยที่ {{email}}<br/>ขอขอบคุณจากทีมงาน"
100 activation:
100 activation:
101 email_exists: "มีผู้ใช้ที่ใช้ e-mail นี้แล้ว"
101 email_exists: "มีผู้ใช้ที่ใช้ e-mail นี้แล้ว"
102 invalid: "รหัสสำหรับยืนยันผิดพลาด กรุณาตรวจสอบอีกครั้ง"
102 invalid: "รหัสสำหรับยืนยันผิดพลาด กรุณาตรวจสอบอีกครั้ง"
103
103
104 + password_retrieval:
105 + header: "การขอรหัสผ่านใหม่"
106 + instructions: "กรุณากรอก e-mail ที่ลงทะเบียน"
107 + button_label: "ขอรหัสผ่านใหม่"
108 + no_email: "ไม่มีบัญชีผู้ใช้ที่ใช้ e-mail ดังกล่าว"
109 + email_body: "สวัสดีครับ {{full_name}},
110 +
111 + คุณได้ร้องขอรหัสผ่านใหม่ สำหรับการแข่งขัน {{contest_name}} ซึ่งเราได้สร้างให้คุณแล้ว ดังนี้
112 +
113 + บัญชีเข้าใช้ของคุณคือ: {{login}}
114 + รหัสผ่านคือ: {{password}}
115 +
116 + ถ้าคุณไม่ได้ขอรหัสผ่านใหม่ หรือไม่ใช่คนที่ลงทะเบียน กรุณาละทิ้ง e-mail ฉบับนี้
117 + และแจ้งความผิดพลาดนี้กับ {{admin_email}}
118 +
119 + ขอบคุณมาก!"
120 +
104 help:
121 help:
105 how_to_submit: "วิธีการส่งโปรแกรม"
122 how_to_submit: "วิธีการส่งโปรแกรม"
106 must_specify_language: "คุณ<b>ต้อง</b>ระบุภาษาโปรแกรมที่ใช้ที่ตอนต้นของรหัสโปรแกรม (source code) นอกจากนี้คุณอาจจะระบุโจทย์ที่ต้องการส่งได้ด้วย"
123 must_specify_language: "คุณ<b>ต้อง</b>ระบุภาษาโปรแกรมที่ใช้ที่ตอนต้นของรหัสโปรแกรม (source code) นอกจากนี้คุณอาจจะระบุโจทย์ที่ต้องการส่งได้ด้วย"
107 list_available_language: "ภาษาโปรแกรมที่สามารถระบุได้คือ <tt>C</tt>, <tt>C++</tt>, และ <tt>Pascal</tt> ด้านล่างแสดงตัวอย่างของการระบุสำหรับภาษาต่าง ๆ"
124 list_available_language: "ภาษาโปรแกรมที่สามารถระบุได้คือ <tt>C</tt>, <tt>C++</tt>, และ <tt>Pascal</tt> ด้านล่างแสดงตัวอย่างของการระบุสำหรับภาษาต่าง ๆ"
108 accept_only_language_specified: "ระบบจะ<b>ไม่รับ</b>โปรแกรมที่ส่งถ้าคุณไม่ได้ระบุภาษาที่ใช้"
125 accept_only_language_specified: "ระบบจะ<b>ไม่รับ</b>โปรแกรมที่ส่งถ้าคุณไม่ได้ระบุภาษาที่ใช้"
109 specifying_task: "นอกจากนี้ คุณยังสามารถระบุชื่อของโจทย์ที่ต้องการส่งเพิ่มเติมได้ ในการระบุให้ใส่ <tt>TASK:</tt> <i>taskname</i> คุณสามารถตรวจสอบชื่อของโจทย์ได้ โดยจะแสดงในวงเล็บหลังชื่อภาษาไทยของโจทย์"
126 specifying_task: "นอกจากนี้ คุณยังสามารถระบุชื่อของโจทย์ที่ต้องการส่งเพิ่มเติมได้ ในการระบุให้ใส่ <tt>TASK:</tt> <i>taskname</i> คุณสามารถตรวจสอบชื่อของโจทย์ได้ โดยจะแสดงในวงเล็บหลังชื่อภาษาไทยของโจทย์"
You need to be logged in to leave comments. Login now