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' |
@@ -1,20 +1,27 | |||
|
1 | 1 | require 'tmail' |
|
2 | 2 | require 'net/smtp' |
|
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 } |
|
12 | 19 | |
|
13 | 20 | #in_place_edit_for :user, :alias_for_editing |
|
14 | 21 | #in_place_edit_for :user, :email_for_editing |
|
15 | 22 | |
|
16 | 23 | def index |
|
17 | 24 | if !Configuration['system.user_setting_enabled'] |
|
18 | 25 | redirect_to :controller => 'main', :action => 'list' |
|
19 | 26 | else |
|
20 | 27 | @user = User.find(session[:user_id]) |
@@ -68,24 +75,46 | |||
|
68 | 75 | @user.activated = true |
|
69 | 76 | @user.save |
|
70 | 77 | @result = :successful |
|
71 | 78 | else |
|
72 | 79 | @result = :email_used |
|
73 | 80 | end |
|
74 | 81 | else |
|
75 | 82 | @result = :failed |
|
76 | 83 | end |
|
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 |
|
83 | 112 | if !Configuration['system.online_registration'] |
|
84 | 113 | redirect_to :controller => 'main', :action => 'login' |
|
85 | 114 | end |
|
86 | 115 | end |
|
87 | 116 | |
|
88 | 117 | def send_confirmation_email(user) |
|
89 | 118 | contest_name = Configuration['contest.name'] |
|
90 | 119 | admin_email = Configuration['system.admin_email'] |
|
91 | 120 | activation_url = url_for(:action => 'confirm', |
@@ -112,13 +141,44 | |||
|
112 | 141 | begin |
|
113 | 142 | Net::SMTP.start(smtp_server) do |smtp| |
|
114 | 143 | smtp.send_message(mail.to_s, mail.from, mail.to) |
|
115 | 144 | end |
|
116 | 145 | result = true |
|
117 | 146 | rescue |
|
118 | 147 | result = false |
|
119 | 148 | end |
|
120 | 149 | |
|
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 |
@@ -30,13 +30,13 | |||
|
30 | 30 | %td{:align => "right"} |
|
31 | 31 | ="#{t 'password_label'}:" |
|
32 | 32 | %td= password_field_tag |
|
33 | 33 | = submit_tag t('login.login_submit') |
|
34 | 34 | %br/ |
|
35 | 35 | |
|
36 | 36 | - if Configuration['system.online_registration'] |
|
37 | 37 | =t 'login.participation' |
|
38 | 38 | %b |
|
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 |
@@ -26,44 +26,48 | |||
|
26 | 26 | |
|
27 | 27 | title_bar: |
|
28 | 28 | current_time: "Current time is" |
|
29 | 29 | remaining_time: "Time left: " |
|
30 | 30 | contest_not_started: "The contest has not started." |
|
31 | 31 | |
|
32 | 32 | login: |
|
33 | 33 | message: 'Please login to see the problem list' |
|
34 | 34 | login_submit: 'Login' |
|
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." |
|
41 | 42 | specified_in_header: "Specified in header" |
|
42 | 43 | |
|
43 | 44 | problem_desc: "desc" |
|
44 | 45 | submitted_at: "Submitted at" |
|
45 | 46 | graded_at: "Graded at" |
|
46 | 47 | score: "score: " |
|
47 | 48 | cmp_msg: "compiler msg" |
|
48 | 49 | src_link: "src" |
|
49 | 50 | submissions_link: "submissions" |
|
50 | 51 | |
|
51 | 52 | test: |
|
52 | 53 | title: "Test Interface" |
|
53 | 54 | intro: "You can test your submission with your own test data on the grading environment using this test interface." |
|
54 | 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 | 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" |
|
61 | 65 | email_guide: "Please make sure that your e-mail is correct.<br/>You'll need to verify your account by email." |
|
62 | 66 | register: "Register" |
|
63 | 67 | |
|
64 | 68 | email_body: "Hello {{full_name}}, |
|
65 | 69 | |
|
66 | 70 | You have registered for {{contest_name}} |
|
67 | 71 | |
|
68 | 72 | Your login is: {{login}} |
|
69 | 73 | |
@@ -89,24 +93,41 | |||
|
89 | 93 | activation_failed_title: "Activation failed" |
|
90 | 94 | |
|
91 | 95 | errors: |
|
92 | 96 | header: "Errors occured during registration" |
|
93 | 97 | email: |
|
94 | 98 | title: "Errors in sending registration confirmation" |
|
95 | 99 | expl: "<h2>Your user account has been created, but the system cannot send you the confirmation e-mail.</h2> |
|
96 | 100 | Maybe there's a problem in the configuration. Please report the admin at {{email}}.<br/>Thank you!" |
|
97 | 101 | activation: |
|
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." |
|
104 | 125 | list_available_language: "The possible language options are <tt>C</tt>, <tt>C++</tt>, and <tt>Pascal</tt>. The follow are examples." |
|
105 | 126 | accept_only_language_specified: "The server <b>will not</b> accept your submission, if you do not specify the language." |
|
106 | 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." |
|
107 | 128 | example_cpp: "For example, suppose you are using <tt>C++</tt> to write task <b>mobiles</b>, you put the following on top of your source code." |
|
108 | 129 | example_pas: "If you are using <tt>Pascal</tt> to write the same task, you'll use" |
|
109 | 130 | ask_questions_at_messages: "If you have any problems, you can ask at [<a href=\"{{url}}\">{{message_link_name}}</a>]." |
|
110 | 131 | |
|
111 | 132 | activerecord: |
|
112 | 133 | attributes: |
@@ -26,43 +26,43 | |||
|
26 | 26 | |
|
27 | 27 | title_bar: |
|
28 | 28 | current_time: "เวลาปัจจุบันคือ" |
|
29 | 29 | remaining_time: "เหลือเวลาอีก" |
|
30 | 30 | contest_not_started: "ยังไม่เริ่มแข่งขัน" |
|
31 | 31 | |
|
32 | 32 | login: |
|
33 | 33 | message: 'กรุณา login เพื่อเข้าสู่ระบบ' |
|
34 | 34 | login_submit: 'เข้าใช้ระบบ' |
|
35 | 35 | participation: 'ต้องการเข้าร่วม?' |
|
36 | 36 | please: 'กรุณา' |
|
37 | 37 | register: 'ลงทะเบียน' |
|
38 | + forget_password: 'ลืมรหัสผ่าน?' | |
|
38 | 39 | |
|
39 | 40 | main: |
|
40 | 41 | start_soon: "การแข่งขันกำลังจะเริ่ม กรุณารอก่อน" |
|
41 | 42 | specified_in_header: "ระบุที่หัวโปรแกรมแล้ว" |
|
42 | 43 | |
|
43 | 44 | problem_desc: "อ่าน" |
|
44 | 45 | submitted_at: "ส่งเมื่อเวลา" |
|
45 | 46 | graded_at: "ตรวจเมื่อเวลา" |
|
46 | 47 | score: "คะแนน: " |
|
47 | 48 | cmp_msg: "ผลคอมไพล์" |
|
48 | 49 | src_link: "ต้นฉบับ" |
|
49 | 50 | submissions_link: "การส่งครั้งอื่น ๆ" |
|
50 | 51 | |
|
51 | 52 | test: |
|
52 | 53 | title: "ทดสอบโปรแกรมบนสภาพแวดล้อมของเครื่องตรวจ" |
|
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/>ในกรณีที่ผู้เข้าแข่งขันเป็นนักเรียน รบกวนช่วยให้ข้อมูลเกี่ยวกับโรงเรียนและจังหวัดด้วย" |
|
60 | 60 | |
|
61 | 61 | successful_title: "การลงทะเบียนเสร็จเรียบร้อย" |
|
62 | 62 | |
|
63 | 63 | login_guide: "ใช้ได้เฉพาะ a-z, A-Z, 0-9 และ _ ความยาวไม่เกิน 20 ตัวอักษร" |
|
64 | 64 | email_guide: "กรุณาตรวจสอบ e-mail ที่ใส่ให้ถูกต้อง<br/>คุณจะต้องยืนยันการลงทะเบียนผ่านทางข้อมูลที่จะส่งให้ทาง e-mail" |
|
65 | 65 | register: "ลงทะเบียน" |
|
66 | 66 | |
|
67 | 67 | email_body: "สวัสดีครับ {{full_name}}, |
|
68 | 68 | |
@@ -92,24 +92,41 | |||
|
92 | 92 | activation_failed_title: "การยืนยันล้มเหลว" |
|
93 | 93 | |
|
94 | 94 | errors: |
|
95 | 95 | header: 'การลงทะเบียนมีข้อผิดพลาด' |
|
96 | 96 | email: |
|
97 | 97 | title: "เกิดปัญหาระหว่างการส่ง e-mail เพื่อยืนยันการสมัคร" |
|
98 | 98 | expl: "<h2>บัญชีผู้ใช้ของคุณถูกสร้างขึ้นแล้ว แต่ระบบไม่สามารถส่ง e-mail เพื่อยืนยันการสมัครได้</h2> |
|
99 | 99 | อาจเกิดปัญหาในการตั้งค่าเริ่มต้นของระบบ กรุณาช่วยติดต่อผู้ดูแลระบบด้วยที่ {{email}}<br/>ขอขอบคุณจากทีมงาน" |
|
100 | 100 | activation: |
|
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) นอกจากนี้คุณอาจจะระบุโจทย์ที่ต้องการส่งได้ด้วย" |
|
107 | 124 | list_available_language: "ภาษาโปรแกรมที่สามารถระบุได้คือ <tt>C</tt>, <tt>C++</tt>, และ <tt>Pascal</tt> ด้านล่างแสดงตัวอย่างของการระบุสำหรับภาษาต่าง ๆ" |
|
108 | 125 | accept_only_language_specified: "ระบบจะ<b>ไม่รับ</b>โปรแกรมที่ส่งถ้าคุณไม่ได้ระบุภาษาที่ใช้" |
|
109 | 126 | specifying_task: "นอกจากนี้ คุณยังสามารถระบุชื่อของโจทย์ที่ต้องการส่งเพิ่มเติมได้ ในการระบุให้ใส่ <tt>TASK:</tt> <i>taskname</i> คุณสามารถตรวจสอบชื่อของโจทย์ได้ โดยจะแสดงในวงเล็บหลังชื่อภาษาไทยของโจทย์" |
|
110 | 127 | example_cpp: "ยกตัวอย่างเช่น ถ้าคุณใช้ภาษา <tt>C++</tt> สำหรับเขียนโจทย์ <tt>mobiles</tt> ตอนต้นโปรแกรมคุณจะใส่ดังนี้" |
|
111 | 128 | example_pas: "ถ้าคุณใช้ภาษา <tt>Pascal</tt> เพื่อเขียนโจทย์ข้อเดียวกัน คุณจะระบุ" |
|
112 | 129 | ask_questions_at_messages: "ถ้ามีปัญหาในการใช้งานสามารถสอบถามได้ที่หน้า<a href=\"{{url}}\">{{message_link_name}}</a>" |
|
113 | 130 | |
|
114 | 131 | activerecord: |
|
115 | 132 | attributes: |
You need to be logged in to leave comments.
Login now