|
|
@@ -24,6 +24,8 @@ import CInput from '@/components/Basic/CInput'
|
|
|
import CButton from '@/components/Basic/CButton'
|
|
|
import { getUserInfo, loginByEmail } from '@/server/user'
|
|
|
import { SET_USER_INFO } from '@/store/types/main-types'
|
|
|
+import { login } from '@/server/admin'
|
|
|
+import userType from '@/server/enums/user-type'
|
|
|
|
|
|
export default {
|
|
|
components: { CButton, CInput },
|
|
|
@@ -52,17 +54,28 @@ export default {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- loginByEmail({ email: this.email, password: this.password }).then(res => {
|
|
|
- this.$setSuccessMessage('欢迎回来,' + res.name)
|
|
|
- this.$store.commit(SET_USER_INFO, { userInfo: res })
|
|
|
- if (res.type === 'TEACHER' || res.type === 'teacher') {
|
|
|
- this.$router.push({ name: 'teacher' })
|
|
|
- } else {
|
|
|
- this.$router.push({ name: 'student' })
|
|
|
- }
|
|
|
- }).catch(err => {
|
|
|
- this.$setErrorMessage(err.response.data.msg)
|
|
|
- })
|
|
|
+ if (this.email.match(/.+@.+/)) {
|
|
|
+ loginByEmail({ email: this.email, password: this.password })
|
|
|
+ .then(res => {
|
|
|
+ this.$setSuccessMessage('欢迎回来,' + res.name)
|
|
|
+ this.$store.commit(SET_USER_INFO, { userInfo: res })
|
|
|
+ if (res.type === userType.teacher) {
|
|
|
+ this.$router.push({ name: 'teacher' })
|
|
|
+ } else if (res.type === userType.student) {
|
|
|
+ this.$router.push({ name: 'student' })
|
|
|
+ } else if (res.type === userType.admin) {
|
|
|
+ this.$router.push({ name: 'admin' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => { this.$setErrorMessage(err.response.data.msg) })
|
|
|
+ } else {
|
|
|
+ login({ username: this.email, password: this.password })
|
|
|
+ .then(res => {
|
|
|
+ this.$store.commit(SET_USER_INFO, { userInfo: { ...res, type: userType.admin } })
|
|
|
+ this.$router.push('/admin')
|
|
|
+ })
|
|
|
+ .catch(err => { this.$setErrorMessage(err.response.data.msg) })
|
|
|
+ }
|
|
|
},
|
|
|
handleToRegister () {
|
|
|
this.$router.push({ name: 'register' })
|