From f6b833594e2ba555c1bf86316b5750a4382495fc Mon Sep 17 00:00:00 2001 From: zema1 Date: Sun, 10 Sep 2017 18:29:01 +0800 Subject: [PATCH] support update password and send password reset email --- oj/.eslintrc.js | 5 +- oj/src/api.js | 17 +- oj/src/components/NavBar.vue | 6 +- oj/src/components/mixins/form.js | 23 +++ oj/src/components/mixins/index.js | 3 +- oj/src/main.js | 3 + oj/src/router/routes.js | 27 ++- oj/src/styles/common.less | 4 +- oj/src/styles/iview-custom.less | 8 + .../views/contest/children/ACMContestRank.vue | 2 +- oj/src/views/index.js | 7 +- oj/src/views/problem/ProblemList.vue | 2 +- oj/src/views/setting/Settings.vue | 43 +++-- .../views/setting/children/ProfileSetting.vue | 83 ++++----- .../setting/children/SecuritySetting.vue | 159 ++++++++++++++++++ oj/src/views/setting/index.js | 3 +- oj/src/views/user/ApplyResetPassword.vue | 131 +++++++++++++++ ...oginORRegister.vue => LoginOrRegister.vue} | 75 ++++++--- oj/src/views/user/ResetPassword.vue | 0 19 files changed, 497 insertions(+), 104 deletions(-) create mode 100644 oj/src/components/mixins/form.js create mode 100644 oj/src/views/user/ApplyResetPassword.vue rename oj/src/views/user/{LoginORRegister.vue => LoginOrRegister.vue} (83%) create mode 100644 oj/src/views/user/ResetPassword.vue diff --git a/oj/.eslintrc.js b/oj/.eslintrc.js index 344002f..1601140 100644 --- a/oj/.eslintrc.js +++ b/oj/.eslintrc.js @@ -18,7 +18,7 @@ module.exports = { 'generator-star-spacing': 0, // allow debugger during development 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, - "space-before-function-paren": ["warn", { + "space-before-function-paren": ["error", { "anonymous": "never", "named": "never", "asyncArrow": "always" @@ -26,6 +26,7 @@ module.exports = { "no-irregular-whitespace": ["error", { "skipComments": true, "skipTemplates": true - }] + }], + "no-unused-vars": ["warn"] } } diff --git a/oj/src/api.js b/oj/src/api.js index 11161fb..a6cfbaa 100644 --- a/oj/src/api.js +++ b/oj/src/api.js @@ -35,9 +35,6 @@ export default { getCaptcha() { return ajax('captcha', 'get') }, - getTwoFactorQrcode() { - return ajax('two_factor_auth', 'get') - }, // 获取自身信息 getUserInfo(username = undefined) { return ajax('profile', 'get', { @@ -46,13 +43,25 @@ export default { } }) }, - // 保存用户资料设置 updateProfile(profile) { return ajax('profile', 'put', { data: profile }) }, + getTwoFactorQrcode() { + return ajax('two_factor_auth', 'get') + }, + apply_reset_password(data) { + return ajax('apply_reset_password', 'post', { + data + }) + }, + changePassword(data) { + return ajax('change_password', 'post', { + data + }) + }, getLanguages() { return ajax('languages', 'get') }, diff --git a/oj/src/components/NavBar.vue b/oj/src/components/NavBar.vue index 378b18c..04d49ac 100644 --- a/oj/src/components/NavBar.vue +++ b/oj/src/components/NavBar.vue @@ -56,7 +56,7 @@ - + @@ -65,11 +65,11 @@ import api from '@/api' import auth from '../utils/auth' - import Register from '@/views/user/LoginORRegister' + import LoginOrRegister from '@/views/user/LoginOrRegister' export default { components: { - Register + LoginOrRegister }, data() { return { diff --git a/oj/src/components/mixins/form.js b/oj/src/components/mixins/form.js new file mode 100644 index 0000000..41523d0 --- /dev/null +++ b/oj/src/components/mixins/form.js @@ -0,0 +1,23 @@ +import api from '@/api' + +export default { + methods: { + validateForm(formName) { + return new Promise((resolve, reject) => { + this.$refs[formName].validate(valid => { + if (!valid) { + this.$error('please validate the error fields') + reject(valid) + } else { + resolve(valid) + } + }) + }) + }, + getCaptchaSrc() { + api.getCaptcha().then(res => { + this.captchaSrc = res.data.data + }) + } + } +} diff --git a/oj/src/components/mixins/index.js b/oj/src/components/mixins/index.js index 4753d46..7e6120b 100644 --- a/oj/src/components/mixins/index.js +++ b/oj/src/components/mixins/index.js @@ -1,5 +1,6 @@ import Emitter from './emitter' import ProblemMixin from './problem' import SettingMixin from './setting' +import FormMixin from './form' -export {Emitter, ProblemMixin, SettingMixin} +export {Emitter, ProblemMixin, SettingMixin, FormMixin} diff --git a/oj/src/main.js b/oj/src/main.js index 50e246b..22a2824 100644 --- a/oj/src/main.js +++ b/oj/src/main.js @@ -50,6 +50,9 @@ Vue.component(Panel.name, Panel) // Vue.use(VueI18n) // 注册全局消息提示 +Vue.prototype.$Message.config({ + duration: 1.8 +}) Vue.prototype.$error = Vue.prototype.$Message.error Vue.prototype.$info = Vue.prototype.$Message.info Vue.prototype.$success = Vue.prototype.$Message.success diff --git a/oj/src/router/routes.js b/oj/src/router/routes.js index 712110f..752286b 100644 --- a/oj/src/router/routes.js +++ b/oj/src/router/routes.js @@ -1,8 +1,10 @@ // all routes here. import Test from '../views/test' import { - ProblemList, ContestList, ContestDetails, ContestProblemList, ContestAnnouncement, ContestRank, - Logout, ACMRank, Settings, ProfileSetting + Logout, ApplyResetPassword, ResetPassword, + ProfileSetting, SecuritySetting, Settings, + ContestAnnouncement, ContestDetails, ContestList, ContestProblemList, ContestRank, + ProblemList, ACMRank } from '../views' export default [ @@ -18,6 +20,16 @@ export default [ path: '/logout', component: Logout }, + { + name: 'apply-reset-password', + path: '/apply-reset-password', + component: ApplyResetPassword + }, + { + name: 'reset-password', + path: '/reset-password/:token', + component: ResetPassword + }, { name: 'problem-list', path: '/problems', @@ -93,6 +105,11 @@ export default [ name: 'profile-setting', path: 'profile', component: ProfileSetting + }, + { + name: 'security-setting', + path: 'security', + component: SecuritySetting } ] }, @@ -100,8 +117,8 @@ export default [ path: '/test', name: 'Test', component: Test + }, + { + path: '*', redirect: '/problems' } - // { - // path: '*', redirect: '/problems' - // } ] diff --git a/oj/src/styles/common.less b/oj/src/styles/common.less index 76f120d..9e4a8db 100644 --- a/oj/src/styles/common.less +++ b/oj/src/styles/common.less @@ -8,8 +8,8 @@ .section-title { font-size: 21px; - font-weight: 400; - padding: 20px 20px; + font-weight: 500; + padding: 20px 25px; line-height: 30px; } diff --git a/oj/src/styles/iview-custom.less b/oj/src/styles/iview-custom.less index e5e9b59..312d6c7 100644 --- a/oj/src/styles/iview-custom.less +++ b/oj/src/styles/iview-custom.less @@ -28,3 +28,11 @@ table { color: #a94442; background-color: #f2dede; } + +.ivu-modal-footer { + border-top-width: 0; + padding: 0 18px 20px 18px; +} +.ivu-modal-body { + padding: 18px; +} diff --git a/oj/src/views/contest/children/ACMContestRank.vue b/oj/src/views/contest/children/ACMContestRank.vue index f64273c..e61aa7b 100644 --- a/oj/src/views/contest/children/ACMContestRank.vue +++ b/oj/src/views/contest/children/ACMContestRank.vue @@ -148,7 +148,7 @@ this.applyToTable(res.data.data.results) }) }, - getContestAndProblems(contestID) { + getContestAndProblems() { // 优先从localStorage中读取 this.contest = utils.loadContest(this.contestID) let problems = storage.get(STORAGE_KEY.contestProblems + this.contestID) diff --git a/oj/src/views/index.js b/oj/src/views/index.js index 98eb390..b2ae7b5 100644 --- a/oj/src/views/index.js +++ b/oj/src/views/index.js @@ -1,12 +1,15 @@ import ProblemList from './problem/ProblemList.vue' import ACMRank from './rank/ACMRank.vue' import Logout from './user/Logout.vue' +import ApplyResetPassword from './user/ApplyResetPassword.vue' +import ResetPassword from './user/ResetPassword.vue' export { - ProblemList, ACMRank, Logout + Logout, ResetPassword, ApplyResetPassword, + ProblemList, ACMRank } export {ContestRank, ContestProblemList, ContestList, ContestDetails, ContestAnnouncement} from './contest' -export {Settings, ProfileSetting} from './setting' +export {Settings, ProfileSetting, SecuritySetting} from './setting' /* 组件导出分为两类, 一类常用的直接导出,另一类诸如Login, Logout等用懒加载,懒加载不在此处导出 * 在对应的route内加载 * 见https://router.vuejs.org/en/advanced/lazy-loading.html diff --git a/oj/src/views/problem/ProblemList.vue b/oj/src/views/problem/ProblemList.vue index 441e20f..6f31630 100644 --- a/oj/src/views/problem/ProblemList.vue +++ b/oj/src/views/problem/ProblemList.vue @@ -2,7 +2,7 @@ -
Problems List
+
Problem List
  • diff --git a/oj/src/views/setting/Settings.vue b/oj/src/views/setting/Settings.vue index 49be08b..9d7213f 100644 --- a/oj/src/views/setting/Settings.vue +++ b/oj/src/views/setting/Settings.vue @@ -1,21 +1,25 @@ + + + diff --git a/oj/src/views/setting/index.js b/oj/src/views/setting/index.js index f00289d..d776607 100644 --- a/oj/src/views/setting/index.js +++ b/oj/src/views/setting/index.js @@ -1,4 +1,5 @@ import Settings from './Settings.vue' import ProfileSetting from './children/ProfileSetting.vue' +import SecuritySetting from './children/SecuritySetting.vue' -export {Settings, ProfileSetting} +export {Settings, ProfileSetting, SecuritySetting} diff --git a/oj/src/views/user/ApplyResetPassword.vue b/oj/src/views/user/ApplyResetPassword.vue new file mode 100644 index 0000000..5ee832e --- /dev/null +++ b/oj/src/views/user/ApplyResetPassword.vue @@ -0,0 +1,131 @@ + + + + diff --git a/oj/src/views/user/LoginORRegister.vue b/oj/src/views/user/LoginOrRegister.vue similarity index 83% rename from oj/src/views/user/LoginORRegister.vue rename to oj/src/views/user/LoginOrRegister.vue index eb81f18..226f3a9 100644 --- a/oj/src/views/user/LoginORRegister.vue +++ b/oj/src/views/user/LoginOrRegister.vue @@ -1,5 +1,5 @@ @@ -71,8 +89,10 @@