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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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' |
@@ -3,9 +3,16 | |||
|
3 | 3 | |
|
4 | 4 | class UsersController < ApplicationController |
|
5 | 5 | |
|
6 |
- before_filter :authenticate, :except => [:new, |
|
|
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, |
|
|
12 | + before_filter :verify_online_registration, :only => [:new, | |
|
13 | + :register, | |
|
14 | + :forget, | |
|
15 | + :retrieve_password] | |
|
9 | 16 | |
|
10 | 17 | verify :method => :post, :only => [:chg_passwd], |
|
11 | 18 | :redirect_to => { :action => :index } |
@@ -77,6 +84,28 | |||
|
77 | 84 | render :action => 'confirm', :layout => 'empty' |
|
78 | 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 | 109 | protected |
|
81 | 110 | |
|
82 | 111 | def verify_online_registration |
@@ -121,4 +150,35 | |||
|
121 | 150 | return result |
|
122 | 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 | 184 | end |
@@ -39,4 +39,4 | |||
|
39 | 39 | = "#{t 'login.please'} " |
|
40 | 40 | = link_to "#{t 'login.register'}", :controller => :users, :action => :new |
|
41 | 41 | %br/ |
|
42 | - | |
|
42 | + = link_to "#{t 'login.forget_password'}", :controller => :users, :action => :forget |
@@ -35,6 +35,7 | |||
|
35 | 35 | participation: 'Want to participate?' |
|
36 | 36 | please: 'Please' |
|
37 | 37 | register: 'register' |
|
38 | + forget_password: 'Forget password?' | |
|
38 | 39 | |
|
39 | 40 | main: |
|
40 | 41 | start_soon: "The contest at your site will start soon. Please wait." |
@@ -55,6 +56,9 | |||
|
55 | 56 | |
|
56 | 57 | registration: |
|
57 | 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 | 62 | successful_title: "Registration successful" |
|
59 | 63 | |
|
60 | 64 | login_guide: "Only a-z, A-Z, 0-9 and _. Can be at most 20 characters long" |
@@ -98,6 +102,23 | |||
|
98 | 102 | email_exists: "A user with this E-mail exists." |
|
99 | 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 | 122 | help: |
|
102 | 123 | how_to_submit: "How to submit" |
|
103 | 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." |
@@ -35,6 +35,7 | |||
|
35 | 35 | participation: 'ต้องการเข้าร่วม?' |
|
36 | 36 | please: 'กรุณา' |
|
37 | 37 | register: 'ลงทะเบียน' |
|
38 | + forget_password: 'ลืมรหัสผ่าน?' | |
|
38 | 39 | |
|
39 | 40 | main: |
|
40 | 41 | start_soon: "การแข่งขันกำลังจะเริ่ม กรุณารอก่อน" |
@@ -53,7 +54,6 | |||
|
53 | 54 | intro: "คุณสามารถทดลองการทำงานของโปรแกรมที่เขียนกับข้อมูลชุดทดสอบของคุณเองในสภาพแวดล้อมจริงของการตรวจโปรแกรมได้ โดยเลือกโปรแกรมส่งแล้วที่ด้านล่างพร้อมทั้งส่งแฟ้มข้อมูลชุดทดสอบที่ต้องการให้ทำงานด้วย" |
|
54 | 55 | disabled_at_end_announcement: "<b>หมายเหตุ:</b> ระบบทดสอบโปรแกรมจะหยุดทำงานในช่วงเวลา 30 นาทีสุดท้ายของการแข่งขัน" |
|
55 | 56 | |
|
56 | - | |
|
57 | 57 | registration: |
|
58 | 58 | title: "ลงทะเบียนผู้ใช้ใหม่" |
|
59 | 59 | description: "ในการลงทะเบียน ให้ผู้สนใจเข้าร่วมการแข่งขันกรอกข้อมูลด้านล่าง จากนั้นระบบจะส่ง e-mail ไปยัง e-mail ที่ระบุเพื่อให้ยืนยันตัวตนและเปิดใช้บัญชีผู้ใช้<br/>ในกรณีที่ผู้เข้าแข่งขันเป็นนักเรียน รบกวนช่วยให้ข้อมูลเกี่ยวกับโรงเรียนและจังหวัดด้วย" |
@@ -101,6 +101,23 | |||
|
101 | 101 | email_exists: "มีผู้ใช้ที่ใช้ e-mail นี้แล้ว" |
|
102 | 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 | 121 | help: |
|
105 | 122 | how_to_submit: "วิธีการส่งโปรแกรม" |
|
106 | 123 | must_specify_language: "คุณ<b>ต้อง</b>ระบุภาษาโปรแกรมที่ใช้ที่ตอนต้นของรหัสโปรแกรม (source code) นอกจากนี้คุณอาจจะระบุโจทย์ที่ต้องการส่งได้ด้วย" |
You need to be logged in to leave comments.
Login now