|
| 1 | +extends ../layout |
| 2 | + |
| 3 | +block content |
| 4 | + .container(style="margin-top:30px;") |
| 5 | + form#form.col-md-5.col-md-offset-3(method="post") |
| 6 | + .form-group |
| 7 | + label.sr-only(for="inputEmail") 邮箱地址/用户名 |
| 8 | + input#inputEmail.form-control(type="text" name="account" placeholder="邮箱地址/用户名" required autofocus) |
| 9 | + .form-group |
| 10 | + .col-md-10(style="margin-left:-15px;") |
| 11 | + label.sr-only(for="inputToken") token |
| 12 | + input#inputToken.form-control(type="text" name="token" placeholder="token" required) |
| 13 | + .col-md-2 |
| 14 | + a.form-control.btn.btn-link(style="margin-bottom:15px;" target="_blank" href="/auth/login") 获取token |
| 15 | + .form-group |
| 16 | + label.sr-only(for="inputPassword") 原密码 |
| 17 | + input#inputPassword.form-control(type="password" name="oldPassword" placeholder="原密码" required) |
| 18 | + .form-group |
| 19 | + label.sr-only(for="inputNewPassword") 新密码 |
| 20 | + input#inputNewPassword.form-control(type="password" name="newPassword" placeholder="新密码" required) |
| 21 | + .form-group |
| 22 | + a#submitBtn.btn.btn-lg.btn-primary.btn-block 修改密码 |
| 23 | + |
| 24 | +block js |
| 25 | + script(). |
| 26 | + var submit = false; |
| 27 | + $('#submitBtn').on('click', function () { |
| 28 | + if (submit) { |
| 29 | + return ; |
| 30 | + } |
| 31 | + var token = $('#inputToken').val(); |
| 32 | + var oldPassword = $('#inputPassword').val(); |
| 33 | + var newPassword = $('#inputNewPassword').val(); |
| 34 | + submit = true; |
| 35 | + $.ajax({ |
| 36 | + type: 'patch', |
| 37 | + data: JSON.stringify({oldPassword:oldPassword,newPassword:newPassword}), |
| 38 | + contentType: 'application/json;charset=utf-8', |
| 39 | + headers: { |
| 40 | + Authorization : 'Bearer '+token |
| 41 | + }, |
| 42 | + url: '/users/password', |
| 43 | + dataType: 'json', |
| 44 | + success: function (data) { |
| 45 | + if (data.status == "OK") { |
| 46 | + alert("修改成功"); |
| 47 | + location.href = '/auth/login'; |
| 48 | + } else if (data.status == 401) { |
| 49 | + alert('token invalid'); |
| 50 | + } else { |
| 51 | + alert(data.message); |
| 52 | + } |
| 53 | + submit = false; |
| 54 | + } |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
0 commit comments