t123yh
7 years ago
7 changed files with 301 additions and 13 deletions
@ -0,0 +1,16 @@
|
||||
const Promise = require('bluebird'); |
||||
const sendmail = Promise.promisify(require('sendmail')()); |
||||
|
||||
async function send_sendmail(to, subject, body) { |
||||
await sendmail({ |
||||
from: `${syzoj.config.title} <${syzoj.config.register_mail.address}>`, |
||||
to: to, |
||||
type: 'text/html', |
||||
subject: subject, |
||||
html: body |
||||
}); |
||||
} |
||||
|
||||
module.exports.send = async function sendEmail(to, subject, body) { |
||||
await send_sendmail(to, subject, body); |
||||
} |
@ -0,0 +1,71 @@
|
||||
<% this.title = '忘记密码' %> |
||||
<% include header %> |
||||
<div class="ui message" id="msgBox" hidden> |
||||
<p id="msgContent"></p> |
||||
</div> |
||||
<div class="ui middle aligned center aligned grid"> |
||||
<div class="row"> |
||||
<div class="column" style="max-width: 450px"> |
||||
<h2 class="ui image header"> |
||||
<div class="content"> |
||||
忘记密码 |
||||
</div> |
||||
</h2> |
||||
<form class="ui large form"> |
||||
<div class="ui existing segment"> |
||||
<div class="field"> |
||||
<div class="ui left icon input"> |
||||
<i class="at icon"></i> |
||||
<input name="email" placeholder="电子邮件地址" type="text" id="email" onkeydown="key_login(event)"> |
||||
</div> |
||||
</div> |
||||
<div class="ui fluid large submit button" id="sendEmail">找回密码</div> |
||||
</div> |
||||
<div class="ui error message"></div> |
||||
</form> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<script type="text/javascript"> |
||||
function showMessage(mclass, content) { |
||||
$("#msgBox").addClass(mclass); |
||||
$("#msgContent").text(content); |
||||
$("#msgBox").show(); |
||||
} |
||||
function submitForm() { |
||||
$("#sendEmail").addClass("loading"); |
||||
$.ajax({ |
||||
url: "/api/forget", |
||||
type: 'POST', |
||||
data: { |
||||
"email": $("#email").val(), |
||||
"_csrf": document.head.getAttribute('data-csrf-token') |
||||
}, |
||||
async: true, |
||||
success: function(data) { |
||||
error_code = data.error_code; |
||||
switch (error_code) { |
||||
case 1: |
||||
showMessage("positive", "找回密码邮件已经发至你电子邮箱的垃圾邮件文件夹。"); |
||||
return; |
||||
case 1002: |
||||
showMessage("error", "用户不存在"); |
||||
break; |
||||
default: |
||||
showMessage("error", "未知错误" + error_code); |
||||
break; |
||||
} |
||||
$("#resetPassword").removeClass("loading"); |
||||
}, |
||||
error: function(XMLHttpRequest, textStatus, errorThrown) { |
||||
alert(XMLHttpRequest.responseText); |
||||
} |
||||
}); |
||||
} |
||||
$(document).ready(function() { |
||||
$("#sendEmail").click(function() { |
||||
submitForm(); |
||||
}); |
||||
}); |
||||
</script> |
||||
<% include footer %> |
@ -0,0 +1,74 @@
|
||||
<% this.title = '重设密码' %> |
||||
<% include header %> |
||||
<div class="ui error message" id="error" hidden></div> |
||||
<div class="ui middle aligned center aligned grid"> |
||||
<div class="row"> |
||||
<div class="column" style="max-width: 450px"> |
||||
<h2 class="ui image header"> |
||||
<div class="content"> |
||||
重设密码 |
||||
</div> |
||||
</h2> |
||||
<form class="ui large form"> |
||||
<div class="ui existing segment"> |
||||
<div class="two fields"> |
||||
<div class="field"> |
||||
<label class="ui header">密码</label> |
||||
<input type="password" placeholder="" id="password1"> |
||||
</div> |
||||
<div class="field"> |
||||
<label class="ui header">确认密码</label> |
||||
<input type="password" placeholder="" id="password2"> |
||||
</div> |
||||
</div> |
||||
<div class="ui fluid large submit button" id="reset">重设</div> |
||||
</div> |
||||
</form> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<script src="/libs/blueimp-md5/js/md5.min.js"></script> |
||||
<script type="text/javascript"> |
||||
function showMessage(mclass, content) { |
||||
$("#msgBox").addClass(mclass); |
||||
$("#msgContent").text(content); |
||||
$("#msgBox").show(); |
||||
} |
||||
function submitForm() { |
||||
if ($("#password1").val() != $("#password2").val()) { |
||||
showMessage("两次输入的密码不一致"); |
||||
return; |
||||
} |
||||
password = md5($("#password1").val() + "syzoj2_xxx"); |
||||
$("#resetPassword").addClass("loading"); |
||||
$.ajax({ |
||||
url: "/api/reset_password", |
||||
type: 'POST', |
||||
data: { |
||||
"token": <%- JSON.stringify(token) %>, |
||||
"password": password |
||||
}, |
||||
async: true, |
||||
success: function(data) { |
||||
error_code = data.error_code; |
||||
switch (error_code) { |
||||
case 1: |
||||
showMessage("positive", "密码重置成功。"); |
||||
return; |
||||
default: |
||||
showMessage("error", "未知错误" + error_code); |
||||
break; |
||||
} |
||||
$("#resetPassword").removeClass("loading"); |
||||
}, |
||||
error: function(XMLHttpRequest, textStatus, errorThrown) { |
||||
alert(XMLHttpRequest.responseText); |
||||
} |
||||
}); |
||||
} |
||||
$(document).ready(function() { |
||||
$("#reset").click(function() { |
||||
submitForm(); |
||||
}); |
||||
}); |
||||
</script> |
Loading…
Reference in new issue